Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
weiiwang01 committed Dec 19, 2024
1 parent 8063053 commit baa8794
Show file tree
Hide file tree
Showing 30 changed files with 306 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
2 changes: 1 addition & 1 deletion lib/charms/opencti/v0/opencti_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _config_metadata(self) -> dict:
Raises:
RuntimeError: If charm metadata file doesn't exist.
"""
config_file = self.charm_dir / "metadata.yaml"
config_file = self.charm_dir / "config.yaml"
if config_file.exists():
return yaml.safe_load(config_file.read_text())["options"]
config_file = self.charm_dir / "charmcraft.yaml"
Expand Down
4 changes: 4 additions & 0 deletions opencti_rock/rockcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ description: >-
platforms:
amd64:

service:
opencti:
command:

parts:
platform/graphql:
plugin: nil
Expand Down
14 changes: 8 additions & 6 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ def _dump_integration(self, name: str) -> str:
dump["unit-data"] = {unit.name: dict(integration.data[unit]) for unit in units}
return json.dumps(dump)

def _reconcile_connector(self):
def _reconcile_connector(self) -> None:
"""Run charm reconcile function for OpenCTI connectors."""
client = opencti.OpenctiClient(
url="http://localhost:8080",
Expand All @@ -671,9 +671,11 @@ def _reconcile_connector(self):
user = self._setup_connector_integration_and_user(client, integration)
if user:
current_using_users.add(user)
for user in client.list_users():
if user.name not in current_using_users and user.name.startswith("charm-connector-"):
client.set_account_status(user.id, "Inactive")
for opencti_user in client.list_users():
if opencti_user.name not in current_using_users and opencti_user.name.startswith(
"charm-connector-"
):
client.set_account_status(opencti_user.id, "Inactive")

def _setup_connector_integration_and_user(
self, client: opencti.OpenctiClient, integration: ops.Relation
Expand All @@ -693,7 +695,7 @@ def _setup_connector_integration_and_user(
integration_data.get("connector_type"),
)
if not connector_charm_name or not connector_type:
return
return None
opencti_url = f"http://{self.app.name}-endpoints.{self.model.name}.svc:8080"
integration.data[self.app]["opencti_url"] = opencti_url
connector_user = f"charm-connector-{connector_charm_name.replace('_', '-').lower()}"
Expand All @@ -715,7 +717,7 @@ def _setup_connector_integration_and_user(
if not opencti_token_id:
secret = self.app.add_secret(content={"token": api_token})
secret.grant(integration)
integration.data[self.app]["opencti_token"] = secret.id
integration.data[self.app]["opencti_token"] = typing.cast(str, secret.id)
if opencti_token_id:
secret = self.model.get_secret(id=opencti_token_id)
if secret.get_content(refresh=True)["token"] != api_token:
Expand Down
Loading

0 comments on commit baa8794

Please sign in to comment.