Skip to content

Commit

Permalink
network_servide.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nforsg committed Aug 17, 2023
1 parent b568282 commit 58f6447
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 58f6447

Please sign in to comment.