Skip to content

Commit

Permalink
Adding support for secrets in all values in DeploymentSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
IaroslavTitov committed Dec 10, 2024
1 parent 19ba5be commit 07891ea
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 28 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ ci-scripts
.mono
/go/
*.sln
.config/
.gradle/
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### Improvements
- Added secret support for all fields in DeploymentSettings [#419](https://github.com/pulumi/pulumi-pulumiservice/issues/419)

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion examples/ts-deployment-settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ const settings = new service.DeploymentSettings("deployment_settings", {
}
},
cacheOptions: {
enable: true,
enable: pulumi.secret(true),
}
});
52 changes: 25 additions & 27 deletions provider/pkg/provider/deployment_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ func (ds *PulumiServiceDeploymentSettingsResource) ToPulumiServiceDeploymentSett
input.Stack.ProjectName = getSecretOrStringValue(inputMap["project"])
input.Stack.StackName = getSecretOrStringValue(inputMap["stack"])

if inputMap["agentPoolId"].HasValue() && inputMap["agentPoolId"].IsString() {
input.AgentPoolId = inputMap["agentPoolId"].StringValue()
if inputMap["agentPoolId"].HasValue() {
input.AgentPoolId = getSecretOrStringValue(inputMap["agentPoolId"])
}

input.ExecutorContext = toExecutorContext(inputMap)
Expand Down Expand Up @@ -327,17 +327,17 @@ func toGitHubConfig(inputMap resource.PropertyMap) *pulumiapi.GitHubConfiguratio
github.Repository = getSecretOrStringValue(githubInput["repository"])
}

if githubInput["deployCommits"].HasValue() && githubInput["deployCommits"].IsBool() {
github.DeployCommits = githubInput["deployCommits"].BoolValue()
if githubInput["deployCommits"].HasValue() {
github.DeployCommits = getSecretOrBoolValue(githubInput["deployCommits"])
}
if githubInput["previewPullRequests"].HasValue() && githubInput["previewPullRequests"].IsBool() {
github.PreviewPullRequests = githubInput["previewPullRequests"].BoolValue()
if githubInput["previewPullRequests"].HasValue() {
github.PreviewPullRequests = getSecretOrBoolValue(githubInput["previewPullRequests"])
}
if githubInput["pullRequestTemplate"].HasValue() && githubInput["pullRequestTemplate"].IsBool() {
github.PullRequestTemplate = githubInput["pullRequestTemplate"].BoolValue()
if githubInput["pullRequestTemplate"].HasValue() {
github.PullRequestTemplate = getSecretOrBoolValue(githubInput["pullRequestTemplate"])
}
if githubInput["paths"].HasValue() && githubInput["paths"].IsArray() {
pathsInput := githubInput["paths"].ArrayValue()
if githubInput["paths"].HasValue() {
pathsInput := getSecretOrArrayValue(githubInput["paths"])
paths := make([]string, len(pathsInput))

for i, v := range pathsInput {
Expand Down Expand Up @@ -445,14 +445,12 @@ func toOperationContext(inputMap resource.PropertyMap) *pulumiapi.OperationConte
oc.EnvironmentVariables = ev
}

if ocInput["preRunCommands"].HasValue() && ocInput["preRunCommands"].IsArray() {
pcInput := ocInput["preRunCommands"].ArrayValue()
if ocInput["preRunCommands"].HasValue() {
pcInput := getSecretOrArrayValue(ocInput["preRunCommands"])
pc := make([]string, len(pcInput))

for i, v := range pcInput {
if v.IsString() {
pc[i] = v.StringValue()
}
pc[i] = getSecretOrStringValue(v)
}

oc.PreRunCommands = pc
Expand All @@ -462,20 +460,20 @@ func toOperationContext(inputMap resource.PropertyMap) *pulumiapi.OperationConte
oInput := ocInput["options"].ObjectValue()
var o pulumiapi.OperationContextOptions

if oInput["skipInstallDependencies"].HasValue() && oInput["skipInstallDependencies"].IsBool() {
o.SkipInstallDependencies = oInput["skipInstallDependencies"].BoolValue()
if oInput["skipInstallDependencies"].HasValue() {
o.SkipInstallDependencies = getSecretOrBoolValue(oInput["skipInstallDependencies"])
}

if oInput["skipIntermediateDeployments"].HasValue() && oInput["skipIntermediateDeployments"].IsBool() {
o.SkipIntermediateDeployments = oInput["skipIntermediateDeployments"].BoolValue()
if oInput["skipIntermediateDeployments"].HasValue() {
o.SkipIntermediateDeployments = getSecretOrBoolValue(oInput["skipIntermediateDeployments"])
}

if oInput["Shell"].HasValue() && oInput["Shell"].IsString() {
o.Shell = oInput["Shell"].StringValue()
if oInput["Shell"].HasValue() {
o.Shell = getSecretOrStringValue(oInput["Shell"])
}

if oInput["deleteAfterDestroy"].HasValue() && oInput["deleteAfterDestroy"].IsBool() {
o.DeleteAfterDestroy = oInput["deleteAfterDestroy"].BoolValue()
if oInput["deleteAfterDestroy"].HasValue() {
o.DeleteAfterDestroy = getSecretOrBoolValue(oInput["deleteAfterDestroy"])
}

oc.Options = &o
Expand All @@ -498,8 +496,8 @@ func toOperationContext(inputMap resource.PropertyMap) *pulumiapi.OperationConte
if awsInput["sessionName"].HasValue() {
aws.SessionName = getSecretOrStringValue(awsInput["sessionName"])
}
if awsInput["policyARNs"].HasValue() && awsInput["policyARNs"].IsArray() {
policyARNsInput := awsInput["policyARNs"].ArrayValue()
if awsInput["policyARNs"].HasValue() {
policyARNsInput := getSecretOrArrayValue(awsInput["policyARNs"])
policyARNs := make([]string, len(policyARNsInput))

for i, v := range policyARNsInput {
Expand Down Expand Up @@ -569,8 +567,8 @@ func toCacheOptions(inputMap resource.PropertyMap) *pulumiapi.CacheOptions {
coInput := inputMap["cacheOptions"].ObjectValue()
var co pulumiapi.CacheOptions

if coInput["enable"].HasValue() && coInput["enable"].IsBool() {
co.Enable = coInput["enable"].BoolValue()
if coInput["enable"].HasValue() {
co.Enable = getSecretOrBoolValue(coInput["enable"])
}

return &co
Expand Down
18 changes: 18 additions & 0 deletions provider/pkg/provider/secret_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ func getSecretOrStringNullableValue(prop resource.PropertyValue) *string {
return &resultString
}

func getSecretOrBoolValue(prop resource.PropertyValue) bool {
switch prop.V.(type) {
case *resource.Secret:
return prop.SecretValue().Element.BoolValue()
default:
return prop.BoolValue()
}
}

func getSecretOrArrayValue(prop resource.PropertyValue) []resource.PropertyValue {
switch prop.V.(type) {
case *resource.Secret:
return prop.SecretValue().Element.ArrayValue()
default:
return prop.ArrayValue()
}
}

// All imported inputs will have a dummy value, asking to be replaced in real code
// All imported properties are just set to ciphertext read from Pulumi Service
func importSecretValue(propertyMap resource.PropertyMap, propertyName string, cipherValue pulumiapi.SecretValue, isInput bool) {
Expand Down

0 comments on commit 07891ea

Please sign in to comment.