Skip to content

Commit

Permalink
Merge pull request #221 from Limmen/dev5
Browse files Browse the repository at this point in the history
network_service.py
  • Loading branch information
Limmen authored Aug 17, 2023
2 parents d714325 + 58f6447 commit 1ef7eda
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Optional, List, Dict, Any
import random
import csle_common.constants.constants as constants
from csle_common.dao.emulation_config.transport_protocol import TransportProtocol
from csle_common.dao.emulation_config.credential import Credential
Expand Down Expand Up @@ -40,7 +41,7 @@ def to_dict(self) -> Dict[str, Any]:
:return: a dict representation of the object
"""
d = {}
d: Dict[str, Any] = {}
d["protocol"] = self.protocol
d["port"] = self.port
d["name"] = self.name
Expand Down Expand Up @@ -102,9 +103,16 @@ def from_credential(credential: Credential) -> "NetworkService":
:return: the network service representation
"""
service = NetworkService(protocol=credential.protocol, port=credential.port,
name=credential.service,
credentials=[credential])
if credential.protocol is None:
protocol = TransportProtocol(random.choice([0, 1]))
else:
protocol = credential.protocol
if credential.service is None:
name = ""
else:
name = credential.service
service = NetworkService(protocol=protocol, port=credential.port,
name=name, credentials=[credential])
return service

@staticmethod
Expand Down

0 comments on commit 1ef7eda

Please sign in to comment.