Add exception for problems with secrets
This commit is contained in:
parent
ca4feaa403
commit
9d5918d618
@ -6,12 +6,8 @@ from uuid import uuid4
|
|||||||
from atst.utils import sha256_hex
|
from atst.utils import sha256_hex
|
||||||
|
|
||||||
from .cloud_provider_interface import CloudProviderInterface
|
from .cloud_provider_interface import CloudProviderInterface
|
||||||
from .exceptions import AuthenticationException, UserProvisioningException
|
from .exceptions import AuthenticationException, UserProvisioningException, SecretException
|
||||||
from .models import (
|
from .models import (
|
||||||
SubscriptionCreationCSPPayload,
|
|
||||||
SubscriptionCreationCSPResult,
|
|
||||||
SubscriptionVerificationCSPPayload,
|
|
||||||
SuscriptionVerificationCSPResult,
|
|
||||||
AdminRoleDefinitionCSPPayload,
|
AdminRoleDefinitionCSPPayload,
|
||||||
AdminRoleDefinitionCSPResult,
|
AdminRoleDefinitionCSPResult,
|
||||||
ApplicationCSPPayload,
|
ApplicationCSPPayload,
|
||||||
@ -27,12 +23,16 @@ from .models import (
|
|||||||
EnvironmentCSPPayload,
|
EnvironmentCSPPayload,
|
||||||
EnvironmentCSPResult,
|
EnvironmentCSPResult,
|
||||||
KeyVaultCredentials,
|
KeyVaultCredentials,
|
||||||
|
PrincipalAdminRoleCSPPayload,
|
||||||
|
PrincipalAdminRoleCSPResult,
|
||||||
ProductPurchaseCSPPayload,
|
ProductPurchaseCSPPayload,
|
||||||
ProductPurchaseCSPResult,
|
ProductPurchaseCSPResult,
|
||||||
ProductPurchaseVerificationCSPPayload,
|
ProductPurchaseVerificationCSPPayload,
|
||||||
ProductPurchaseVerificationCSPResult,
|
ProductPurchaseVerificationCSPResult,
|
||||||
PrincipalAdminRoleCSPPayload,
|
SubscriptionCreationCSPPayload,
|
||||||
PrincipalAdminRoleCSPResult,
|
SubscriptionCreationCSPResult,
|
||||||
|
SubscriptionVerificationCSPPayload,
|
||||||
|
SuscriptionVerificationCSPResult,
|
||||||
TaskOrderBillingCreationCSPPayload,
|
TaskOrderBillingCreationCSPPayload,
|
||||||
TaskOrderBillingCreationCSPResult,
|
TaskOrderBillingCreationCSPResult,
|
||||||
TaskOrderBillingVerificationCSPPayload,
|
TaskOrderBillingVerificationCSPPayload,
|
||||||
@ -54,7 +54,6 @@ from .models import (
|
|||||||
)
|
)
|
||||||
from .policy import AzurePolicyManager
|
from .policy import AzurePolicyManager
|
||||||
|
|
||||||
|
|
||||||
# This needs to be a fully pathed role definition identifier, not just a UUID
|
# This needs to be a fully pathed role definition identifier, not just a UUID
|
||||||
# TODO: Extract these from sdk msrestazure.azure_cloud import AZURE_PUBLIC_CLOUD
|
# TODO: Extract these from sdk msrestazure.azure_cloud import AZURE_PUBLIC_CLOUD
|
||||||
AZURE_SKU_ID = "0001" # probably a static sku specific to ATAT/JEDI
|
AZURE_SKU_ID = "0001" # probably a static sku specific to ATAT/JEDI
|
||||||
@ -117,11 +116,15 @@ class AzureCloudProvider(CloudProviderInterface):
|
|||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
return secret_client.set_secret(secret_key, secret_value)
|
return secret_client.set_secret(secret_key, secret_value)
|
||||||
except self.exceptions.HttpResponseError:
|
except self.sdk.exceptions.HttpResponseError as exc:
|
||||||
app.logger.error(
|
app.logger.error(
|
||||||
f"Could not SET secret in Azure keyvault for key {secret_key}.",
|
f"Could not SET secret in Azure keyvault for key {secret_key}.",
|
||||||
exc_info=1,
|
exc_info=1,
|
||||||
)
|
)
|
||||||
|
raise SecretException(
|
||||||
|
f"Could not SET secret in Azure keyvault for key {secret_key}.",
|
||||||
|
exc.message,
|
||||||
|
)
|
||||||
|
|
||||||
def get_secret(self, secret_key):
|
def get_secret(self, secret_key):
|
||||||
credential = self._get_client_secret_credential_obj()
|
credential = self._get_client_secret_credential_obj()
|
||||||
@ -130,11 +133,15 @@ class AzureCloudProvider(CloudProviderInterface):
|
|||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
return secret_client.get_secret(secret_key).value
|
return secret_client.get_secret(secret_key).value
|
||||||
except self.exceptions.HttpResponseError:
|
except self.sdk.exceptions.HttpResponseError:
|
||||||
app.logger.error(
|
app.logger.error(
|
||||||
f"Could not GET secret in Azure keyvault for key {secret_key}.",
|
f"Could not GET secret in Azure keyvault for key {secret_key}.",
|
||||||
exc_info=1,
|
exc_info=1,
|
||||||
)
|
)
|
||||||
|
raise SecretException(
|
||||||
|
f"Could not GET secret in Azure keyvault for key {secret_key}.",
|
||||||
|
exc.message,
|
||||||
|
)
|
||||||
|
|
||||||
def create_environment(self, payload: EnvironmentCSPPayload):
|
def create_environment(self, payload: EnvironmentCSPPayload):
|
||||||
creds = self._source_creds(payload.tenant_id)
|
creds = self._source_creds(payload.tenant_id)
|
||||||
|
@ -118,3 +118,17 @@ class BaselineProvisionException(GeneralCSPException):
|
|||||||
return "Could not complete baseline provisioning for environment ({}): {}".format(
|
return "Could not complete baseline provisioning for environment ({}): {}".format(
|
||||||
self.env_identifier, self.reason
|
self.env_identifier, self.reason
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class SecretException(GeneralCSPException):
|
||||||
|
"""A problem occurred with setting or getting secrets"""
|
||||||
|
|
||||||
|
def __init__(self, tenant_id, reason):
|
||||||
|
self.tenant_id = tenant_id
|
||||||
|
self.reason = reason
|
||||||
|
|
||||||
|
@property
|
||||||
|
def message(self):
|
||||||
|
return "Could not get or set secret for ({}): {}".format(
|
||||||
|
self.tenant_id, self.reason
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user