Skip to content

Commit

Permalink
feat: add trusted secret get data at secret manager (#199)
Browse files Browse the repository at this point in the history
Signed-off-by: ImMin5 <[email protected]>
  • Loading branch information
ImMin5 committed Mar 13, 2024
1 parent 7c8582a commit f62d7a9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
9 changes: 9 additions & 0 deletions src/spaceone/identity/manager/secret_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ def get_secret_data(self, secret_id: str, domain_id: str) -> dict:
token=system_token,
)

def get_trusted_secret_data(self, trusted_secret_id: str, domain_id: str) -> dict:
system_token = config.get_global("TOKEN")

return self.secret_conn.dispatch(
"TrustedSecret.get_data",
{"trusted_secret_id": trusted_secret_id, "domain_id": domain_id},
token=system_token,
)

def create_trusted_secret(self, params: dict) -> dict:
return self.secret_conn.dispatch("TrustedSecret.create", params)

Expand Down
1 change: 1 addition & 0 deletions src/spaceone/identity/service/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from spaceone.identity.service.job_service import JobService
19 changes: 11 additions & 8 deletions src/spaceone/identity/service/job_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,19 @@ def created_service_account_job(
ac_plugin_mgr.initialize(endpoint)

try:
secret_data = self._get_secret_data(
trusted_secret_data = self._get_trusted_secret_data(
trusted_account_vo.trusted_secret_id, domain_id
)
schema_mgr = SchemaManager()
# Check secret_data by schema
schema_mgr.validate_secret_data_by_schema_id(
schema_id, domain_id, secret_data, "SECRET"
schema_id, domain_id, trusted_secret_data, "SECRET"
)
except Exception as e:
secret_data = {}
trusted_secret_data = {}
_LOGGER.error(
f"[created_trusted_account_job] get secret error: {e}", exc_info=True
f"[created_trusted_account_job] get trusted secret error: {e}",
exc_info=True,
)

# Add Job Options
Expand All @@ -310,7 +311,7 @@ def created_service_account_job(
"job_id": job_vo.job_id,
"trusted_account_id": trusted_account_id,
"trusted_secret_id": trusted_account_vo.trusted_secret_id,
"secret_data": secret_data,
"secret_data": trusted_secret_data,
"workspace_id": trusted_account_vo.workspace_id,
"domain_id": domain_id,
}
Expand Down Expand Up @@ -338,11 +339,13 @@ def _get_all_schedule_enabled_trusted_accounts(self, current_hour: int) -> list:
)
return trusted_account_vos

def _get_secret_data(self, secret_id: str, domain_id: str) -> dict:
def _get_trusted_secret_data(self, trusted_secret_id: str, domain_id: str) -> dict:
# todo: this method is internal method
secret_mgr: SecretManager = self.locator.get_manager("SecretManager")
if secret_id:
secret_data = secret_mgr.get_secret_data(secret_id, domain_id)
if trusted_secret_id:
secret_data = secret_mgr.get_trusted_secret_data(
trusted_secret_id, domain_id
)
else:
secret_data = {}

Expand Down

0 comments on commit f62d7a9

Please sign in to comment.