mirror of https://github.com/pulumi/pulumi.git
Update pu/pu apitype to support Deployments yaml marshalling (#16381)
<!--- Thanks so much for your contribution! If this is your first time contributing, please ensure that you have read the [CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md) documentation. --> # Description Add support for deployment settings YAML marshalling. This work is part of the effort to manage deployment settings through the CLI and source control. Fixes https://github.com/pulumi/pulumi-service/issues/20275 ## Checklist - [ ] I have run `make tidy` to update any new dependencies - [ ] I have run `make lint` to verify my code passes the lint check - [ ] I have formatted my code using `gofumpt` <!--- Please provide details if the checkbox below is to be left unchecked. --> - [ ] I have added tests that prove my fix is effective or that my feature works <!--- User-facing changes require a CHANGELOG entry. --> - [ ] I have run `make changelog` and committed the `changelog/pending/<file>` documenting my change <!-- If the change(s) in this PR is a modification of an existing call to the Pulumi Cloud, then the service should honor older versions of the CLI where this change would not exist. You must then bump the API version in /pkg/backend/httpstate/client/api.go, as well as add it to the service. --> - [ ] Yes, there are changes in this PR that warrants bumping the Pulumi Cloud API version <!-- @Pulumi employees: If yes, you must submit corresponding changes in the service repo. --> --------- Co-authored-by: Fraser Waters <fraser@pulumi.com>
This commit is contained in:
parent
486a10e677
commit
14293f7b28
sdk/go/common/apitype
|
@ -16,6 +16,7 @@ package apitype
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
|
@ -27,12 +28,33 @@ type PulumiOperation string
|
|||
|
||||
// The possible operations we can deploy.
|
||||
const (
|
||||
Update PulumiOperation = "update"
|
||||
Preview PulumiOperation = "preview"
|
||||
Destroy PulumiOperation = "destroy"
|
||||
Refresh PulumiOperation = "refresh"
|
||||
Update PulumiOperation = "update"
|
||||
Preview PulumiOperation = "preview"
|
||||
Destroy PulumiOperation = "destroy"
|
||||
Refresh PulumiOperation = "refresh"
|
||||
DetectDrift PulumiOperation = "detect-drift"
|
||||
RemediateDrift PulumiOperation = "remediate-drift"
|
||||
)
|
||||
|
||||
func ParsePulumiOperation(o string) (PulumiOperation, error) {
|
||||
switch o {
|
||||
case "update":
|
||||
return Update, nil
|
||||
case "preview":
|
||||
return Preview, nil
|
||||
case "destroy":
|
||||
return Destroy, nil
|
||||
case "refresh":
|
||||
return Refresh, nil
|
||||
case "detect-drift":
|
||||
return DetectDrift, nil
|
||||
case "remediate-drift":
|
||||
return RemediateDrift, nil
|
||||
default:
|
||||
return "", fmt.Errorf("invalid pulumi operation; %q", o)
|
||||
}
|
||||
}
|
||||
|
||||
// CreateDeploymentRequest defines the request payload that is expected when
|
||||
// creating a new deployment.
|
||||
type CreateDeploymentRequest struct {
|
||||
|
@ -53,23 +75,41 @@ type CreateDeploymentRequest struct {
|
|||
Operation *OperationContext `json:"operationContext,omitempty"`
|
||||
}
|
||||
|
||||
type DeploymentSettings struct {
|
||||
Tag string `json:"tag,omitempty" yaml:"tag,omitempty"`
|
||||
Executor *ExecutorContext `json:"executorContext,omitempty" yaml:"executorContext,omitempty"`
|
||||
SourceContext *SourceContext `json:"sourceContext,omitempty" yaml:"sourceContext,omitempty"`
|
||||
GitHub *DeploymentSettingsGitHub `json:"gitHub,omitempty" yaml:"gitHub,omitempty"`
|
||||
Operation *OperationContext `json:"operationContext,omitempty" yaml:"operationContext,omitempty"`
|
||||
AgentPoolID *string `json:"agentPoolID,omitempty" yaml:"agentPoolID,omitempty"`
|
||||
}
|
||||
|
||||
type DeploymentSettingsGitHub struct {
|
||||
Repository string `json:"repository,omitempty" yaml:"repository,omitempty"`
|
||||
PullRequestTemplate bool `json:"pullRequestTemplate,omitempty" yaml:"pullRequestTemplate,omitempty"`
|
||||
DeployCommits bool `json:"deployCommits,omitempty" yaml:"deployCommits,omitempty"`
|
||||
PreviewPullRequests bool `json:"previewPullRequests,omitempty" yaml:"previewPullRequests,omitempty"`
|
||||
DeployPullRequest *int64 `json:"deployPullRequest,omitempty" yaml:"deployPullRequest,omitempty"`
|
||||
Paths []string `json:"paths,omitempty" yaml:"paths,omitempty"`
|
||||
}
|
||||
|
||||
type ExecutorContext struct {
|
||||
// WorkingDirectory defines the path where the work should be done when executing.
|
||||
WorkingDirectory string `json:"workingDirectory"`
|
||||
WorkingDirectory string `json:"workingDirectory" yaml:"workingDirectory,omitempty"`
|
||||
|
||||
// Defines the image that the pulumi operations should run in.
|
||||
ExecutorImage *DockerImage `json:"executorImage,omitempty"`
|
||||
ExecutorImage *DockerImage `json:"executorImage,omitempty" yaml:"executorImage,omitempty"`
|
||||
}
|
||||
|
||||
// A DockerImage describes a Docker image reference + optional credentials for use with a job definition.
|
||||
type DockerImage struct {
|
||||
Reference string `json:"reference"`
|
||||
Credentials *DockerImageCredentials `json:"credentials,omitempty"`
|
||||
Reference string `json:"reference" yaml:"reference"`
|
||||
Credentials *DockerImageCredentials `json:"credentials,omitempty" yaml:"credentials,omitempty"`
|
||||
}
|
||||
|
||||
type dockerImageJSON struct {
|
||||
Reference string `json:"reference"`
|
||||
Credentials *DockerImageCredentials `json:"credentials,omitempty"`
|
||||
Reference string `json:"reference" yaml:"reference"`
|
||||
Credentials *DockerImageCredentials `json:"credentials,omitempty" yaml:"credentials,omitempty"`
|
||||
}
|
||||
|
||||
func (d *DockerImage) MarshalJSON() ([]byte, error) {
|
||||
|
@ -99,28 +139,28 @@ func (d *DockerImage) UnmarshalJSON(bytes []byte) error {
|
|||
|
||||
// DockerImageCredentials describes the credentials needed to access a Docker repository.
|
||||
type DockerImageCredentials struct {
|
||||
Username string `json:"username"`
|
||||
Password SecretValue `json:"password"`
|
||||
Username string `json:"username" yaml:"username"`
|
||||
Password SecretValue `json:"password" yaml:"password"`
|
||||
}
|
||||
|
||||
// SourceContext describes some source code, and how to obtain it.
|
||||
type SourceContext struct {
|
||||
Git *SourceContextGit `json:"git,omitempty"`
|
||||
Git *SourceContextGit `json:"git,omitempty" yaml:"git,omitempty"`
|
||||
}
|
||||
|
||||
type SourceContextGit struct {
|
||||
RepoURL string `json:"repoURL"`
|
||||
RepoURL string `json:"repoURL" yaml:"repoURL"`
|
||||
|
||||
Branch string `json:"branch"`
|
||||
Branch string `json:"branch" yaml:"branch"`
|
||||
|
||||
// (optional) RepoDir is the directory to work from in the project's source repository
|
||||
// where Pulumi.yaml is located. It is used in case Pulumi.yaml is not
|
||||
// in the project source root.
|
||||
RepoDir string `json:"repoDir,omitempty"`
|
||||
RepoDir string `json:"repoDir,omitempty" yaml:"repoDir"`
|
||||
|
||||
// (optional) Commit is the hash of the commit to deploy. If used, HEAD will be in detached mode. This
|
||||
// is mutually exclusive with the Branch setting. Either value needs to be specified.
|
||||
Commit string `json:"commit,omitempty"`
|
||||
Commit string `json:"commit,omitempty" yaml:"commit,omitempty"`
|
||||
|
||||
// (optional) GitAuth allows configuring git authentication options
|
||||
// There are 3 different authentication options:
|
||||
|
@ -130,7 +170,7 @@ type SourceContextGit struct {
|
|||
// Only one authentication mode will be considered if more than one option is specified,
|
||||
// with ssh private key/password preferred first, then personal access token, and finally
|
||||
// basic auth credentials.
|
||||
GitAuth *GitAuthConfig `json:"gitAuth,omitempty"`
|
||||
GitAuth *GitAuthConfig `json:"gitAuth,omitempty" yaml:"gitAuth,omitempty"`
|
||||
}
|
||||
|
||||
// GitAuthConfig specifies git authentication configuration options.
|
||||
|
@ -141,23 +181,23 @@ type SourceContextGit struct {
|
|||
//
|
||||
// Only 1 authentication mode is valid.
|
||||
type GitAuthConfig struct {
|
||||
PersonalAccessToken *SecretValue `json:"accessToken,omitempty"`
|
||||
SSHAuth *SSHAuth `json:"sshAuth,omitempty"`
|
||||
BasicAuth *BasicAuth `json:"basicAuth,omitempty"`
|
||||
PersonalAccessToken *SecretValue `json:"accessToken,omitempty" yaml:"accessToken,omitempty"`
|
||||
SSHAuth *SSHAuth `json:"sshAuth,omitempty" yaml:"sshAuth,omitempty"`
|
||||
BasicAuth *BasicAuth `json:"basicAuth,omitempty" yaml:"basicAuth,omitempty"`
|
||||
}
|
||||
|
||||
// SSHAuth configures ssh-based auth for git authentication.
|
||||
// SSHPrivateKey is required but password is optional.
|
||||
type SSHAuth struct {
|
||||
SSHPrivateKey SecretValue `json:"sshPrivateKey"`
|
||||
Password *SecretValue `json:"password,omitempty"`
|
||||
SSHPrivateKey SecretValue `json:"sshPrivateKey" yaml:"sshPrivateKey"`
|
||||
Password *SecretValue `json:"password,omitempty" yaml:"password,omitempty"`
|
||||
}
|
||||
|
||||
// BasicAuth configures git authentication through basic auth —
|
||||
// i.e. username and password. Both UserName and Password are required.
|
||||
type BasicAuth struct {
|
||||
UserName SecretValue `json:"userName"`
|
||||
Password SecretValue `json:"password"`
|
||||
UserName SecretValue `json:"userName" yaml:"userName"`
|
||||
Password SecretValue `json:"password" yaml:"password"`
|
||||
}
|
||||
|
||||
// OperationContext describes what to do.
|
||||
|
@ -165,22 +205,25 @@ type OperationContext struct {
|
|||
// PreRunCommands is an optional list of arbitrary commands to run before Pulumi
|
||||
// is invoked.
|
||||
// ref: https://github.com/pulumi/pulumi/issues/9397
|
||||
PreRunCommands []string `json:"preRunCommands"`
|
||||
PreRunCommands []string `json:"preRunCommands" yaml:"preRunCommands"`
|
||||
|
||||
// Operation is what we plan on doing.
|
||||
Operation PulumiOperation `json:"operation"`
|
||||
Operation PulumiOperation `json:"operation" yaml:"operation"`
|
||||
|
||||
// EnvironmentVariables contains environment variables to be applied during the execution.
|
||||
EnvironmentVariables map[string]SecretValue `json:"environmentVariables"`
|
||||
EnvironmentVariables map[string]SecretValue `json:"environmentVariables" yaml:"environmentVariables"`
|
||||
|
||||
// Options is a bag of settings to specify or override default behavior
|
||||
Options *OperationContextOptions `json:"options,omitempty"`
|
||||
Options *OperationContextOptions `json:"options,omitempty" yaml:"options,omitempty"`
|
||||
}
|
||||
|
||||
// OperationContextOptions is a bag of settings to specify or override default behavior in a deployment
|
||||
type OperationContextOptions struct {
|
||||
// SkipInstallDependencies sets whether to skip the default dependency installation step. Defaults to false.
|
||||
SkipInstallDependencies bool `json:"skipInstallDependencies"`
|
||||
SkipInstallDependencies bool `json:"skipInstallDependencies" yaml:"skipInstallDependencies"`
|
||||
SkipIntermediateDeployments bool `json:"skipIntermediateDeployments" yaml:"skipIntermediateDeployments"`
|
||||
Shell string `json:"shell" yaml:"shell"`
|
||||
DeleteAfterDestroy bool `json:"deleteAfterDestroy" yaml:"deleteAfterDestroy"`
|
||||
RemediateIfDriftDetected bool `json:"remediateIfDriftDetected" yaml:"remediateIfDriftDetected"`
|
||||
}
|
||||
|
||||
// CreateDeploymentResponse defines the response given when a new Deployment is created.
|
||||
|
|
Loading…
Reference in New Issue