-
Notifications
You must be signed in to change notification settings - Fork 17
/
awscdk_SecretValue.go
402 lines (343 loc) · 10.2 KB
/
awscdk_SecretValue.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
// An experiment to bundle the entire CDK into a single module
package awscdk
import (
_init_ "github.com/aws/aws-cdk-go/awscdk/jsii"
_jsii_ "github.com/aws/jsii-runtime-go/runtime"
)
// Work with secret values in the CDK.
//
// Constructs that need secrets will declare parameters of type `SecretValue`.
//
// The actual values of these secrets should not be committed to your
// repository, or even end up in the synthesized CloudFormation template. Instead, you should
// store them in an external system like AWS Secrets Manager or SSM Parameter
// Store, and you can reference them by calling `SecretValue.secretsManager()` or
// `SecretValue.ssmSecure()`.
//
// You can use `SecretValue.unsafePlainText()` to construct a `SecretValue` from a
// literal string, but doing so is highly discouraged.
//
// To make sure secret values don't accidentally end up in readable parts
// of your infrastructure definition (such as the environment variables
// of an AWS Lambda Function, where everyone who can read the function
// definition has access to the secret), using secret values directly is not
// allowed. You must pass them to constructs that accept `SecretValue`
// properties, which are guaranteed to use the value only in CloudFormation
// properties that are write-only.
//
// If you are sure that what you are doing is safe, you can call
// `secretValue.unsafeUnwrap()` to access the protected string of the secret
// value.
//
// (If you are writing something like an AWS Lambda Function and need to access
// a secret inside it, make the API call to `GetSecretValue` directly inside
// your Lamba's code, instead of using environment variables.)
//
// Example:
// // Read the secret from Secrets Manager
// pipeline := codepipeline.NewPipeline(this, jsii.String("MyPipeline"))
// sourceOutput := codepipeline.NewArtifact()
// sourceAction := codepipeline_actions.NewGitHubSourceAction(&gitHubSourceActionProps{
// actionName: jsii.String("GitHub_Source"),
// owner: jsii.String("awslabs"),
// repo: jsii.String("aws-cdk"),
// oauthToken: awscdk.SecretValue.secretsManager(jsii.String("my-github-token")),
// output: sourceOutput,
// branch: jsii.String("develop"),
// })
// pipeline.addStage(&stageOptions{
// stageName: jsii.String("Source"),
// actions: []iAction{
// sourceAction,
// },
// })
//
// Experimental.
type SecretValue interface {
Intrinsic
// The captured stack trace which represents the location in which this token was created.
// Experimental.
CreationStack() *[]*string
// Creates a throwable Error object that contains the token creation stack trace.
// Experimental.
NewError(message *string) interface{}
// Resolve the secret.
//
// If the feature flag is not set, resolve as normal. Otherwise, throw a descriptive
// error that the usage guard is missing.
// Experimental.
Resolve(context IResolveContext) interface{}
// Turn this Token into JSON.
//
// Called automatically when JSON.stringify() is called on a Token.
// Experimental.
ToJSON() interface{}
// Convert an instance of this Token to a string.
//
// This method will be called implicitly by language runtimes if the object
// is embedded into a string. We treat it the same as an explicit
// stringification.
// Experimental.
ToString() *string
// Disable usage protection on this secret.
//
// Call this to indicate that you want to use the secret value held by this
// object in an unchecked way. If you don't call this method, using the secret
// value directly in a string context or as a property value somewhere will
// produce an error.
//
// This method has 'unsafe' in the name on purpose! Make sure that the
// construct property you are using the returned value in is does not end up
// in a place in your AWS infrastructure where it could be read by anyone
// unexpected.
//
// When in doubt, don't call this method and only pass the object to constructs that
// accept `SecretValue` parameters.
// Experimental.
UnsafeUnwrap() *string
}
// The jsii proxy struct for SecretValue
type jsiiProxy_SecretValue struct {
jsiiProxy_Intrinsic
}
func (j *jsiiProxy_SecretValue) CreationStack() *[]*string {
var returns *[]*string
_jsii_.Get(
j,
"creationStack",
&returns,
)
return returns
}
// Construct a SecretValue (do not use!).
//
// Do not use the constructor directly: use one of the factory functions on the class
// instead.
// Experimental.
func NewSecretValue(protectedValue interface{}, options *IntrinsicProps) SecretValue {
_init_.Initialize()
if err := validateNewSecretValueParameters(protectedValue, options); err != nil {
panic(err)
}
j := jsiiProxy_SecretValue{}
_jsii_.Create(
"monocdk.SecretValue",
[]interface{}{protectedValue, options},
&j,
)
return &j
}
// Construct a SecretValue (do not use!).
//
// Do not use the constructor directly: use one of the factory functions on the class
// instead.
// Experimental.
func NewSecretValue_Override(s SecretValue, protectedValue interface{}, options *IntrinsicProps) {
_init_.Initialize()
_jsii_.Create(
"monocdk.SecretValue",
[]interface{}{protectedValue, options},
s,
)
}
// Obtain the secret value through a CloudFormation dynamic reference.
//
// If possible, use `SecretValue.ssmSecure` or `SecretValue.secretsManager` directly.
// Experimental.
func SecretValue_CfnDynamicReference(ref CfnDynamicReference) SecretValue {
_init_.Initialize()
if err := validateSecretValue_CfnDynamicReferenceParameters(ref); err != nil {
panic(err)
}
var returns SecretValue
_jsii_.StaticInvoke(
"monocdk.SecretValue",
"cfnDynamicReference",
[]interface{}{ref},
&returns,
)
return returns
}
// Obtain the secret value through a CloudFormation parameter.
//
// Generally, this is not a recommended approach. AWS Secrets Manager is the
// recommended way to reference secrets.
// Experimental.
func SecretValue_CfnParameter(param CfnParameter) SecretValue {
_init_.Initialize()
if err := validateSecretValue_CfnParameterParameters(param); err != nil {
panic(err)
}
var returns SecretValue
_jsii_.StaticInvoke(
"monocdk.SecretValue",
"cfnParameter",
[]interface{}{param},
&returns,
)
return returns
}
// Test whether an object is a SecretValue.
// Experimental.
func SecretValue_IsSecretValue(x interface{}) *bool {
_init_.Initialize()
if err := validateSecretValue_IsSecretValueParameters(x); err != nil {
panic(err)
}
var returns *bool
_jsii_.StaticInvoke(
"monocdk.SecretValue",
"isSecretValue",
[]interface{}{x},
&returns,
)
return returns
}
// Construct a literal secret value for use with secret-aware constructs.
//
// Do not use this method for any secrets that you care about! The value
// will be visible to anyone who has access to the CloudFormation template
// (via the AWS Console, SDKs, or CLI).
//
// The only reasonable use case for using this method is when you are testing.
// Deprecated: Use `unsafePlainText()` instead.
func SecretValue_PlainText(secret *string) SecretValue {
_init_.Initialize()
if err := validateSecretValue_PlainTextParameters(secret); err != nil {
panic(err)
}
var returns SecretValue
_jsii_.StaticInvoke(
"monocdk.SecretValue",
"plainText",
[]interface{}{secret},
&returns,
)
return returns
}
// Use a resource's output as secret value.
// Experimental.
func SecretValue_ResourceAttribute(attr *string) SecretValue {
_init_.Initialize()
if err := validateSecretValue_ResourceAttributeParameters(attr); err != nil {
panic(err)
}
var returns SecretValue
_jsii_.StaticInvoke(
"monocdk.SecretValue",
"resourceAttribute",
[]interface{}{attr},
&returns,
)
return returns
}
// Creates a `SecretValue` with a value which is dynamically loaded from AWS Secrets Manager.
// Experimental.
func SecretValue_SecretsManager(secretId *string, options *SecretsManagerSecretOptions) SecretValue {
_init_.Initialize()
if err := validateSecretValue_SecretsManagerParameters(secretId, options); err != nil {
panic(err)
}
var returns SecretValue
_jsii_.StaticInvoke(
"monocdk.SecretValue",
"secretsManager",
[]interface{}{secretId, options},
&returns,
)
return returns
}
// Use a secret value stored from a Systems Manager (SSM) parameter.
// Experimental.
func SecretValue_SsmSecure(parameterName *string, version *string) SecretValue {
_init_.Initialize()
if err := validateSecretValue_SsmSecureParameters(parameterName); err != nil {
panic(err)
}
var returns SecretValue
_jsii_.StaticInvoke(
"monocdk.SecretValue",
"ssmSecure",
[]interface{}{parameterName, version},
&returns,
)
return returns
}
// Construct a literal secret value for use with secret-aware constructs.
//
// Do not use this method for any secrets that you care about! The value
// will be visible to anyone who has access to the CloudFormation template
// (via the AWS Console, SDKs, or CLI).
//
// The only reasonable use case for using this method is when you are testing.
// Experimental.
func SecretValue_UnsafePlainText(secret *string) SecretValue {
_init_.Initialize()
if err := validateSecretValue_UnsafePlainTextParameters(secret); err != nil {
panic(err)
}
var returns SecretValue
_jsii_.StaticInvoke(
"monocdk.SecretValue",
"unsafePlainText",
[]interface{}{secret},
&returns,
)
return returns
}
func (s *jsiiProxy_SecretValue) NewError(message *string) interface{} {
if err := s.validateNewErrorParameters(message); err != nil {
panic(err)
}
var returns interface{}
_jsii_.Invoke(
s,
"newError",
[]interface{}{message},
&returns,
)
return returns
}
func (s *jsiiProxy_SecretValue) Resolve(context IResolveContext) interface{} {
if err := s.validateResolveParameters(context); err != nil {
panic(err)
}
var returns interface{}
_jsii_.Invoke(
s,
"resolve",
[]interface{}{context},
&returns,
)
return returns
}
func (s *jsiiProxy_SecretValue) ToJSON() interface{} {
var returns interface{}
_jsii_.Invoke(
s,
"toJSON",
nil, // no parameters
&returns,
)
return returns
}
func (s *jsiiProxy_SecretValue) ToString() *string {
var returns *string
_jsii_.Invoke(
s,
"toString",
nil, // no parameters
&returns,
)
return returns
}
func (s *jsiiProxy_SecretValue) UnsafeUnwrap() *string {
var returns *string
_jsii_.Invoke(
s,
"unsafeUnwrap",
nil, // no parameters
&returns,
)
return returns
}