mirror of
https://github.com/open-metadata/OpenMetadata.git
synced 2025-11-03 12:08:31 +00:00
Fix External Account Json Schema Issue (#15671)
This commit is contained in:
parent
039d66390b
commit
00677a1e1b
@ -26,7 +26,7 @@ from metadata.generated.schema.security.credentials.gcpCredentials import (
|
||||
GcpCredentialsPath,
|
||||
)
|
||||
from metadata.generated.schema.security.credentials.gcpExternalAccount import (
|
||||
GcpCredentialsValuesExternalAccount,
|
||||
GcpExternalAccount,
|
||||
)
|
||||
from metadata.generated.schema.security.credentials.gcpValues import (
|
||||
GcpCredentialsValues,
|
||||
@ -89,7 +89,7 @@ def create_credential_tmp_file(credentials: dict) -> str:
|
||||
|
||||
|
||||
def build_google_credentials_dict(
|
||||
gcp_values: Union[GcpCredentialsValues, GcpCredentialsValuesExternalAccount]
|
||||
gcp_values: Union[GcpCredentialsValues, GcpExternalAccount]
|
||||
) -> Dict[str, str]:
|
||||
"""
|
||||
Given GcPCredentialsValues, build a dictionary as the JSON file
|
||||
@ -97,7 +97,7 @@ def build_google_credentials_dict(
|
||||
:param gcp_values: GCP credentials
|
||||
:return: Dictionary with credentials
|
||||
"""
|
||||
if gcp_values.type == "service_account":
|
||||
if isinstance(gcp_values, GcpCredentialsValues):
|
||||
private_key_str = gcp_values.privateKey.get_secret_value()
|
||||
# adding the replace string here to escape line break if passed from env
|
||||
private_key_str = private_key_str.replace("\\n", "\n")
|
||||
@ -115,17 +115,16 @@ def build_google_credentials_dict(
|
||||
"auth_provider_x509_cert_url": str(gcp_values.authProviderX509CertUrl),
|
||||
"client_x509_cert_url": str(gcp_values.clientX509CertUrl),
|
||||
}
|
||||
if gcp_values.type == "external_account":
|
||||
if isinstance(gcp_values, GcpExternalAccount):
|
||||
return {
|
||||
"type": gcp_values.type,
|
||||
"type": gcp_values.externalType,
|
||||
"audience": gcp_values.audience,
|
||||
"subject_token_type": gcp_values.subjectTokenType,
|
||||
"token_url": gcp_values.tokenURL,
|
||||
"credential_source": gcp_values.credentialSource,
|
||||
}
|
||||
|
||||
raise InvalidGcpConfigException(
|
||||
f"Error not support credential type {gcp_values.type}"
|
||||
f"Error trying to build GCP credentials dict due to Invalid GCP config {type(gcp_values)}"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ from unittest import TestCase
|
||||
from pydantic import SecretStr
|
||||
|
||||
from metadata.generated.schema.security.credentials.gcpExternalAccount import (
|
||||
GcpCredentialsValuesExternalAccount,
|
||||
GcpExternalAccount,
|
||||
)
|
||||
from metadata.generated.schema.security.credentials.gcpValues import (
|
||||
GcpCredentialsValues,
|
||||
@ -90,8 +90,8 @@ VEhPQF0i0tUU7Fl071hcYaiQoZx4nIjN+NG6p5QKbl6k
|
||||
"""
|
||||
Check how we can validate GCS values
|
||||
"""
|
||||
gcp_values = GcpCredentialsValuesExternalAccount(
|
||||
type="external_account",
|
||||
gcp_values = GcpExternalAccount(
|
||||
externalType="external_account",
|
||||
audience="audience",
|
||||
subjectTokenType="subject_token_type",
|
||||
tokenURL="token_url",
|
||||
@ -106,6 +106,4 @@ VEhPQF0i0tUU7Fl071hcYaiQoZx4nIjN+NG6p5QKbl6k
|
||||
"credential_source": {"environmentId": "environment_id"},
|
||||
}
|
||||
|
||||
build_google_credentials_dict(gcp_values)
|
||||
|
||||
self.assertEqual(expected_dict, build_google_credentials_dict(gcp_values))
|
||||
|
||||
@ -3,11 +3,10 @@
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "object",
|
||||
"javaType": "org.openmetadata.schema.security.credentials.GCPExternalAccount",
|
||||
"title": "GCP Credentials Values ( External Account )",
|
||||
"title": "GCP External Account",
|
||||
"description": "Pass the raw credential values provided by GCP",
|
||||
"definitions": {},
|
||||
"properties": {
|
||||
"type": {
|
||||
"externalType": {
|
||||
"title": "Credentials Type",
|
||||
"description": "Google Cloud Platform account type.",
|
||||
"type": "string",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user