Class: AWSCDK::GetContextValueOptions

Inherits:
GetContextKeyOptions
  • Object
show all
Defined in:
get_context_value_options.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(provider:, additional_cache_key: nil, include_environment: nil, props: nil, dummy_value:, ignore_error_on_missing_context: nil, must_exist: nil) ⇒ GetContextValueOptions

Returns a new instance of GetContextValueOptions.

Parameters:

  • provider (String)

    The context provider to query.

  • additional_cache_key (String, nil) (defaults to: nil)

    Adds an additional discriminator to the cdk.context.json cache key.

  • include_environment (Boolean, nil) (defaults to: nil)

    Whether to include the stack's account and region automatically.

  • props (Hash{String => Object}, nil) (defaults to: nil)

    Provider-specific properties.

  • dummy_value (Object)

    The value to return if the lookup has not yet been performed.

  • ignore_error_on_missing_context (Boolean, nil) (defaults to: nil)

    Ignore a lookup failure and return the dummyValue instead.

  • must_exist (Boolean, nil) (defaults to: nil)

    Whether the resource must exist.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'get_context_value_options.rb', line 13

def initialize(provider:, additional_cache_key: nil, include_environment: nil, props: nil, dummy_value:, ignore_error_on_missing_context: nil, must_exist: nil)
  @provider = provider
  Jsii::Type.check_type(@provider, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "provider")
  @additional_cache_key = additional_cache_key
  Jsii::Type.check_type(@additional_cache_key, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "additionalCacheKey") unless @additional_cache_key.nil?
  @include_environment = include_environment
  Jsii::Type.check_type(@include_environment, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJib29sZWFuIn0=")), "includeEnvironment") unless @include_environment.nil?
  @props = props
  Jsii::Type.check_type(@props, JSON.parse(Base64.strict_decode64("eyJjb2xsZWN0aW9uIjp7ImVsZW1lbnR0eXBlIjp7InByaW1pdGl2ZSI6ImFueSJ9LCJraW5kIjoibWFwIn19")), "props") unless @props.nil?
  @dummy_value = dummy_value
  Jsii::Type.check_type(@dummy_value, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJhbnkifQ==")), "dummyValue")
  @ignore_error_on_missing_context = ignore_error_on_missing_context
  Jsii::Type.check_type(@ignore_error_on_missing_context, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJib29sZWFuIn0=")), "ignoreErrorOnMissingContext") unless @ignore_error_on_missing_context.nil?
  @must_exist = must_exist
  Jsii::Type.check_type(@must_exist, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJib29sZWFuIn0=")), "mustExist") unless @must_exist.nil?
end

Instance Attribute Details

#additional_cache_keyString? (readonly)

Note:

Default: - no additional cache key

Adds an additional discriminator to the cdk.context.json cache key.

Returns:

  • (String, nil)


38
39
40
# File 'get_context_value_options.rb', line 38

def additional_cache_key
  @additional_cache_key
end

#dummy_valueObject (readonly)

The value to return if the lookup has not yet been performed.

Upon first synthesis, the lookups has not yet been performed. The get_value() operation returns this value instead, so that synthesis can proceed. After synthesis completes the first time, the actual lookup will be performed and synthesis will run again with the real value.

Dummy values should preferably have valid shapes so that downstream consumers of lookup values don't throw validation exceptions if they encounter a dummy value (or all possible downstream consumers need to effectively check for the well-known shape of the dummy value); throwing an exception would error out the synthesis operation and prevent the lookup and the second, real, synthesis from happening.

Connection to mustExist

dummy_value is also used as the official value to return if the lookup has failed and mustExist == false.

Returns:

  • (Object)


68
69
70
# File 'get_context_value_options.rb', line 68

def dummy_value
  @dummy_value
end

#ignore_error_on_missing_contextBoolean? (readonly)

Deprecated.

Use mustExist instead

Note:

Default: false

Ignore a lookup failure and return the dummyValue instead.

must_exist is the recommended alias for this deprecated property (note that its value is reversed).

Returns:

  • (Boolean, nil)


77
78
79
# File 'get_context_value_options.rb', line 77

def ignore_error_on_missing_context
  @ignore_error_on_missing_context
end

#include_environmentBoolean? (readonly)

Note:

Default: true

Whether to include the stack's account and region automatically.

Returns:

  • (Boolean, nil)


43
44
45
# File 'get_context_value_options.rb', line 43

def include_environment
  @include_environment
end

#must_existBoolean? (readonly)

Note:

Default: true

Whether the resource must exist.

If this is set (the default), the query fails if the value or resource we tried to look up doesn't exist.

If this is false and the value we tried to look up could not be found, the failure is suppressed and dummy_value is officially returned instead.

When this happens, dummy_value is encoded into cached context and it will never be refreshed anymore until the user runs cdk context --reset <key>.

Note that it is not possible for the CDK app code to make a distinction between "the lookup has not been performed yet" and "the lookup didn't find anything and we returned a default value instead".

Context providers

This feature must explicitly be supported by context providers. It is currently supported by:

  • KMS key provider
  • SSM parameter provider

Note to implementors

The dummy value should not be returned for all SDK lookup failures. For example, "no network" or "no credentials" or "malformed query" should not lead to the dummy value being returned. Only the case of "no such resource" should.

Returns:

  • (Boolean, nil)


110
111
112
# File 'get_context_value_options.rb', line 110

def must_exist
  @must_exist
end

#propsHash{String => Object}? (readonly)

Provider-specific properties.

Returns:

  • (Hash{String => Object}, nil)


47
48
49
# File 'get_context_value_options.rb', line 47

def props
  @props
end

#providerString (readonly)

The context provider to query.

Returns:

  • (String)


33
34
35
# File 'get_context_value_options.rb', line 33

def provider
  @provider
end

Class Method Details

.jsii_propertiesObject



112
113
114
115
116
117
118
119
120
121
122
# File 'get_context_value_options.rb', line 112

def self.jsii_properties
  {
    :provider => "provider",
    :additional_cache_key => "additionalCacheKey",
    :include_environment => "includeEnvironment",
    :props => "props",
    :dummy_value => "dummyValue",
    :ignore_error_on_missing_context => "ignoreErrorOnMissingContext",
    :must_exist => "mustExist",
  }
end

Instance Method Details

#to_jsiiObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'get_context_value_options.rb', line 124

def to_jsii
  result = {}
  result.merge!(super)
  result.merge!({
    "provider" => @provider,
    "additionalCacheKey" => @additional_cache_key,
    "includeEnvironment" => @include_environment,
    "props" => @props,
    "dummyValue" => @dummy_value,
    "ignoreErrorOnMissingContext" => @ignore_error_on_missing_context,
    "mustExist" => @must_exist,
  })
  result.compact
end