func()

in releases/go/mpl/AwsCryptographyMaterialProvidersOperations/AwsCryptographyMaterialProvidersOperations.go [584:769]


func (_static *CompanionStruct_Default___) CreateAwsKmsHierarchicalKeyring(config Config, input m_AwsCryptographyMaterialProvidersTypes.CreateAwsKmsHierarchicalKeyringInput) m_Wrappers.Result {
	var output m_Wrappers.Result = m_Wrappers.Result{}
	_ = output
	var _0_cmc m_AwsCryptographyMaterialProvidersTypes.ICryptographicMaterialsCache = (m_AwsCryptographyMaterialProvidersTypes.ICryptographicMaterialsCache)(nil)
	_ = _0_cmc
	if ((input).Dtor_cache()).Is_Some() {
		var _1_valueOrError0 m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default()
		_ = _1_valueOrError0
		var _out0 m_Wrappers.Outcome
		_ = _out0
		_out0 = Companion_Default___.CheckCache(((input).Dtor_cache()).Dtor_value().(m_AwsCryptographyMaterialProvidersTypes.CacheType), (input).Dtor_ttlSeconds())
		_1_valueOrError0 = _out0
		if (_1_valueOrError0).IsFailure() {
			output = (_1_valueOrError0).PropagateFailure()
			return output
		}
		var _source0 m_AwsCryptographyMaterialProvidersTypes.CacheType = ((input).Dtor_cache()).Dtor_value().(m_AwsCryptographyMaterialProvidersTypes.CacheType)
		_ = _source0
		{
			{
				if _source0.Is_Shared() {
					var _2_c m_AwsCryptographyMaterialProvidersTypes.ICryptographicMaterialsCache = _source0.Get_().(m_AwsCryptographyMaterialProvidersTypes.CacheType_Shared).Shared
					_ = _2_c
					_0_cmc = _2_c
					goto Lmatch0
				}
			}
			{
				var _3_valueOrError1 m_Wrappers.Result = m_Wrappers.Result{}
				_ = _3_valueOrError1
				var _out1 m_Wrappers.Result
				_ = _out1
				_out1 = Companion_Default___.CreateCryptographicMaterialsCache(config, m_AwsCryptographyMaterialProvidersTypes.Companion_CreateCryptographicMaterialsCacheInput_.Create_CreateCryptographicMaterialsCacheInput_(((input).Dtor_cache()).Dtor_value().(m_AwsCryptographyMaterialProvidersTypes.CacheType)))
				_3_valueOrError1 = _out1
				if (_3_valueOrError1).IsFailure() {
					output = (_3_valueOrError1).PropagateFailure()
					return output
				}
				_0_cmc = m_AwsCryptographyMaterialProvidersTypes.Companion_ICryptographicMaterialsCache_.CastTo_((_3_valueOrError1).Extract())
			}
			goto Lmatch0
		}
	Lmatch0:
	} else {
		var _4_valueOrError2 m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default()
		_ = _4_valueOrError2
		var _out2 m_Wrappers.Outcome
		_ = _out2
		_out2 = Companion_Default___.CheckCache(m_AwsCryptographyMaterialProvidersTypes.Companion_CacheType_.Create_StormTracking_(m_StormTracker.Companion_Default___.DefaultStorm()), (input).Dtor_ttlSeconds())
		_4_valueOrError2 = _out2
		if (_4_valueOrError2).IsFailure() {
			output = (_4_valueOrError2).PropagateFailure()
			return output
		}
		var _5_valueOrError3 m_Wrappers.Result = m_Wrappers.Result{}
		_ = _5_valueOrError3
		var _out3 m_Wrappers.Result
		_ = _out3
		_out3 = Companion_Default___.CreateCryptographicMaterialsCache(config, m_AwsCryptographyMaterialProvidersTypes.Companion_CreateCryptographicMaterialsCacheInput_.Create_CreateCryptographicMaterialsCacheInput_(m_AwsCryptographyMaterialProvidersTypes.Companion_CacheType_.Create_Default_(m_AwsCryptographyMaterialProvidersTypes.Companion_DefaultCache_.Create_DefaultCache_(int32(1000)))))
		_5_valueOrError3 = _out3
		if (_5_valueOrError3).IsFailure() {
			output = (_5_valueOrError3).PropagateFailure()
			return output
		}
		_0_cmc = m_AwsCryptographyMaterialProvidersTypes.Companion_ICryptographicMaterialsCache_.CastTo_((_5_valueOrError3).Extract())
	}
	var _6_partitionIdBytes _dafny.Sequence = _dafny.EmptySeq
	_ = _6_partitionIdBytes
	if ((input).Dtor_partitionId()).Is_Some() {
		var _7_valueOrError4 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(m_UTF8.Companion_ValidUTF8Bytes_.Witness())
		_ = _7_valueOrError4
		_7_valueOrError4 = (m_UTF8.Encode(((input).Dtor_partitionId()).Dtor_value().(_dafny.Sequence))).MapFailure(func(coer132 func(_dafny.Sequence) m_AwsCryptographyMaterialProvidersTypes.Error) func(interface{}) interface{} {
			return func(arg133 interface{}) interface{} {
				return coer132(arg133.(_dafny.Sequence))
			}
		}(func(_8_e _dafny.Sequence) m_AwsCryptographyMaterialProvidersTypes.Error {
			return m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographicMaterialProvidersException_(_dafny.Companion_Sequence_.Concatenate(_dafny.SeqOfString("Could not UTF-8 Encode Partition ID: "), _8_e))
		}))
		if (_7_valueOrError4).IsFailure() {
			output = (_7_valueOrError4).PropagateFailure()
			return output
		}
		_6_partitionIdBytes = (_7_valueOrError4).Extract().(_dafny.Sequence)
	} else {
		var _9_uuid_q m_Wrappers.Result
		_ = _9_uuid_q
		var _out4 m_Wrappers.Result
		_ = _out4
		_out4 = m_UUID.GenerateUUID()
		_9_uuid_q = _out4
		var _10_valueOrError5 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq.SetString())
		_ = _10_valueOrError5
		_10_valueOrError5 = (_9_uuid_q).MapFailure(func(coer133 func(_dafny.Sequence) m_AwsCryptographyMaterialProvidersTypes.Error) func(interface{}) interface{} {
			return func(arg134 interface{}) interface{} {
				return coer133(arg134.(_dafny.Sequence))
			}
		}(func(_11_e _dafny.Sequence) m_AwsCryptographyMaterialProvidersTypes.Error {
			return m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographicMaterialProvidersException_(_11_e)
		}))
		if (_10_valueOrError5).IsFailure() {
			output = (_10_valueOrError5).PropagateFailure()
			return output
		}
		var _12_uuid _dafny.Sequence
		_ = _12_uuid
		_12_uuid = (_10_valueOrError5).Extract().(_dafny.Sequence)
		var _13_valueOrError6 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(_dafny.EmptySeq)
		_ = _13_valueOrError6
		_13_valueOrError6 = (m_UUID.ToByteArray(_12_uuid)).MapFailure(func(coer134 func(_dafny.Sequence) m_AwsCryptographyMaterialProvidersTypes.Error) func(interface{}) interface{} {
			return func(arg135 interface{}) interface{} {
				return coer134(arg135.(_dafny.Sequence))
			}
		}(func(_14_e _dafny.Sequence) m_AwsCryptographyMaterialProvidersTypes.Error {
			return m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographicMaterialProvidersException_(_14_e)
		}))
		if (_13_valueOrError6).IsFailure() {
			output = (_13_valueOrError6).PropagateFailure()
			return output
		}
		_6_partitionIdBytes = (_13_valueOrError6).Extract().(_dafny.Sequence)
	}
	var _15_getKeyStoreInfoOutput_q m_Wrappers.Result
	_ = _15_getKeyStoreInfoOutput_q
	var _out5 m_Wrappers.Result
	_ = _out5
	_out5 = ((input).Dtor_keyStore()).GetKeyStoreInfo()
	_15_getKeyStoreInfoOutput_q = _out5
	var _16_valueOrError7 m_Wrappers.Result = m_Wrappers.Result{}
	_ = _16_valueOrError7
	_16_valueOrError7 = (_15_getKeyStoreInfoOutput_q).MapFailure(func(coer135 func(m_AwsCryptographyKeyStoreTypes.Error) m_AwsCryptographyMaterialProvidersTypes.Error) func(interface{}) interface{} {
		return func(arg136 interface{}) interface{} {
			return coer135(arg136.(m_AwsCryptographyKeyStoreTypes.Error))
		}
	}(func(_17_e m_AwsCryptographyKeyStoreTypes.Error) m_AwsCryptographyMaterialProvidersTypes.Error {
		return m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographyKeyStore_(_17_e)
	}))
	if (_16_valueOrError7).IsFailure() {
		output = (_16_valueOrError7).PropagateFailure()
		return output
	}
	var _18_getKeyStoreInfoOutput m_AwsCryptographyKeyStoreTypes.GetKeyStoreInfoOutput
	_ = _18_getKeyStoreInfoOutput
	_18_getKeyStoreInfoOutput = (_16_valueOrError7).Extract().(m_AwsCryptographyKeyStoreTypes.GetKeyStoreInfoOutput)
	var _19_logicalKeyStoreName _dafny.Sequence
	_ = _19_logicalKeyStoreName
	_19_logicalKeyStoreName = (_18_getKeyStoreInfoOutput).Dtor_logicalKeyStoreName()
	var _20_valueOrError8 m_Wrappers.Result = m_Wrappers.Companion_Result_.Default(m_UTF8.Companion_ValidUTF8Bytes_.Witness())
	_ = _20_valueOrError8
	_20_valueOrError8 = (m_UTF8.Encode(_19_logicalKeyStoreName)).MapFailure(func(coer136 func(_dafny.Sequence) m_AwsCryptographyMaterialProvidersTypes.Error) func(interface{}) interface{} {
		return func(arg137 interface{}) interface{} {
			return coer136(arg137.(_dafny.Sequence))
		}
	}(func(_21_e _dafny.Sequence) m_AwsCryptographyMaterialProvidersTypes.Error {
		return m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographicMaterialProvidersException_(_dafny.Companion_Sequence_.Concatenate(_dafny.SeqOfString("Could not UTF-8 Encode Logical Key Store Name: "), _21_e))
	}))
	if (_20_valueOrError8).IsFailure() {
		output = (_20_valueOrError8).PropagateFailure()
		return output
	}
	var _22_logicalKeyStoreNameBytes _dafny.Sequence
	_ = _22_logicalKeyStoreNameBytes
	_22_logicalKeyStoreNameBytes = (_20_valueOrError8).Extract().(_dafny.Sequence)
	var _23_valueOrError9 m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default()
	_ = _23_valueOrError9
	_23_valueOrError9 = m_Wrappers.Companion_Default___.Need((((input).Dtor_branchKeyId()).Is_None()) || (((input).Dtor_branchKeyIdSupplier()).Is_None()), m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographicMaterialProvidersException_(_dafny.SeqOfString("Cannot initialize keyring with both a branchKeyId and BranchKeyIdSupplier.")))
	if (_23_valueOrError9).IsFailure() {
		output = (_23_valueOrError9).PropagateFailure()
		return output
	}
	var _24_valueOrError10 m_Wrappers.Outcome = m_Wrappers.Companion_Outcome_.Default()
	_ = _24_valueOrError10
	_24_valueOrError10 = m_Wrappers.Companion_Default___.Need((((input).Dtor_branchKeyId()).Is_Some()) || (((input).Dtor_branchKeyIdSupplier()).Is_Some()), m_AwsCryptographyMaterialProvidersTypes.Companion_Error_.Create_AwsCryptographicMaterialProvidersException_(_dafny.SeqOfString("Must initialize keyring with either branchKeyId or BranchKeyIdSupplier.")))
	if (_24_valueOrError10).IsFailure() {
		output = (_24_valueOrError10).PropagateFailure()
		return output
	}
	var _25_keyring *m_AwsKmsHierarchicalKeyring.AwsKmsHierarchicalKeyring
	_ = _25_keyring
	var _nw0 *m_AwsKmsHierarchicalKeyring.AwsKmsHierarchicalKeyring = m_AwsKmsHierarchicalKeyring.New_AwsKmsHierarchicalKeyring_()
	_ = _nw0
	_nw0.Ctor__((input).Dtor_keyStore(), (input).Dtor_branchKeyId(), (input).Dtor_branchKeyIdSupplier(), (input).Dtor_ttlSeconds(), _0_cmc, _6_partitionIdBytes, _22_logicalKeyStoreNameBytes, (config).Dtor_crypto())
	_25_keyring = _nw0
	output = m_Wrappers.Companion_Result_.Create_Success_(_25_keyring)
	return output
	return output
}