func()

in releases/go/mpl/KeyStore/KeyStore.go [183:353]


func (_static *CompanionStruct_Default___) KeyStore(config m_AwsCryptographyKeyStoreTypes.KeyStoreConfig) m_Wrappers.Result {
	var res m_Wrappers.Result = m_Wrappers.Result{}
	_ = res
	var _0_kmsClient m_ComAmazonawsKmsTypes.IKMSClient = (m_ComAmazonawsKmsTypes.IKMSClient)(nil)
	_ = _0_kmsClient
	var _1_ddbClient m_ComAmazonawsDynamodbTypes.IDynamoDBClient = (m_ComAmazonawsDynamodbTypes.IDynamoDBClient)(nil)
	_ = _1_ddbClient
	var _2_inferredRegion m_Wrappers.Option
	_ = _2_inferredRegion
	_2_inferredRegion = m_Wrappers.Companion_Option_.Create_None_()
	if m_KMSKeystoreOperations.Companion_Default___.HasKeyId((config).Dtor_kmsConfiguration()) {
		var _3_valueOrError0 m_Wrappers.Result = m_Wrappers.Result{}
		_ = _3_valueOrError0
		_3_valueOrError0 = m_KmsArn.Companion_Default___.IsValidKeyArn(m_KMSKeystoreOperations.Companion_Default___.GetKeyId((config).Dtor_kmsConfiguration()))
		if (_3_valueOrError0).IsFailure() {
			res = (_3_valueOrError0).PropagateFailure()
			return res
		}
		var _4_parsedArn m_AwsArnParsing.AwsArn
		_ = _4_parsedArn
		_4_parsedArn = (_3_valueOrError0).Extract().(m_AwsArnParsing.AwsArn)
		_2_inferredRegion = m_Wrappers.Companion_Option_.Create_Some_((_4_parsedArn).Dtor_region())
	} else if ((config).Dtor_kmsConfiguration()).Is_mrDiscovery() {
		_2_inferredRegion = m_Wrappers.Companion_Option_.Create_Some_((((config).Dtor_kmsConfiguration()).Dtor_mrDiscovery()).Dtor_region())
	}
	var _5_grantTokens m_Wrappers.Result
	_ = _5_grantTokens
	_5_grantTokens = m_AwsKmsUtils.Companion_Default___.GetValidGrantTokens((config).Dtor_grantTokens())
	var _6_valueOrError1 m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default()
	_ = _6_valueOrError1
	_6_valueOrError1 = m_Wrappers.Companion_Default___.Need((true) && ((_5_grantTokens).Is_Success()), m_AwsCryptographyKeyStoreTypes.Companion_Error_.Create_KeyStoreException_(_dafny.SeqOfString("Grant Tokens passed to Key Store configuration are invalid.")))
	if (_6_valueOrError1).IsFailure() {
		res = (_6_valueOrError1).PropagateFailure()
		return res
	}
	var _7_keyStoreId _dafny.Sequence = _dafny.EmptySeq.SetString()
	_ = _7_keyStoreId
	if ((config).Dtor_id()).Is_Some() {
		_7_keyStoreId = ((config).Dtor_id()).Dtor_value().(_dafny.Sequence)
	} else {
		var _8_maybeUuid m_Wrappers.Result
		_ = _8_maybeUuid
		var _out0 m_Wrappers.Result
		_ = _out0
		_out0 = m_UUID.GenerateUUID()
		_8_maybeUuid = _out0
		var _9_valueOrError2 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq.SetString())
		_ = _9_valueOrError2
		_9_valueOrError2 = (_8_maybeUuid).MapFailure(func(coer24 func(_dafny.Sequence) m_AwsCryptographyKeyStoreTypes.Error) func(interface{}) interface{} {
			return func(arg24 interface{}) interface{} {
				return coer24(arg24.(_dafny.Sequence))
			}
		}(func(_10_e _dafny.Sequence) m_AwsCryptographyKeyStoreTypes.Error {
			return m_AwsCryptographyKeyStoreTypes.Companion_Error_.Create_KeyStoreException_(_10_e)
		}))
		if (_9_valueOrError2).IsFailure() {
			res = (_9_valueOrError2).PropagateFailure()
			return res
		}
		var _11_uuid _dafny.Sequence
		_ = _11_uuid
		_11_uuid = (_9_valueOrError2).Extract().(_dafny.Sequence)
		_7_keyStoreId = _11_uuid
	}
	if ((config).Dtor_kmsClient()).Is_Some() {
		_0_kmsClient = m_ComAmazonawsKmsTypes.Companion_IKMSClient_.CastTo_(((config).Dtor_kmsClient()).Dtor_value())
	} else if (((config).Dtor_kmsClient()).Is_None()) && ((_2_inferredRegion).Is_Some()) {
		var _12_maybeKmsClient m_Wrappers.Result
		_ = _12_maybeKmsClient
		var _out1 m_Wrappers.Result
		_ = _out1
		_out1 = m_Com_Amazonaws_Kms.Companion_Default___.KMSClientForRegion((_2_inferredRegion).Dtor_value().(_dafny.Sequence))
		_12_maybeKmsClient = _out1
		var _13_valueOrError3 m_Wrappers.Result = m_Wrappers.Result{}
		_ = _13_valueOrError3
		_13_valueOrError3 = (_12_maybeKmsClient).MapFailure(func(coer25 func(m_ComAmazonawsKmsTypes.Error) m_AwsCryptographyKeyStoreTypes.Error) func(interface{}) interface{} {
			return func(arg25 interface{}) interface{} {
				return coer25(arg25.(m_ComAmazonawsKmsTypes.Error))
			}
		}(func(_14_e m_ComAmazonawsKmsTypes.Error) m_AwsCryptographyKeyStoreTypes.Error {
			return m_AwsCryptographyKeyStoreTypes.Companion_Error_.Create_ComAmazonawsKms_(_14_e)
		}))
		if (_13_valueOrError3).IsFailure() {
			res = (_13_valueOrError3).PropagateFailure()
			return res
		}
		_0_kmsClient = m_ComAmazonawsKmsTypes.Companion_IKMSClient_.CastTo_((_13_valueOrError3).Extract())
	} else {
		var _15_maybeKmsClient m_Wrappers.Result
		_ = _15_maybeKmsClient
		var _out2 m_Wrappers.Result
		_ = _out2
		_out2 = m_Com_Amazonaws_Kms.Companion_Default___.KMSClient()
		_15_maybeKmsClient = _out2
		var _16_valueOrError4 m_Wrappers.Result = m_Wrappers.Result{}
		_ = _16_valueOrError4
		_16_valueOrError4 = (_15_maybeKmsClient).MapFailure(func(coer26 func(m_ComAmazonawsKmsTypes.Error) m_AwsCryptographyKeyStoreTypes.Error) func(interface{}) interface{} {
			return func(arg26 interface{}) interface{} {
				return coer26(arg26.(m_ComAmazonawsKmsTypes.Error))
			}
		}(func(_17_e m_ComAmazonawsKmsTypes.Error) m_AwsCryptographyKeyStoreTypes.Error {
			return m_AwsCryptographyKeyStoreTypes.Companion_Error_.Create_ComAmazonawsKms_(_17_e)
		}))
		if (_16_valueOrError4).IsFailure() {
			res = (_16_valueOrError4).PropagateFailure()
			return res
		}
		_0_kmsClient = m_ComAmazonawsKmsTypes.Companion_IKMSClient_.CastTo_((_16_valueOrError4).Extract())
	}
	if ((config).Dtor_ddbClient()).Is_Some() {
		_1_ddbClient = m_ComAmazonawsDynamodbTypes.Companion_IDynamoDBClient_.CastTo_(((config).Dtor_ddbClient()).Dtor_value())
	} else if (((config).Dtor_ddbClient()).Is_None()) && ((_2_inferredRegion).Is_Some()) {
		var _18_maybeDdbClient m_Wrappers.Result
		_ = _18_maybeDdbClient
		var _out3 m_Wrappers.Result
		_ = _out3
		_out3 = m_Com_Amazonaws_Dynamodb.Companion_Default___.DDBClientForRegion((_2_inferredRegion).Dtor_value().(_dafny.Sequence))
		_18_maybeDdbClient = _out3
		var _19_valueOrError5 m_Wrappers.Result = m_Wrappers.Result{}
		_ = _19_valueOrError5
		_19_valueOrError5 = (_18_maybeDdbClient).MapFailure(func(coer27 func(m_ComAmazonawsDynamodbTypes.Error) m_AwsCryptographyKeyStoreTypes.Error) func(interface{}) interface{} {
			return func(arg27 interface{}) interface{} {
				return coer27(arg27.(m_ComAmazonawsDynamodbTypes.Error))
			}
		}(func(_20_e m_ComAmazonawsDynamodbTypes.Error) m_AwsCryptographyKeyStoreTypes.Error {
			return m_AwsCryptographyKeyStoreTypes.Companion_Error_.Create_ComAmazonawsDynamodb_(_20_e)
		}))
		if (_19_valueOrError5).IsFailure() {
			res = (_19_valueOrError5).PropagateFailure()
			return res
		}
		_1_ddbClient = m_ComAmazonawsDynamodbTypes.Companion_IDynamoDBClient_.CastTo_((_19_valueOrError5).Extract())
	} else {
		var _21_maybeDdbClient m_Wrappers.Result
		_ = _21_maybeDdbClient
		var _out4 m_Wrappers.Result
		_ = _out4
		_out4 = m_Com_Amazonaws_Dynamodb.Companion_Default___.DynamoDBClient()
		_21_maybeDdbClient = _out4
		var _22_valueOrError6 m_Wrappers.Result = m_Wrappers.Result{}
		_ = _22_valueOrError6
		_22_valueOrError6 = (_21_maybeDdbClient).MapFailure(func(coer28 func(m_ComAmazonawsDynamodbTypes.Error) m_AwsCryptographyKeyStoreTypes.Error) func(interface{}) interface{} {
			return func(arg28 interface{}) interface{} {
				return coer28(arg28.(m_ComAmazonawsDynamodbTypes.Error))
			}
		}(func(_23_e m_ComAmazonawsDynamodbTypes.Error) m_AwsCryptographyKeyStoreTypes.Error {
			return m_AwsCryptographyKeyStoreTypes.Companion_Error_.Create_ComAmazonawsDynamodb_(_23_e)
		}))
		if (_22_valueOrError6).IsFailure() {
			res = (_22_valueOrError6).PropagateFailure()
			return res
		}
		_1_ddbClient = m_ComAmazonawsDynamodbTypes.Companion_IDynamoDBClient_.CastTo_((_22_valueOrError6).Extract())
	}
	var _24_valueOrError7 m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default()
	_ = _24_valueOrError7
	_24_valueOrError7 = m_Wrappers.Companion_Default___.Need(m_ComAmazonawsDynamodbTypes.Companion_Default___.IsValid__TableName((config).Dtor_ddbTableName()), m_AwsCryptographyKeyStoreTypes.Companion_Error_.Create_KeyStoreException_(_dafny.SeqOfString("Invalid Amazon DynamoDB Table Name")))
	if (_24_valueOrError7).IsFailure() {
		res = (_24_valueOrError7).PropagateFailure()
		return res
	}
	var _25_client *KeyStoreClient
	_ = _25_client
	var _nw0 *KeyStoreClient = New_KeyStoreClient_()
	_ = _nw0
	_nw0.Ctor__(m_AwsCryptographyKeyStoreOperations.Companion_Config_.Create_Config_(_7_keyStoreId, (config).Dtor_ddbTableName(), (config).Dtor_logicalKeyStoreName(), (config).Dtor_kmsConfiguration(), (_5_grantTokens).Dtor_value().(_dafny.Sequence), _0_kmsClient, _1_ddbClient))
	_25_client = _nw0
	res = m_Wrappers.Companion_Result_.Create_Success_(_25_client)
	return res
	return res
}