Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get_data api for Trusted Secret #36

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/spaceone/secret/info/trusted_secret_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
_LOGGER = logging.getLogger(__name__)


def TrustedSecretDataInfo(secret_data):
info = {
"encrypted": secret_data.get("encrypted", False),
"encrypt_options": change_struct_type(secret_data.get("encrypt_options", {})),
"data": change_struct_type(secret_data["data"]),
}

return trusted_secret_pb2.TrustedSecretDataInfo(**info)


def TrustedSecretInfo(trusted_secret_vo: TrustedSecret, minimal=False):
info = {
"trusted_secret_id": trusted_secret_vo.trusted_secret_id,
Expand Down
7 changes: 7 additions & 0 deletions src/spaceone/secret/interface/grpc/trusted_secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ def update_data(self, request, context):
trusted_secret_service.update_data(params)
return self.locator.get_info('EmptyInfo')

def get_data(self, request, context):
params, metadata = self.parse_request(request, context)

with self.locator.get_service('TrustedSecretService', metadata) as trusted_secret_service:
trusted_secret_data = trusted_secret_service.get_data(params)
return self.locator.get_info('TrustedSecretDataInfo', trusted_secret_data)

def get(self, request, context):
params, metadata = self.parse_request(request, context)

Expand Down
37 changes: 37 additions & 0 deletions src/spaceone/secret/service/trusted_secret_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from spaceone.secret.manager.secret_manager import SecretManager
from spaceone.secret.manager.trusted_secret_manager import TrustedSecretManager
from spaceone.secret.manager.secret_connector_manager import SecretConnectorManager
from spaceone.secret.model.trusted_secret_model import TrustedSecret

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -188,6 +189,42 @@ def update_data(self, params):
)
secret_conn_mgr.update_secret(trusted_secret_id, data)

@transaction(exclude=["authentication", "authorization", "mutation"])
@check_required(["trusted_account_id", "domain_id"])
def get_data(self, params):
"""Get user secret data

Args:
params (dict): {
'trusted_account_id': 'str', # required
'workspace_id': 'str', # injected from auth
'domain_id': 'str', # injected from auth (required)
}

Returns:
user_secret_data (dict)
"""

trusted_account_id = params["secret_id"]
domain_id = params["domain_id"]
workspace_id = params.get("workspace_id")

trusted_secret_vo: TrustedSecret = self.trusted_secret_mgr.get_trusted_secret(
trusted_account_id, domain_id, workspace_id
)

secret_conn_mgr: SecretConnectorManager = self.locator.get_manager(
"SecretConnectorManager"
)

trusted_secret_data = secret_conn_mgr.get_secret(trusted_account_id)

return {
"encrypted": trusted_secret_vo.encrypted,
"encrypt_options": trusted_secret_vo.encrypt_options,
"data": trusted_secret_data,
}

@transaction(
permission="secret:TrustedSecret.read",
role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER", "WORKSPACE_MEMBER"],
Expand Down