-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
variable.ts
85 lines (75 loc) · 2.3 KB
/
variable.ts
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
import { CfnPipeline } from './codepipeline.generated';
import { validatePipelineVariableName } from './private/validation';
import { Token } from '../../core';
/**
* Properties of pipeline-level variable.
*/
export interface VariableProps {
/**
* The name of a pipeline-level variable.
*/
readonly variableName: string;
/**
* The description of a pipeline-level variable. It's used to add additional context
* about the variable, and not being used at time when pipeline executes.
*
* @default - No description.
*/
readonly description?: string;
/**
* The default value of a pipeline-level variable.
*
* @default - No default value.
*/
readonly defaultValue?: string;
}
/**
* Pipeline-Level variable.
*/
export class Variable {
/**
* The name of a pipeline-level variable.
*/
public readonly variableName: string;
private readonly description?: string;
private readonly defaultValue?: string;
constructor(props: VariableProps) {
this.variableName = props.variableName;
this.description = props.description;
this.defaultValue = props.defaultValue;
this.validate();
}
private validate() {
validatePipelineVariableName(this.variableName);
if (
this.defaultValue !== undefined
&& !Token.isUnresolved(this.defaultValue)
&& (this.defaultValue.length < 1 || this.defaultValue.length > 1000)
) {
throw new Error(`Default value for variable '${this.variableName}' must be between 1 and 1000 characters long, got ${this.defaultValue.length}`);
}
if (this.description !== undefined && !Token.isUnresolved(this.description) && this.description.length > 200) {
throw new Error(`Description for variable '${this.variableName}' must not be greater than 200 characters long, got ${this.description.length}`);
}
}
/**
* Reference the variable name at Pipeline actions.
*
* @returns The variable name in a format that can be referenced at Pipeline actions
*/
public reference(): string {
return `#{variables.${this.variableName}}`;
}
/**
* Render to CloudFormation property.
*
* @internal
*/
public _render(): CfnPipeline.VariableDeclarationProperty {
return {
defaultValue: this.defaultValue,
description: this.description,
name: this.variableName,
};
}
}