├── dce ├── docs ├── dce-logo.png ├── update_docs.go ├── dce_auth.md ├── dce_docs.md ├── dce_configure.md ├── dce_system_users_add.md ├── dce_accounts_list.md ├── dce_admin_login.md ├── dce_login.md ├── dce_system_logs_reset.md ├── dce_system_logs_usage.md ├── dce_system_logs_leases.md ├── dce_accounts_login.md ├── dce_system_users_remove.md ├── dce_accounts_release.md ├── dce_accounts_request.md ├── dce_admin_upgrade.md ├── dce_leases_describe.md ├── dce_system_logs_accounts.md ├── dce_version.md ├── dce_leases_add.md ├── dce_accounts_describe.md ├── dce_leases_remove.md ├── dce_system.md ├── dce_admin_accounts_describe.md ├── dce_accounts_remove.md ├── dce_admin_accounts_list.md ├── dce_system_users.md ├── dce_admin_init.md ├── dce_system_init.md ├── dce_admin_accounts_add.md ├── dce_admin_accounts_remove.md ├── dce_init.md ├── dce_system_logs.md ├── dce_usage.md ├── dce_accounts.md ├── dce_admin.md ├── dce_accounts_add.md ├── dce_leases_end.md ├── dce_admin_accounts.md ├── dce_leases.md ├── dce_leases_create.md ├── dce.md ├── dce_leases_login.md ├── dce_leases_list.md └── dce_system_deploy.md ├── update_docs ├── main.go ├── internal ├── constants │ ├── prompts.go │ ├── constants_windows.go │ ├── constants_unix.go │ ├── contextkeys.go │ ├── github.go │ └── defaults.go ├── observation │ ├── logging.go │ └── observation.go └── util │ ├── prompt.go │ ├── github.go │ ├── web.go │ ├── ifaces.go │ ├── duration.go │ ├── api.go │ └── session.go ├── tests ├── unit │ ├── examples │ │ ├── README.txt │ │ └── maintf-basic.example │ ├── config_test.go │ ├── terraform_test.go │ ├── common.go │ ├── duration_test.go │ └── tftemplate_test.go └── integration │ ├── githuber.go │ ├── util.go │ ├── mock_prompter.go │ └── auth_test.go ├── NOTICE.txt ├── cmd ├── auth.go ├── init.go ├── version.go ├── usage.go └── accounts.go ├── mocks ├── Initer.go ├── Weber.go ├── Usager.go ├── Authenticater.go ├── Githuber.go ├── TerraformBinDownloader.go ├── OutputWriter.go ├── Accounter.go ├── Deployer.go ├── Prompter.go ├── TFTemplater.go ├── Durationer.go ├── AWSer.go ├── Terraformer.go ├── Leaser.go └── TerraformBinFileSystemUtil.go ├── scripts ├── install_ci.sh ├── lint.sh └── test.sh ├── .github ├── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md └── pull_request_template.md ├── pkg └── service │ ├── usage.go │ ├── init.go │ ├── auth.go │ ├── accounts.go │ └── service.go ├── .gitignore ├── Makefile ├── models ├── lease_auth.go ├── usage.go ├── lease_status.go ├── account_status.go └── lease_status_reason.go ├── client ├── c_o_r_s │ ├── options_auth_responses.go │ ├── options_usage_responses.go │ ├── options_leases_responses.go │ ├── options_accounts_responses.go │ ├── options_auth_file_responses.go │ ├── options_leases_id_responses.go │ ├── options_leases_auth_responses.go │ ├── options_accounts_id_responses.go │ ├── options_leases_id_auth_responses.go │ ├── options_auth_parameters.go │ ├── options_usage_parameters.go │ ├── options_leases_parameters.go │ ├── options_accounts_parameters.go │ ├── options_auth_file_parameters.go │ ├── options_leases_id_parameters.go │ ├── options_accounts_id_parameters.go │ ├── options_leases_auth_parameters.go │ └── options_leases_id_auth_parameters.go └── operations │ ├── get_auth_responses.go │ ├── get_auth_file_responses.go │ ├── get_auth_parameters.go │ ├── get_auth_file_parameters.go │ └── post_leases_auth_parameters.go ├── configs └── config.go ├── go.mod ├── README.md ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md └── azure-pipelines.yml /dce: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | go run main.go $@ 4 | 5 | exit $? -------------------------------------------------------------------------------- /docs/dce-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Optum/dce-cli/HEAD/docs/dce-logo.png -------------------------------------------------------------------------------- /update_docs: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | go run docs/update_docs.go $@ 4 | 5 | exit $? -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/Optum/dce-cli/cmd" 4 | 5 | func main() { 6 | cmd.Execute() 7 | } 8 | -------------------------------------------------------------------------------- /internal/constants/prompts.go: -------------------------------------------------------------------------------- 1 | package constants 2 | 3 | const PromptChangeConfigConfirmation string = "Is this correct? (yes/no)" 4 | -------------------------------------------------------------------------------- /internal/constants/constants_windows.go: -------------------------------------------------------------------------------- 1 | // +build windows 2 | 3 | package constants 4 | 5 | const CredentialsExport string = `SET AWS_ACCESS_KEY_ID=%s 6 | SET AWS_SECRET_ACCESS_KEY=%s 7 | SET AWS_SESSION_TOKEN=%s` 8 | -------------------------------------------------------------------------------- /tests/unit/examples/README.txt: -------------------------------------------------------------------------------- 1 | This directory contains files that are used for comparing output 2 | from the main.tf template generator. They were generated, linted, 3 | and then saved to make sure behavior does not change. -------------------------------------------------------------------------------- /internal/constants/constants_unix.go: -------------------------------------------------------------------------------- 1 | // +build !windows 2 | 3 | package constants 4 | 5 | const CredentialsExport string = `export AWS_ACCESS_KEY_ID=%s 6 | export AWS_SECRET_ACCESS_KEY=%s 7 | export AWS_SESSION_TOKEN=%s` 8 | -------------------------------------------------------------------------------- /internal/constants/contextkeys.go: -------------------------------------------------------------------------------- 1 | package constants 2 | 3 | type ContextKey string 4 | 5 | const ( 6 | DeployConfig ContextKey = ContextKey("deployConfig") 7 | DeployLogFileKey ContextKey = ContextKey("deployLogFile") 8 | ) 9 | -------------------------------------------------------------------------------- /internal/constants/github.go: -------------------------------------------------------------------------------- 1 | package constants 2 | 3 | const GithubLatestAssetDownloadURL string = "https://github.com/Optum/dce/releases/latest/download/" 4 | const GithubAssetDownloadURLFormat string = "https://github.com/Optum/dce/releases/download/v%s/%s" 5 | -------------------------------------------------------------------------------- /docs/update_docs.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/Optum/dce-cli/cmd" 7 | "github.com/spf13/cobra/doc" 8 | ) 9 | 10 | func main() { 11 | err := doc.GenMarkdownTree(cmd.RootCmd, "./docs") 12 | if err != nil { 13 | fmt.Println(err) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | DCE-CLI 2 | 3 | Copyright 2019 Optum 4 | 5 | Project Description: 6 | ==================== 7 | This is the CLI for DCE. Disposable Cloud Environment (DCE) manages ephemeral AWS accounts for easy and secure access to the cloud. 8 | 9 | Author(s): 10 | Joshua Marsh (@joshmarsh) 11 | Edan Schwartz (@eschwartz) 12 | Matthew Meyers (@marinatedpork) 13 | -------------------------------------------------------------------------------- /cmd/auth.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/spf13/cobra" 5 | ) 6 | 7 | func init() { 8 | RootCmd.AddCommand(authCmd) 9 | authCmd.Flags() 10 | } 11 | 12 | var authCmd = &cobra.Command{ 13 | Use: "auth", 14 | Short: "Login to dce", 15 | RunE: func(cmd *cobra.Command, args []string) error { 16 | return Service.Authenticate() 17 | }, 18 | } 19 | -------------------------------------------------------------------------------- /mocks/Initer.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // Initer is an autogenerated mock type for the Initer type 8 | type Initer struct { 9 | mock.Mock 10 | } 11 | 12 | // InitializeDCE provides a mock function with given fields: 13 | func (_m *Initer) InitializeDCE() { 14 | _m.Called() 15 | } 16 | -------------------------------------------------------------------------------- /mocks/Weber.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // Weber is an autogenerated mock type for the Weber type 8 | type Weber struct { 9 | mock.Mock 10 | } 11 | 12 | // OpenURL provides a mock function with given fields: url 13 | func (_m *Weber) OpenURL(url string) { 14 | _m.Called(url) 15 | } 16 | -------------------------------------------------------------------------------- /scripts/install_ci.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euxo pipefail 3 | 4 | export GOBIN=$(dirname `which go`) 5 | 6 | go get github.com/jstemmer/go-junit-report 7 | go get github.com/axw/gocov/gocov 8 | go get github.com/AlekSi/gocov-xml 9 | go get github.com/matm/gocov-html 10 | go get -u github.com/golangci/golangci-lint/cmd/golangci-lint@v1.24.0 11 | go get -u github.com/securego/gosec/cmd/gosec 12 | -------------------------------------------------------------------------------- /mocks/Usager.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // Usager is an autogenerated mock type for the Usager type 8 | type Usager struct { 9 | mock.Mock 10 | } 11 | 12 | // GetUsage provides a mock function with given fields: startDate, endDate 13 | func (_m *Usager) GetUsage(startDate float64, endDate float64) { 14 | _m.Called(startDate, endDate) 15 | } 16 | -------------------------------------------------------------------------------- /scripts/lint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | 4 | echo -n "Formatting golang code... " 5 | gofmtout=$(go fmt ./...) 6 | if [ "$gofmtout" ]; then 7 | printf "\n\n" 8 | echo "Files with formatting errors:" 9 | echo "${gofmtout}" 10 | exit 1 11 | fi 12 | echo "done." 13 | 14 | echo -n "Linting golang code... " 15 | golangci-lint run 16 | echo "done." 17 | 18 | 19 | echo -n "Scanning for securirty issues... " 20 | gosec ./... 21 | echo "done." 22 | -------------------------------------------------------------------------------- /internal/observation/logging.go: -------------------------------------------------------------------------------- 1 | package observation 2 | 3 | import "os" 4 | 5 | type LogObservation struct { 6 | LevelLogger 7 | } 8 | 9 | func (l *LogObservation) Endf(format string, args ...interface{}) { 10 | l.Infof(format, args...) 11 | os.Exit(0) 12 | } 13 | 14 | func (l *LogObservation) End(args ...interface{}) { 15 | l.Info(args...) 16 | os.Exit(0) 17 | } 18 | 19 | func (l *LogObservation) Endln(args ...interface{}) { 20 | l.Infoln(args...) 21 | os.Exit(0) 22 | } 23 | -------------------------------------------------------------------------------- /scripts/test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -uxo pipefail 3 | 4 | mkdir -p junit-report 5 | 6 | # Run tests 7 | go test -v -coverprofile=coverage.txt -covermode count \ 8 | ./... 2>&1 | \ 9 | tee test.output.txt | \ 10 | tee >(go-junit-report -set-exit-code > junit-report/report.xml) 11 | 12 | # Echo Test Output 13 | cat test.output.txt 14 | 15 | # Convert coverate to xml and html 16 | gocov convert coverage.txt > coverage.json 17 | gocov-xml < coverage.json > coverage.xml 18 | -------------------------------------------------------------------------------- /docs/dce_auth.md: -------------------------------------------------------------------------------- 1 | ## dce auth 2 | 3 | Login to dce 4 | 5 | ### Synopsis 6 | 7 | Login to dce 8 | 9 | ``` 10 | dce auth [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for auth 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is "$HOME/.dce/config.yaml") 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce](dce.md) - Disposable Cloud Environment (DCE) 28 | 29 | ###### Auto generated by spf13/cobra on 24-Apr-2020 30 | -------------------------------------------------------------------------------- /docs/dce_docs.md: -------------------------------------------------------------------------------- 1 | ## dce docs 2 | 3 | Updates Markown Docs 4 | 5 | ### Synopsis 6 | 7 | Updates Markown Docs 8 | 9 | ``` 10 | dce docs [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for docs 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce](dce.md) - Disposable Cloud Environment (DCE) 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_configure.md: -------------------------------------------------------------------------------- 1 | ## dce configure 2 | 3 | Configure DCE cli 4 | 5 | ### Synopsis 6 | 7 | Configure DCE cli 8 | 9 | ``` 10 | dce configure [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for configure 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce](dce.md) - Disposable Cloud Environment (DCE) 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_system_users_add.md: -------------------------------------------------------------------------------- 1 | ## dce system users add 2 | 3 | Add users 4 | 5 | ### Synopsis 6 | 7 | Add users 8 | 9 | ``` 10 | dce system users add [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for add 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce system users](dce_system_users.md) - Manage users 28 | 29 | ###### Auto generated by spf13/cobra on 15-Oct-2019 30 | -------------------------------------------------------------------------------- /cmd/init.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/Optum/dce-cli/internal/constants" 7 | "github.com/spf13/cobra" 8 | ) 9 | 10 | func init() { 11 | RootCmd.AddCommand(initCmd) 12 | } 13 | 14 | var initCmd = &cobra.Command{ 15 | Use: "init", 16 | Short: fmt.Sprintf("First time DCE cli setup. Creates config file at \"%s\" (by default) or at the location specified by \"--config\"", constants.ConfigFileDefaultLocationUnexpanded), 17 | Run: func(cmd *cobra.Command, args []string) { 18 | Service.InitializeDCE() 19 | }, 20 | } 21 | -------------------------------------------------------------------------------- /docs/dce_accounts_list.md: -------------------------------------------------------------------------------- 1 | ## dce accounts list 2 | 3 | list accounts 4 | 5 | ### Synopsis 6 | 7 | list accounts 8 | 9 | ``` 10 | dce accounts list [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is "$HOME/.dce/config.yaml") 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce accounts](dce_accounts.md) - Manage dce accounts 28 | 29 | ###### Auto generated by spf13/cobra on 24-Apr-2020 30 | -------------------------------------------------------------------------------- /docs/dce_admin_login.md: -------------------------------------------------------------------------------- 1 | ## dce admin login 2 | 3 | Login to DCE master account 4 | 5 | ### Synopsis 6 | 7 | Login to DCE master account 8 | 9 | ``` 10 | dce admin login [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for login 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce admin](dce_admin.md) - Administer DCE 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_login.md: -------------------------------------------------------------------------------- 1 | ## dce login 2 | 3 | Login to one of your DCE accounts 4 | 5 | ### Synopsis 6 | 7 | Login to one of your DCE accounts 8 | 9 | ``` 10 | dce login [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for login 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce](dce.md) - Disposable Cloud Environment (DCE) 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_system_logs_reset.md: -------------------------------------------------------------------------------- 1 | ## dce system logs reset 2 | 3 | View reset logs 4 | 5 | ### Synopsis 6 | 7 | View reset logs 8 | 9 | ``` 10 | dce system logs reset [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for reset 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce system logs](dce_system_logs.md) - View logs 28 | 29 | ###### Auto generated by spf13/cobra on 15-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_system_logs_usage.md: -------------------------------------------------------------------------------- 1 | ## dce system logs usage 2 | 3 | View usage logs 4 | 5 | ### Synopsis 6 | 7 | View usage logs 8 | 9 | ``` 10 | dce system logs usage [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for usage 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce system logs](dce_system_logs.md) - View logs 28 | 29 | ###### Auto generated by spf13/cobra on 15-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_system_logs_leases.md: -------------------------------------------------------------------------------- 1 | ## dce system logs leases 2 | 3 | View lease logs 4 | 5 | ### Synopsis 6 | 7 | View lease logs 8 | 9 | ``` 10 | dce system logs leases [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for leases 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce system logs](dce_system_logs.md) - View logs 28 | 29 | ###### Auto generated by spf13/cobra on 15-Oct-2019 30 | -------------------------------------------------------------------------------- /cmd/version.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "fmt" 5 | "github.com/spf13/cobra" 6 | "strings" 7 | ) 8 | 9 | var version string 10 | 11 | func init() { 12 | RootCmd.AddCommand(versionCmd) 13 | } 14 | 15 | var versionCmd = &cobra.Command{ 16 | Use: "version", 17 | Short: "View the running version of dce-cli", 18 | Args: cobra.NoArgs, 19 | Run: func(cmd *cobra.Command, args []string) { 20 | shortVersion := strings.Split(version, "-")[0] 21 | finalVersion := strings.Replace(shortVersion, "v", "", 1) 22 | fmt.Println(finalVersion) 23 | }, 24 | } 25 | -------------------------------------------------------------------------------- /docs/dce_accounts_login.md: -------------------------------------------------------------------------------- 1 | ## dce accounts login 2 | 3 | Login to a DCE account 4 | 5 | ### Synopsis 6 | 7 | Login to a DCE account 8 | 9 | ``` 10 | dce accounts login [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for login 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce accounts](dce_accounts.md) - Manage dce accounts 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_system_users_remove.md: -------------------------------------------------------------------------------- 1 | ## dce system users remove 2 | 3 | Remove users 4 | 5 | ### Synopsis 6 | 7 | Remove users 8 | 9 | ``` 10 | dce system users remove [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for remove 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce system users](dce_system_users.md) - Manage users 28 | 29 | ###### Auto generated by spf13/cobra on 15-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_accounts_release.md: -------------------------------------------------------------------------------- 1 | ## dce accounts release 2 | 3 | Release an account 4 | 5 | ### Synopsis 6 | 7 | Release an account 8 | 9 | ``` 10 | dce accounts release [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for release 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce accounts](dce_accounts.md) - Manage your dce accounts 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_accounts_request.md: -------------------------------------------------------------------------------- 1 | ## dce accounts request 2 | 3 | Request an account 4 | 5 | ### Synopsis 6 | 7 | Request an account 8 | 9 | ``` 10 | dce accounts request [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for request 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce accounts](dce_accounts.md) - Manage your dce accounts 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_admin_upgrade.md: -------------------------------------------------------------------------------- 1 | ## dce admin upgrade 2 | 3 | Upgrade DCE to the latest version. 4 | 5 | ### Synopsis 6 | 7 | Upgrade DCE to the latest version. 8 | 9 | ``` 10 | dce admin upgrade [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for upgrade 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce admin](dce_admin.md) - Administer DCE 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_leases_describe.md: -------------------------------------------------------------------------------- 1 | ## dce leases describe 2 | 3 | describe a lease 4 | 5 | ### Synopsis 6 | 7 | describe a lease 8 | 9 | ``` 10 | dce leases describe [Lease ID] [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for describe 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is "$HOME/.dce/config.yaml") 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce leases](dce_leases.md) - Manage dce leases 28 | 29 | ###### Auto generated by spf13/cobra on 24-Apr-2020 30 | -------------------------------------------------------------------------------- /docs/dce_system_logs_accounts.md: -------------------------------------------------------------------------------- 1 | ## dce system logs accounts 2 | 3 | View account logs 4 | 5 | ### Synopsis 6 | 7 | View account logs 8 | 9 | ``` 10 | dce system logs accounts [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for accounts 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce system logs](dce_system_logs.md) - View logs 28 | 29 | ###### Auto generated by spf13/cobra on 15-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_version.md: -------------------------------------------------------------------------------- 1 | ## dce version 2 | 3 | View the running version of dce-cli 4 | 5 | ### Synopsis 6 | 7 | View the running version of dce-cli 8 | 9 | ``` 10 | dce version [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for version 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is "$HOME/.dce/config.yaml") 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce](dce.md) - Disposable Cloud Environment (DCE) 28 | 29 | ###### Auto generated by spf13/cobra on 24-Apr-2020 30 | -------------------------------------------------------------------------------- /docs/dce_leases_add.md: -------------------------------------------------------------------------------- 1 | ## dce leases add 2 | 3 | Add one or more leases to the leases pool. 4 | 5 | ### Synopsis 6 | 7 | Add one or more leases to the leases pool. 8 | 9 | ``` 10 | dce leases add [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for add 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce leases](dce_leases.md) - Manage dce leases 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_accounts_describe.md: -------------------------------------------------------------------------------- 1 | ## dce accounts describe 2 | 3 | describe an account 4 | 5 | ### Synopsis 6 | 7 | describe an account 8 | 9 | ``` 10 | dce accounts describe [Accound ID] [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for describe 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is "$HOME/.dce/config.yaml") 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce accounts](dce_accounts.md) - Manage dce accounts 28 | 29 | ###### Auto generated by spf13/cobra on 24-Apr-2020 30 | -------------------------------------------------------------------------------- /mocks/Authenticater.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // Authenticater is an autogenerated mock type for the Authenticater type 8 | type Authenticater struct { 9 | mock.Mock 10 | } 11 | 12 | // Authenticate provides a mock function with given fields: 13 | func (_m *Authenticater) Authenticate() error { 14 | ret := _m.Called() 15 | 16 | var r0 error 17 | if rf, ok := ret.Get(0).(func() error); ok { 18 | r0 = rf() 19 | } else { 20 | r0 = ret.Error(0) 21 | } 22 | 23 | return r0 24 | } 25 | -------------------------------------------------------------------------------- /docs/dce_leases_remove.md: -------------------------------------------------------------------------------- 1 | ## dce leases remove 2 | 3 | Remove one or more leases from the leases pool. 4 | 5 | ### Synopsis 6 | 7 | Remove one or more leases from the leases pool. 8 | 9 | ``` 10 | dce leases remove [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for remove 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce leases](dce_leases.md) - Manage dce leases 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_system.md: -------------------------------------------------------------------------------- 1 | ## dce system 2 | 3 | Deploy and configure the DCE system 4 | 5 | ### Synopsis 6 | 7 | Deploy and configure the DCE system 8 | 9 | ### Options 10 | 11 | ``` 12 | -h, --help help for system 13 | ``` 14 | 15 | ### Options inherited from parent commands 16 | 17 | ``` 18 | --config string config file (default is "$HOME/.dce/config.yaml") 19 | ``` 20 | 21 | ### SEE ALSO 22 | 23 | * [dce](dce.md) - Disposable Cloud Environment (DCE) 24 | * [dce system deploy](dce_system_deploy.md) - Deploy DCE to a new master account 25 | 26 | ###### Auto generated by spf13/cobra on 24-Apr-2020 27 | -------------------------------------------------------------------------------- /docs/dce_admin_accounts_describe.md: -------------------------------------------------------------------------------- 1 | ## dce admin accounts describe 2 | 3 | Describe any DCE account. 4 | 5 | ### Synopsis 6 | 7 | Describe any DCE account. 8 | 9 | ``` 10 | dce admin accounts describe [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for describe 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce admin accounts](dce_admin_accounts.md) - Administer all DCE accounts 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_accounts_remove.md: -------------------------------------------------------------------------------- 1 | ## dce accounts remove 2 | 3 | Remove an account from the accounts pool. 4 | 5 | ### Synopsis 6 | 7 | Remove an account from the accounts pool. 8 | 9 | ``` 10 | dce accounts remove [Account ID] [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for remove 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is "$HOME/.dce/config.yaml") 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce accounts](dce_accounts.md) - Manage dce accounts 28 | 29 | ###### Auto generated by spf13/cobra on 24-Apr-2020 30 | -------------------------------------------------------------------------------- /docs/dce_admin_accounts_list.md: -------------------------------------------------------------------------------- 1 | ## dce admin accounts list 2 | 3 | List all DCE accounts based on filters. 4 | 5 | ### Synopsis 6 | 7 | List all DCE accounts based on filters. 8 | 9 | ``` 10 | dce admin accounts list [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for list 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce admin accounts](dce_admin_accounts.md) - Administer all DCE accounts 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_system_users.md: -------------------------------------------------------------------------------- 1 | ## dce system users 2 | 3 | Manage users 4 | 5 | ### Synopsis 6 | 7 | Manage users 8 | 9 | ### Options 10 | 11 | ``` 12 | -h, --help help for users 13 | ``` 14 | 15 | ### Options inherited from parent commands 16 | 17 | ``` 18 | --config string config file (default is $HOME/.dce.yaml) 19 | ``` 20 | 21 | ### SEE ALSO 22 | 23 | * [dce system](dce_system.md) - Deploy and configure the DCE system 24 | * [dce system users add](dce_system_users_add.md) - Add users 25 | * [dce system users remove](dce_system_users_remove.md) - Remove users 26 | 27 | ###### Auto generated by spf13/cobra on 15-Oct-2019 28 | -------------------------------------------------------------------------------- /docs/dce_admin_init.md: -------------------------------------------------------------------------------- 1 | ## dce admin init 2 | 3 | First time initialization of DCE. Specify an account as master and deploy DCE to it. 4 | 5 | ### Synopsis 6 | 7 | First time initialization of DCE. Specify an account as master and deploy DCE to it. 8 | 9 | ``` 10 | dce admin init [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for init 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce admin](dce_admin.md) - Administer DCE 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_system_init.md: -------------------------------------------------------------------------------- 1 | ## dce system init 2 | 3 | Initialize a DCE configuration file at the specified location (Defaults to ~/.dce.yaml) 4 | 5 | ### Synopsis 6 | 7 | Initialize a DCE configuration file at the specified location (Defaults to ~/.dce.yaml) 8 | 9 | ``` 10 | dce system init [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for init 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce system](dce_system.md) - Deploy and configure the DCE system 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_admin_accounts_add.md: -------------------------------------------------------------------------------- 1 | ## dce admin accounts add 2 | 3 | Add DCE account(s) to the accounts pool. Increases the total number of accounts. 4 | 5 | ### Synopsis 6 | 7 | Add DCE account(s) to the accounts pool. Increases the total number of accounts. 8 | 9 | ``` 10 | dce admin accounts add [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for add 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce admin accounts](dce_admin_accounts.md) - Administer all DCE accounts 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /mocks/Githuber.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // Githuber is an autogenerated mock type for the Githuber type 8 | type Githuber struct { 9 | mock.Mock 10 | } 11 | 12 | // DownloadGithubReleaseAsset provides a mock function with given fields: assetName, dceVersion 13 | func (_m *Githuber) DownloadGithubReleaseAsset(assetName string, dceVersion string) error { 14 | ret := _m.Called(assetName, dceVersion) 15 | 16 | var r0 error 17 | if rf, ok := ret.Get(0).(func(string, string) error); ok { 18 | r0 = rf(assetName, dceVersion) 19 | } else { 20 | r0 = ret.Error(0) 21 | } 22 | 23 | return r0 24 | } 25 | -------------------------------------------------------------------------------- /mocks/TerraformBinDownloader.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // TerraformBinDownloader is an autogenerated mock type for the TerraformBinDownloader type 8 | type TerraformBinDownloader struct { 9 | mock.Mock 10 | } 11 | 12 | // Download provides a mock function with given fields: url, localpath 13 | func (_m *TerraformBinDownloader) Download(url string, localpath string) error { 14 | ret := _m.Called(url, localpath) 15 | 16 | var r0 error 17 | if rf, ok := ret.Get(0).(func(string, string) error); ok { 18 | r0 = rf(url, localpath) 19 | } else { 20 | r0 = ret.Error(0) 21 | } 22 | 23 | return r0 24 | } 25 | -------------------------------------------------------------------------------- /internal/constants/defaults.go: -------------------------------------------------------------------------------- 1 | package constants 2 | 3 | const CommandShortName = "dce" 4 | const ConfigFileDefaultLocationUnexpanded = "$HOME/.dce/config.yaml" 5 | 6 | const DefaultConfigFileName string = "config.yaml" 7 | const GlobalTFTagDefaults string = `"Terraform":"True","AppName":"DCE","Source":"github.com/Optum/dce//modules"` 8 | const TerraformBinName = "terraform" 9 | const TerraformBinVersion = "0.12.18" 10 | const TerraformBinDownloadURLFormat = "https://releases.hashicorp.com/terraform/%s/terraform_%s_%s_%s.zip" 11 | 12 | // Default version of DCE to deploy, using `dce system deploy` 13 | const DefaultDCEVersion = "0.29.0" 14 | 15 | // Default DCE Location 16 | const DefaultDCELocation = "github.com/Optum/dce" 17 | -------------------------------------------------------------------------------- /docs/dce_admin_accounts_remove.md: -------------------------------------------------------------------------------- 1 | ## dce admin accounts remove 2 | 3 | Remove a DCE account(s) from the accounts pull. Reduces the total number of accounts. 4 | 5 | ### Synopsis 6 | 7 | Remove a DCE account(s) from the accounts pull. Reduces the total number of accounts. 8 | 9 | ``` 10 | dce admin accounts remove [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for remove 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is $HOME/.dce.yaml) 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce admin accounts](dce_admin_accounts.md) - Administer all DCE accounts 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | 12 | 13 | **Describe the solution you'd like** 14 | 15 | 16 | **Describe alternatives you've considered** 17 | 18 | 19 | **Additional context** 20 | -------------------------------------------------------------------------------- /docs/dce_init.md: -------------------------------------------------------------------------------- 1 | ## dce init 2 | 3 | First time DCE cli setup. Creates config file at "$HOME/.dce/config.yaml" (by default) or at the location specified by "--config" 4 | 5 | ### Synopsis 6 | 7 | First time DCE cli setup. Creates config file at "$HOME/.dce/config.yaml" (by default) or at the location specified by "--config" 8 | 9 | ``` 10 | dce init [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -h, --help help for init 17 | ``` 18 | 19 | ### Options inherited from parent commands 20 | 21 | ``` 22 | --config string config file (default is "$HOME/.dce/config.yaml") 23 | ``` 24 | 25 | ### SEE ALSO 26 | 27 | * [dce](dce.md) - Disposable Cloud Environment (DCE) 28 | 29 | ###### Auto generated by spf13/cobra on 24-Apr-2020 30 | -------------------------------------------------------------------------------- /mocks/OutputWriter.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // OutputWriter is an autogenerated mock type for the OutputWriter type 8 | type OutputWriter struct { 9 | mock.Mock 10 | } 11 | 12 | // Write provides a mock function with given fields: p 13 | func (_m *OutputWriter) Write(p []byte) (int, error) { 14 | ret := _m.Called(p) 15 | 16 | var r0 int 17 | if rf, ok := ret.Get(0).(func([]byte) int); ok { 18 | r0 = rf(p) 19 | } else { 20 | r0 = ret.Get(0).(int) 21 | } 22 | 23 | var r1 error 24 | if rf, ok := ret.Get(1).(func([]byte) error); ok { 25 | r1 = rf(p) 26 | } else { 27 | r1 = ret.Error(1) 28 | } 29 | 30 | return r0, r1 31 | } 32 | -------------------------------------------------------------------------------- /docs/dce_system_logs.md: -------------------------------------------------------------------------------- 1 | ## dce system logs 2 | 3 | View logs 4 | 5 | ### Synopsis 6 | 7 | View logs 8 | 9 | ### Options 10 | 11 | ``` 12 | -h, --help help for logs 13 | ``` 14 | 15 | ### Options inherited from parent commands 16 | 17 | ``` 18 | --config string config file (default is $HOME/.dce.yaml) 19 | ``` 20 | 21 | ### SEE ALSO 22 | 23 | * [dce system](dce_system.md) - Deploy and configure the DCE system 24 | * [dce system logs accounts](dce_system_logs_accounts.md) - View account logs 25 | * [dce system logs leases](dce_system_logs_leases.md) - View lease logs 26 | * [dce system logs reset](dce_system_logs_reset.md) - View reset logs 27 | * [dce system logs usage](dce_system_logs_usage.md) - View usage logs 28 | 29 | ###### Auto generated by spf13/cobra on 15-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_usage.md: -------------------------------------------------------------------------------- 1 | ## dce usage 2 | 3 | View lease budget information 4 | 5 | ### Synopsis 6 | 7 | View lease budget information 8 | 9 | ``` 10 | dce usage [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -e, --end-date float The end date of the window over which usage information will be queried. (epoch timestamp) 17 | -h, --help help for usage 18 | -s, --start-date float The start date of the window over which usage information will be queried. (epoch timestamp) 19 | ``` 20 | 21 | ### Options inherited from parent commands 22 | 23 | ``` 24 | --config string config file (default is "$HOME/.dce/config.yaml") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [dce](dce.md) - Disposable Cloud Environment (DCE) 30 | 31 | ###### Auto generated by spf13/cobra on 24-Apr-2020 32 | -------------------------------------------------------------------------------- /docs/dce_accounts.md: -------------------------------------------------------------------------------- 1 | ## dce accounts 2 | 3 | Manage dce accounts 4 | 5 | ### Synopsis 6 | 7 | Manage dce accounts 8 | 9 | ### Options 10 | 11 | ``` 12 | -h, --help help for accounts 13 | ``` 14 | 15 | ### Options inherited from parent commands 16 | 17 | ``` 18 | --config string config file (default is "$HOME/.dce/config.yaml") 19 | ``` 20 | 21 | ### SEE ALSO 22 | 23 | * [dce](dce.md) - Disposable Cloud Environment (DCE) 24 | * [dce accounts add](dce_accounts_add.md) - Add an account to the accounts pool 25 | * [dce accounts describe](dce_accounts_describe.md) - describe an account 26 | * [dce accounts list](dce_accounts_list.md) - list accounts 27 | * [dce accounts remove](dce_accounts_remove.md) - Remove an account from the accounts pool. 28 | 29 | ###### Auto generated by spf13/cobra on 24-Apr-2020 30 | -------------------------------------------------------------------------------- /docs/dce_admin.md: -------------------------------------------------------------------------------- 1 | ## dce admin 2 | 3 | Administer DCE 4 | 5 | ### Synopsis 6 | 7 | Administer DCE 8 | 9 | ### Options 10 | 11 | ``` 12 | -h, --help help for admin 13 | ``` 14 | 15 | ### Options inherited from parent commands 16 | 17 | ``` 18 | --config string config file (default is $HOME/.dce.yaml) 19 | ``` 20 | 21 | ### SEE ALSO 22 | 23 | * [dce](dce.md) - Disposable Cloud Environment (DCE) 24 | * [dce admin accounts](dce_admin_accounts.md) - Administer all DCE accounts 25 | * [dce admin init](dce_admin_init.md) - First time initialization of DCE. Specify an account as master and deploy DCE to it. 26 | * [dce admin login](dce_admin_login.md) - Login to DCE master account 27 | * [dce admin upgrade](dce_admin_upgrade.md) - Upgrade DCE to the latest version. 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /tests/unit/examples/maintf-basic.example: -------------------------------------------------------------------------------- 1 | terraform { 2 | 3 | backend "local" { 4 | path="/Users/jexmple/.dce/terraform.tfstate" 5 | workspace_dir="/Users/jexmple/.dce/tf-workspace" 6 | } 7 | } 8 | 9 | variable "namespace" { 10 | type = string 11 | default = "dcecliut" 12 | } 13 | 14 | variable "budget_notification_from_email" { 15 | type = string 16 | default = "noreply@example.com" 17 | } 18 | 19 | module "dce" { 20 | source="github.com/Optum/dce//modules?ref=v0.23.0" 21 | 22 | namespace = var.namespace 23 | budget_notification_from_email = var.budget_notification_from_email 24 | } 25 | 26 | output "artifacts_bucket_name" { 27 | description = "S3 bucket for artifacts like AWS Lambda code" 28 | value = module.dce.artifacts_bucket_name 29 | } 30 | 31 | output "api_url" { 32 | description = "URL of DCE API" 33 | value = module.dce.api_url 34 | } 35 | -------------------------------------------------------------------------------- /docs/dce_accounts_add.md: -------------------------------------------------------------------------------- 1 | ## dce accounts add 2 | 3 | Add an account to the accounts pool 4 | 5 | ### Synopsis 6 | 7 | Add an account to the accounts pool 8 | 9 | ``` 10 | dce accounts add [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -a, --account-id string The ID of the existing account to add to the DCE accounts pool (WARNING: Account will be nuked.) 17 | -r, --admin-role-arn string The admin role arn to be assumed by the DCE master account. Trust policy must be configured with DCE master account as trusted entity. 18 | -h, --help help for add 19 | ``` 20 | 21 | ### Options inherited from parent commands 22 | 23 | ``` 24 | --config string config file (default is "$HOME/.dce/config.yaml") 25 | ``` 26 | 27 | ### SEE ALSO 28 | 29 | * [dce accounts](dce_accounts.md) - Manage dce accounts 30 | 31 | ###### Auto generated by spf13/cobra on 24-Apr-2020 32 | -------------------------------------------------------------------------------- /internal/util/prompt.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "fmt" 5 | "github.com/Optum/dce-cli/configs" 6 | observ "github.com/Optum/dce-cli/internal/observation" 7 | "github.com/chzyer/readline" 8 | ) 9 | 10 | type PromptUtil struct { 11 | Config *configs.Root 12 | Observation *observ.ObservationContainer 13 | } 14 | 15 | func (u *PromptUtil) PromptBasic(label string, validator func(input string) error) *string { 16 | rl, err := readline.NewEx(&readline.Config{ 17 | Prompt: fmt.Sprint(label, " "), 18 | DisableAutoSaveHistory: true, 19 | }) 20 | defer rl.Close() //nolint,errcheck 21 | if err != nil { 22 | log.Fatalln(err) 23 | } 24 | 25 | input, err := rl.Readline() 26 | if err != nil { 27 | log.Fatalln(err) 28 | } 29 | if validator != nil { 30 | err = validator(input) 31 | if err != nil { 32 | log.Fatalln(err) 33 | } 34 | } 35 | 36 | return &input 37 | } 38 | -------------------------------------------------------------------------------- /docs/dce_leases_end.md: -------------------------------------------------------------------------------- 1 | ## dce leases end 2 | 3 | Cause a lease to immediately expire 4 | 5 | ### Synopsis 6 | 7 | Cause a lease to immediately expire 8 | 9 | ``` 10 | dce leases end [Lease ID] [flags] 11 | ``` 12 | 13 | ### Examples 14 | 15 | ``` 16 | dce leases end 17 | dce leases end --principal-id --account-id 18 | ``` 19 | 20 | ### Options 21 | 22 | ``` 23 | -a, --account-id string Account ID associated with the lease you wish to end 24 | -h, --help help for end 25 | -p, --principal-id string Principle ID for the user of the leased account 26 | ``` 27 | 28 | ### Options inherited from parent commands 29 | 30 | ``` 31 | --config string config file (default is "$HOME/.dce/config.yaml") 32 | ``` 33 | 34 | ### SEE ALSO 35 | 36 | * [dce leases](dce_leases.md) - Manage dce leases 37 | 38 | ###### Auto generated by spf13/cobra on 24-Apr-2020 39 | -------------------------------------------------------------------------------- /cmd/usage.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/spf13/cobra" 5 | ) 6 | 7 | var startDate float64 8 | var endDate float64 9 | 10 | func init() { 11 | usageCmd.Flags().Float64VarP(&startDate, "start-date", "s", 0, "The start date of the window over which usage information will be queried. (epoch timestamp)") 12 | usageCmd.Flags().Float64VarP(&endDate, "end-date", "e", 0, "The end date of the window over which usage information will be queried. (epoch timestamp)") 13 | if err := usageCmd.MarkFlagRequired("start-date"); err != nil { 14 | log.Fatalln(err) 15 | } 16 | if err := usageCmd.MarkFlagRequired("end-date"); err != nil { 17 | log.Fatalln(err) 18 | } 19 | RootCmd.AddCommand(usageCmd) 20 | } 21 | 22 | var usageCmd = &cobra.Command{ 23 | Use: "usage", 24 | Short: "View lease budget information", 25 | Args: cobra.NoArgs, 26 | Run: func(cmd *cobra.Command, args []string) { 27 | Service.GetUsage(startDate, endDate) 28 | }, 29 | } 30 | -------------------------------------------------------------------------------- /mocks/Accounter.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // Accounter is an autogenerated mock type for the Accounter type 8 | type Accounter struct { 9 | mock.Mock 10 | } 11 | 12 | // AddAccount provides a mock function with given fields: accountID, adminRoleARN 13 | func (_m *Accounter) AddAccount(accountID string, adminRoleARN string) { 14 | _m.Called(accountID, adminRoleARN) 15 | } 16 | 17 | // GetAccount provides a mock function with given fields: accountID 18 | func (_m *Accounter) GetAccount(accountID string) { 19 | _m.Called(accountID) 20 | } 21 | 22 | // ListAccounts provides a mock function with given fields: 23 | func (_m *Accounter) ListAccounts() { 24 | _m.Called() 25 | } 26 | 27 | // RemoveAccount provides a mock function with given fields: accountID 28 | func (_m *Accounter) RemoveAccount(accountID string) { 29 | _m.Called(accountID) 30 | } 31 | -------------------------------------------------------------------------------- /docs/dce_admin_accounts.md: -------------------------------------------------------------------------------- 1 | ## dce admin accounts 2 | 3 | Administer all DCE accounts 4 | 5 | ### Synopsis 6 | 7 | Administer all DCE accounts 8 | 9 | ### Options 10 | 11 | ``` 12 | -h, --help help for accounts 13 | ``` 14 | 15 | ### Options inherited from parent commands 16 | 17 | ``` 18 | --config string config file (default is $HOME/.dce.yaml) 19 | ``` 20 | 21 | ### SEE ALSO 22 | 23 | * [dce admin](dce_admin.md) - Administer DCE 24 | * [dce admin accounts add](dce_admin_accounts_add.md) - Add DCE account(s) to the accounts pool. Increases the total number of accounts. 25 | * [dce admin accounts describe](dce_admin_accounts_describe.md) - Describe any DCE account. 26 | * [dce admin accounts list](dce_admin_accounts_list.md) - List all DCE accounts based on filters. 27 | * [dce admin accounts remove](dce_admin_accounts_remove.md) - Remove a DCE account(s) from the accounts pull. Reduces the total number of accounts. 28 | 29 | ###### Auto generated by spf13/cobra on 4-Oct-2019 30 | -------------------------------------------------------------------------------- /docs/dce_leases.md: -------------------------------------------------------------------------------- 1 | ## dce leases 2 | 3 | Manage dce leases 4 | 5 | ### Synopsis 6 | 7 | Manage dce leases 8 | 9 | ### Options 10 | 11 | ``` 12 | -h, --help help for leases 13 | ``` 14 | 15 | ### Options inherited from parent commands 16 | 17 | ``` 18 | --config string config file (default is "$HOME/.dce/config.yaml") 19 | ``` 20 | 21 | ### SEE ALSO 22 | 23 | * [dce](dce.md) - Disposable Cloud Environment (DCE) 24 | * [dce leases create](dce_leases_create.md) - Create a lease. 25 | * [dce leases describe](dce_leases_describe.md) - describe a lease 26 | * [dce leases end](dce_leases_end.md) - Cause a lease to immediately expire 27 | * [dce leases list](dce_leases_list.md) - List leases using various query filters. 28 | * [dce leases login](dce_leases_login.md) - Login to a leased DCE account. 29 | If no Lease ID is provided, uses the active lease for the requesting user. 30 | Sets AWS CLI credentials if used with no flags 31 | 32 | ###### Auto generated by spf13/cobra on 24-Apr-2020 33 | -------------------------------------------------------------------------------- /docs/dce_leases_create.md: -------------------------------------------------------------------------------- 1 | ## dce leases create 2 | 3 | Create a lease. 4 | 5 | ### Synopsis 6 | 7 | Create a lease. 8 | 9 | ``` 10 | dce leases create [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -b, --budget-amount float The leased accounts budget amount 17 | -c, --budget-currency string The leased accounts budget currency (default "USD") 18 | -e, --email stringArray The email address that budget notifications will be sent to 19 | -E, --expires-on string The leased accounts expiry date as a long (UNIX epoch) or string (eg., '7d', '8h' (default "7d") 20 | -h, --help help for create 21 | -p, --principal-id string Principle ID for the user of the leased account 22 | ``` 23 | 24 | ### Options inherited from parent commands 25 | 26 | ``` 27 | --config string config file (default is "$HOME/.dce/config.yaml") 28 | ``` 29 | 30 | ### SEE ALSO 31 | 32 | * [dce leases](dce_leases.md) - Manage dce leases 33 | 34 | ###### Auto generated by spf13/cobra on 24-Apr-2020 35 | -------------------------------------------------------------------------------- /pkg/service/usage.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "encoding/json" 5 | "time" 6 | 7 | "github.com/Optum/dce-cli/client/operations" 8 | "github.com/Optum/dce-cli/configs" 9 | observ "github.com/Optum/dce-cli/internal/observation" 10 | utl "github.com/Optum/dce-cli/internal/util" 11 | ) 12 | 13 | type UsageService struct { 14 | Config *configs.Root 15 | Observation *observ.ObservationContainer 16 | Util *utl.UtilContainer 17 | } 18 | 19 | func (s *UsageService) GetUsage(startDate, endDate float64) { 20 | params := &operations.GetUsageParams{ 21 | StartDate: startDate, 22 | EndDate: endDate, 23 | } 24 | params.SetTimeout(5 * time.Second) 25 | res, err := ApiClient.GetUsage(params, nil) 26 | if err != nil { 27 | log.Fatalln("err: ", err) 28 | } else { 29 | jsonPayload, err := json.MarshalIndent(res.GetPayload(), "", "\t") 30 | if err != nil { 31 | log.Fatalln("err: ", err) 32 | } 33 | if _, err := Out.Write(jsonPayload); err != nil { 34 | log.Fatalln("err: ", err) 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /mocks/Deployer.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | import service "github.com/Optum/dce-cli/pkg/service" 7 | 8 | // Deployer is an autogenerated mock type for the Deployer type 9 | type Deployer struct { 10 | mock.Mock 11 | } 12 | 13 | // Deploy provides a mock function with given fields: input 14 | func (_m *Deployer) Deploy(input *service.DeployConfig) error { 15 | ret := _m.Called(input) 16 | 17 | var r0 error 18 | if rf, ok := ret.Get(0).(func(*service.DeployConfig) error); ok { 19 | r0 = rf(input) 20 | } else { 21 | r0 = ret.Error(0) 22 | } 23 | 24 | return r0 25 | } 26 | 27 | // PostDeploy provides a mock function with given fields: input 28 | func (_m *Deployer) PostDeploy(input *service.DeployConfig) error { 29 | ret := _m.Called(input) 30 | 31 | var r0 error 32 | if rf, ok := ret.Get(0).(func(*service.DeployConfig) error); ok { 33 | r0 = rf(input) 34 | } else { 35 | r0 = ret.Error(0) 36 | } 37 | 38 | return r0 39 | } 40 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Version information** 11 | 17 | 18 | **Describe the bug** 19 | 20 | 21 | **To Reproduce** 22 | 39 | 40 | **Expected behavior** 41 | 42 | 43 | **Additional context** 44 | 45 | -------------------------------------------------------------------------------- /docs/dce.md: -------------------------------------------------------------------------------- 1 | ## dce 2 | 3 | Disposable Cloud Environment (DCE) 4 | 5 | ### Synopsis 6 | 7 | Disposable Cloud Environment (DCE) 8 | 9 | The DCE cli allows: 10 | 11 | - Admins to provision DCE to a master account and administer said account 12 | - Users to lease accounts and execute commands against them 13 | 14 | ### Options 15 | 16 | ``` 17 | --config string config file (default is "$HOME/.dce/config.yaml") 18 | -h, --help help for dce 19 | ``` 20 | 21 | ### SEE ALSO 22 | 23 | * [dce accounts](dce_accounts.md) - Manage dce accounts 24 | * [dce auth](dce_auth.md) - Login to dce 25 | * [dce init](dce_init.md) - First time DCE cli setup. Creates config file at "$HOME/.dce/config.yaml" (by default) or at the location specified by "--config" 26 | * [dce leases](dce_leases.md) - Manage dce leases 27 | * [dce system](dce_system.md) - Deploy and configure the DCE system 28 | * [dce usage](dce_usage.md) - View lease budget information 29 | * [dce version](dce_version.md) - View the running version of dce-cli 30 | 31 | ###### Auto generated by spf13/cobra on 24-Apr-2020 32 | -------------------------------------------------------------------------------- /docs/dce_leases_login.md: -------------------------------------------------------------------------------- 1 | ## dce leases login 2 | 3 | Login to a leased DCE account. 4 | If no Lease ID is provided, uses the active lease for the requesting user. 5 | Sets AWS CLI credentials if used with no flags 6 | 7 | ### Synopsis 8 | 9 | Login to a leased DCE account. 10 | If no Lease ID is provided, uses the active lease for the requesting user. 11 | Sets AWS CLI credentials if used with no flags 12 | 13 | ``` 14 | dce leases login [Lease ID] [flags] 15 | ``` 16 | 17 | ### Options 18 | 19 | ``` 20 | -h, --help help for login 21 | -b, --open-browser Opens web broswer to AWS console instead of printing credentials 22 | -c, --print-creds Prints credentials rather than adding them to .aws/credentials file 23 | -p, --profile string Add aws cli credentials to a specific profile (default "default") 24 | ``` 25 | 26 | ### Options inherited from parent commands 27 | 28 | ``` 29 | --config string config file (default is "$HOME/.dce/config.yaml") 30 | ``` 31 | 32 | ### SEE ALSO 33 | 34 | * [dce leases](dce_leases.md) - Manage dce leases 35 | 36 | ###### Auto generated by spf13/cobra on 24-Apr-2020 37 | -------------------------------------------------------------------------------- /mocks/Prompter.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // Prompter is an autogenerated mock type for the Prompter type 8 | type Prompter struct { 9 | mock.Mock 10 | } 11 | 12 | // PromptBasic provides a mock function with given fields: label, validator 13 | func (_m *Prompter) PromptBasic(label string, validator func(string) error) *string { 14 | ret := _m.Called(label, validator) 15 | 16 | var r0 *string 17 | if rf, ok := ret.Get(0).(func(string, func(string) error) *string); ok { 18 | r0 = rf(label, validator) 19 | } else { 20 | if ret.Get(0) != nil { 21 | r0 = ret.Get(0).(*string) 22 | } 23 | } 24 | 25 | return r0 26 | } 27 | 28 | // PromptSelect provides a mock function with given fields: label, items 29 | func (_m *Prompter) PromptSelect(label string, items []string) *string { 30 | ret := _m.Called(label, items) 31 | 32 | var r0 *string 33 | if rf, ok := ret.Get(0).(func(string, []string) *string); ok { 34 | r0 = rf(label, items) 35 | } else { 36 | if ret.Get(0) != nil { 37 | r0 = ret.Get(0).(*string) 38 | } 39 | } 40 | 41 | return r0 42 | } 43 | -------------------------------------------------------------------------------- /internal/util/github.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "net/http" 7 | "os" 8 | 9 | "github.com/Optum/dce-cli/configs" 10 | "github.com/Optum/dce-cli/internal/constants" 11 | observ "github.com/Optum/dce-cli/internal/observation" 12 | ) 13 | 14 | type GithubUtil struct { 15 | Config *configs.Root 16 | Observation *observ.ObservationContainer 17 | } 18 | 19 | func (u *GithubUtil) DownloadGithubReleaseAsset(assetName string, releaseName string) error { 20 | // There is an open issue on being able to get different versions. That 21 | // would go here... 22 | assetDownloadURL := fmt.Sprintf(constants.GithubAssetDownloadURLFormat, releaseName, assetName) 23 | req, err := http.NewRequest("GET", assetDownloadURL, nil) 24 | if err != nil { 25 | log.Fatalf("error: %v", err) 26 | } 27 | 28 | resp, err := http.DefaultClient.Do(req) 29 | if err != nil { 30 | return err 31 | } 32 | defer resp.Body.Close() 33 | 34 | out, err := os.Create(assetName) 35 | if err != nil { 36 | return err 37 | } 38 | // #nosec 39 | defer out.Close() 40 | _, err = io.Copy(out, resp.Body) 41 | if err != nil { 42 | return err 43 | } 44 | 45 | return nil 46 | } 47 | -------------------------------------------------------------------------------- /docs/dce_leases_list.md: -------------------------------------------------------------------------------- 1 | ## dce leases list 2 | 3 | List leases using various query filters. 4 | 5 | ### Synopsis 6 | 7 | List leases using various query filters. 8 | 9 | ``` 10 | dce leases list [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -a, --account-id string An AWS Account ID 17 | -h, --help help for list 18 | -l, --limit int Max number of leases to return at once. Will include url to next page if there is one. (default 25) 19 | --next-account-id string Account ID with which to begin the scan operation. This is used to traverse through paginated results. 20 | --next-principal-id string Principal ID with which to begin the scan operation. This is used to traverse through paginated results. 21 | -p, --principal-id string Principle ID of a user 22 | -s, --status string Lease status 23 | ``` 24 | 25 | ### Options inherited from parent commands 26 | 27 | ``` 28 | --config string config file (default is "$HOME/.dce/config.yaml") 29 | ``` 30 | 31 | ### SEE ALSO 32 | 33 | * [dce leases](dce_leases.md) - Manage dce leases 34 | 35 | ###### Auto generated by spf13/cobra on 24-Apr-2020 36 | -------------------------------------------------------------------------------- /internal/util/web.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "io" 5 | "net/http" 6 | "os" 7 | 8 | observ "github.com/Optum/dce-cli/internal/observation" 9 | "github.com/pkg/browser" 10 | ) 11 | 12 | type WebUtil struct { 13 | Observation *observ.ObservationContainer 14 | } 15 | 16 | func (w *WebUtil) OpenURL(url string) { 17 | if err := browser.OpenURL(url); err != nil { 18 | log.Fatalln("Error opening web browser", err) 19 | } 20 | } 21 | 22 | // Download will download the file at the given `url` and save it to the 23 | // `localpath` 24 | // Care should be taken to mitigate CWE-88 (https://cwe.mitre.org/data/definitions/88.html) 25 | // by ensuring inputs comes from a trusted source. 26 | func (w *WebUtil) Download(url string, localpath string) error { 27 | 28 | /* 29 | #nosec CWE-88: added disclaimer to function docs 30 | */ 31 | resp, err := http.Get(url) 32 | if err != nil { 33 | return err 34 | } 35 | defer resp.Body.Close() 36 | 37 | // Create the file 38 | out, err := os.Create(localpath) 39 | if err != nil { 40 | return err 41 | } 42 | // #nosec 43 | defer out.Close() 44 | 45 | // Write the body to file 46 | _, err = io.Copy(out, resp.Body) 47 | return err 48 | } 49 | -------------------------------------------------------------------------------- /tests/integration/githuber.go: -------------------------------------------------------------------------------- 1 | package integration 2 | 3 | import ( 4 | "fmt" 5 | "github.com/Optum/dce-cli/mocks" 6 | "io/ioutil" 7 | "testing" 8 | ) 9 | 10 | // stubGithub is a stub of the the Githuber util, 11 | // which may be used to mock github releases 12 | type stubGithub struct { 13 | *mocks.Githuber 14 | // map of "assetName/dceVersion" --> file content 15 | mockAssets map[string][]byte 16 | } 17 | 18 | func (gh *stubGithub) MockReleaseAsset(t *testing.T, assetName string, dceVersion string, content []byte) { 19 | if gh.mockAssets == nil { 20 | gh.mockAssets = map[string][]byte{} 21 | } 22 | 23 | key := fmt.Sprintf("%s/%s", assetName, dceVersion) 24 | gh.mockAssets[key] = content 25 | } 26 | 27 | func (gh *stubGithub) DownloadGithubReleaseAsset(assetName string, dceVersion string) error { 28 | // Grab the mocked asset 29 | key := fmt.Sprintf("%s/%s", assetName, dceVersion) 30 | content, ok := gh.mockAssets[key] 31 | if !ok { 32 | return fmt.Errorf("Test failure: mocked Github asset does not exist "+ 33 | "for %s @ %s", assetName, dceVersion) 34 | } 35 | 36 | // Write the file 37 | // #nosec 38 | err := ioutil.WriteFile(assetName, content, 0666) 39 | return err 40 | } 41 | -------------------------------------------------------------------------------- /mocks/TFTemplater.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import io "io" 6 | import mock "github.com/stretchr/testify/mock" 7 | 8 | // TFTemplater is an autogenerated mock type for the TFTemplater type 9 | type TFTemplater struct { 10 | mock.Mock 11 | } 12 | 13 | // AddVariable provides a mock function with given fields: name, vartype, vardefault 14 | func (_m *TFTemplater) AddVariable(name string, vartype string, vardefault string) error { 15 | ret := _m.Called(name, vartype, vardefault) 16 | 17 | var r0 error 18 | if rf, ok := ret.Get(0).(func(string, string, string) error); ok { 19 | r0 = rf(name, vartype, vardefault) 20 | } else { 21 | r0 = ret.Error(0) 22 | } 23 | 24 | return r0 25 | } 26 | 27 | // SetModuleSource provides a mock function with given fields: source 28 | func (_m *TFTemplater) SetModuleSource(source string) { 29 | _m.Called(source) 30 | } 31 | 32 | // Write provides a mock function with given fields: w 33 | func (_m *TFTemplater) Write(w io.Writer) error { 34 | ret := _m.Called(w) 35 | 36 | var r0 error 37 | if rf, ok := ret.Get(0).(func(io.Writer) error); ok { 38 | r0 = rf(w) 39 | } else { 40 | r0 = ret.Error(0) 41 | } 42 | 43 | return r0 44 | } 45 | -------------------------------------------------------------------------------- /mocks/Durationer.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | import time "time" 7 | 8 | // Durationer is an autogenerated mock type for the Durationer type 9 | type Durationer struct { 10 | mock.Mock 11 | } 12 | 13 | // ExpandEpochTime provides a mock function with given fields: str 14 | func (_m *Durationer) ExpandEpochTime(str string) (int64, error) { 15 | ret := _m.Called(str) 16 | 17 | var r0 int64 18 | if rf, ok := ret.Get(0).(func(string) int64); ok { 19 | r0 = rf(str) 20 | } else { 21 | r0 = ret.Get(0).(int64) 22 | } 23 | 24 | var r1 error 25 | if rf, ok := ret.Get(1).(func(string) error); ok { 26 | r1 = rf(str) 27 | } else { 28 | r1 = ret.Error(1) 29 | } 30 | 31 | return r0, r1 32 | } 33 | 34 | // ParseDuration provides a mock function with given fields: str 35 | func (_m *Durationer) ParseDuration(str string) (time.Duration, error) { 36 | ret := _m.Called(str) 37 | 38 | var r0 time.Duration 39 | if rf, ok := ret.Get(0).(func(string) time.Duration); ok { 40 | r0 = rf(str) 41 | } else { 42 | r0 = ret.Get(0).(time.Duration) 43 | } 44 | 45 | var r1 error 46 | if rf, ok := ret.Get(1).(func(string) error); ok { 47 | r1 = rf(str) 48 | } else { 49 | r1 = ret.Error(1) 50 | } 51 | 52 | return r0, r1 53 | } 54 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Project 2 | bin 3 | bin/* 4 | local_terraform.tfvars 5 | 6 | ## Terraform 7 | # Local .terraform directories 8 | **/.terraform/* 9 | 10 | # .tfstate files 11 | *.tfstate 12 | *.tfstate.* 13 | 14 | # Crash log files 15 | crash.log 16 | 17 | # Ignore any .tfvars files that are generated automatically for each Terraform run. Most 18 | # .tfvars files are managed as part of configuration and so should be included in 19 | # version control. 20 | # 21 | # example.tfvars 22 | 23 | # Ignore override files as they are usually used to override resources locally and so 24 | # are not checked in 25 | override.tf 26 | override.tf.json 27 | *_override.tf 28 | *_override.tf.json 29 | 30 | # Include override files you do wish to add to version control using negated pattern 31 | # 32 | # !example_override.tf 33 | 34 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan 35 | # example: *tfplan* 36 | 37 | ## Go 38 | # Binaries for programs and plugins 39 | *.exe 40 | *.exe~ 41 | *.dll 42 | *.so 43 | *.dylib 44 | 45 | # Test binary, built with `go test -c` 46 | *.test 47 | 48 | # Output of the go coverage tool, specifically when used with LiteIDE 49 | *.out 50 | 51 | # Other stuff 52 | *.zip 53 | .idea/ 54 | 55 | junit-report/ 56 | 57 | dce-cli 58 | 59 | .vscode/ 60 | 61 | coverage.* 62 | test.output.txt 63 | -------------------------------------------------------------------------------- /pkg/service/init.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "github.com/Optum/dce-cli/configs" 5 | observ "github.com/Optum/dce-cli/internal/observation" 6 | utl "github.com/Optum/dce-cli/internal/util" 7 | "github.com/aws/aws-sdk-go/aws" 8 | ) 9 | 10 | type InitService struct { 11 | Config *configs.Root 12 | Observation *observ.ObservationContainer 13 | Util *utl.UtilContainer 14 | } 15 | 16 | func (s *InitService) InitializeDCE() { 17 | // Set default region 18 | if s.Config.Region == nil { 19 | s.Config.Region = aws.String("us-east-1") 20 | } 21 | 22 | // Prompt user for required configs 23 | s.promptUserForConfig(s.Config) 24 | 25 | // Write the config to the config file 26 | err := s.Util.WriteConfig() 27 | if err != nil { 28 | log.Fatalf("Failed to write YAML config to %s: %s", 29 | s.Util.GetConfigFile(), err) 30 | } 31 | 32 | log.Infoln("Config file created at: " + s.Util.GetConfigFile()) 33 | } 34 | 35 | func (s *InitService) promptUserForConfig(config *configs.Root) { 36 | // API Config 37 | if config.API.Host == nil { 38 | config.API.Host = s.Util.PromptBasic("Host name of the DCE API (example: abcde12345.execute-api.us-east-1.amazonaws.com)", nil) 39 | } 40 | if config.API.BasePath == nil { 41 | config.API.BasePath = s.Util.PromptBasic("Base path of the DCE API (example: /api)", nil) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | VERSION := $(shell git describe --always --long --dirty) 2 | 3 | all: mocks test build 4 | 5 | # Generate client code from swagger in a local dce repo (make openapi DCE_REPO=/path/to/dce) 6 | openapi: 7 | echo "\nMANUAL STEP: Install goswagger cli tool if needed: https://goswagger.io/install.html\n" 8 | swagger flatten --with-expand $(DCE_REPO)/modules/swagger.yaml > $(PWD)/out.yaml 9 | swagger generate client -f $(PWD)/out.yaml --skip-validation -t $(PWD) 10 | rm ./out.yaml 11 | 12 | 13 | # Generate interfaces for OpenApi clients so they can be mocked. 14 | ifaces: 15 | echo "\nMANUAL STEP: Install interfacer if needed: `go install github.com/rjeczalik/interfaces/cmd/interfacer`\n" 16 | interfacer -for github.com/Optum/dce-cli/client/operations.Client -as APIer -o internal/util/ifaces.go 17 | echo "\nMANUAL STEP: Update the package name of internal/util/ifaces.go to package util\n" 18 | 19 | .PHONY: mocks 20 | mocks: 21 | rm -rf mocks/* 22 | mockery -all 23 | 24 | lint: 25 | ./scripts/lint.sh 26 | 27 | test: lint 28 | ./scripts/test.sh 29 | 30 | cover: 31 | go test -coverprofile=coverage.out -coverpkg="./pkg/...,./internal/...,./cmd/...,./configs/..." ./tests/... 32 | 33 | test_functional: 34 | go test -count=1 -v ./tests/functional/ 35 | 36 | test_unit: 37 | go test -count=1 -v ./tests/unit/ 38 | 39 | build: 40 | go build -ldflags "-X github.com/Optum/dce-cli/cmd.version=${VERSION}" . 41 | 42 | .PHONY: docs 43 | docs: 44 | ./update_docs 45 | -------------------------------------------------------------------------------- /models/lease_auth.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package models 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | strfmt "github.com/go-openapi/strfmt" 10 | "github.com/go-openapi/swag" 11 | ) 12 | 13 | // LeaseAuth Lease Authentication 14 | // swagger:model leaseAuth 15 | type LeaseAuth struct { 16 | 17 | // Access Key ID for access to the AWS API 18 | AccessKeyID string `json:"accessKeyId,omitempty"` 19 | 20 | // URL to access the AWS Console 21 | ConsoleURL string `json:"consoleUrl,omitempty"` 22 | 23 | // expires on 24 | ExpiresOn float64 `json:"expiresOn,omitempty"` 25 | 26 | // Secret Access Key for access to the AWS API 27 | SecretAccessKey string `json:"secretAccessKey,omitempty"` 28 | 29 | // Session Token for access to the AWS API 30 | SessionToken string `json:"sessionToken,omitempty"` 31 | } 32 | 33 | // Validate validates this lease auth 34 | func (m *LeaseAuth) Validate(formats strfmt.Registry) error { 35 | return nil 36 | } 37 | 38 | // MarshalBinary interface implementation 39 | func (m *LeaseAuth) MarshalBinary() ([]byte, error) { 40 | if m == nil { 41 | return nil, nil 42 | } 43 | return swag.WriteJSON(m) 44 | } 45 | 46 | // UnmarshalBinary interface implementation 47 | func (m *LeaseAuth) UnmarshalBinary(b []byte) error { 48 | var res LeaseAuth 49 | if err := swag.ReadJSON(b, &res); err != nil { 50 | return err 51 | } 52 | *m = res 53 | return nil 54 | } 55 | -------------------------------------------------------------------------------- /mocks/AWSer.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | 7 | // AWSer is an autogenerated mock type for the AWSer type 8 | type AWSer struct { 9 | mock.Mock 10 | } 11 | 12 | // ConfigureAWSCLICredentials provides a mock function with given fields: accessKeyID, secretAccessKey, sessionToken, profile 13 | func (_m *AWSer) ConfigureAWSCLICredentials(accessKeyID string, secretAccessKey string, sessionToken string, profile string) { 14 | _m.Called(accessKeyID, secretAccessKey, sessionToken, profile) 15 | } 16 | 17 | // UpdateLambdasFromS3Assets provides a mock function with given fields: lambdaNames, bucket, namespace 18 | func (_m *AWSer) UpdateLambdasFromS3Assets(lambdaNames []string, bucket string, namespace string) { 19 | _m.Called(lambdaNames, bucket, namespace) 20 | } 21 | 22 | // UploadDirectoryToS3 provides a mock function with given fields: localPath, bucket, prefix 23 | func (_m *AWSer) UploadDirectoryToS3(localPath string, bucket string, prefix string) ([]string, []string) { 24 | ret := _m.Called(localPath, bucket, prefix) 25 | 26 | var r0 []string 27 | if rf, ok := ret.Get(0).(func(string, string, string) []string); ok { 28 | r0 = rf(localPath, bucket, prefix) 29 | } else { 30 | if ret.Get(0) != nil { 31 | r0 = ret.Get(0).([]string) 32 | } 33 | } 34 | 35 | var r1 []string 36 | if rf, ok := ret.Get(1).(func(string, string, string) []string); ok { 37 | r1 = rf(localPath, bucket, prefix) 38 | } else { 39 | if ret.Get(1) != nil { 40 | r1 = ret.Get(1).([]string) 41 | } 42 | } 43 | 44 | return r0, r1 45 | } 46 | -------------------------------------------------------------------------------- /mocks/Terraformer.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import context "context" 6 | import mock "github.com/stretchr/testify/mock" 7 | 8 | // Terraformer is an autogenerated mock type for the Terraformer type 9 | type Terraformer struct { 10 | mock.Mock 11 | } 12 | 13 | // Apply provides a mock function with given fields: ctx, args 14 | func (_m *Terraformer) Apply(ctx context.Context, args []string) error { 15 | ret := _m.Called(ctx, args) 16 | 17 | var r0 error 18 | if rf, ok := ret.Get(0).(func(context.Context, []string) error); ok { 19 | r0 = rf(ctx, args) 20 | } else { 21 | r0 = ret.Error(0) 22 | } 23 | 24 | return r0 25 | } 26 | 27 | // GetOutput provides a mock function with given fields: ctx, key 28 | func (_m *Terraformer) GetOutput(ctx context.Context, key string) (string, error) { 29 | ret := _m.Called(ctx, key) 30 | 31 | var r0 string 32 | if rf, ok := ret.Get(0).(func(context.Context, string) string); ok { 33 | r0 = rf(ctx, key) 34 | } else { 35 | r0 = ret.Get(0).(string) 36 | } 37 | 38 | var r1 error 39 | if rf, ok := ret.Get(1).(func(context.Context, string) error); ok { 40 | r1 = rf(ctx, key) 41 | } else { 42 | r1 = ret.Error(1) 43 | } 44 | 45 | return r0, r1 46 | } 47 | 48 | // Init provides a mock function with given fields: ctx, args 49 | func (_m *Terraformer) Init(ctx context.Context, args []string) error { 50 | ret := _m.Called(ctx, args) 51 | 52 | var r0 error 53 | if rf, ok := ret.Get(0).(func(context.Context, []string) error); ok { 54 | r0 = rf(ctx, args) 55 | } else { 56 | r0 = ret.Error(0) 57 | } 58 | 59 | return r0 60 | } 61 | -------------------------------------------------------------------------------- /internal/observation/observation.go: -------------------------------------------------------------------------------- 1 | package observation 2 | 3 | import ( 4 | "io" 5 | "os" 6 | ) 7 | 8 | type ObservationContainer struct { 9 | Logger 10 | OutputWriter 11 | } 12 | 13 | func New(levelLogger LevelLogger) *ObservationContainer { 14 | 15 | logger := &LogObservation{ 16 | LevelLogger: levelLogger, 17 | } 18 | 19 | return &ObservationContainer{ 20 | Logger: logger, 21 | OutputWriter: os.Stdout, 22 | } 23 | } 24 | 25 | type OutputWriter interface { 26 | io.Writer 27 | } 28 | 29 | type Logger interface { 30 | LevelLogger 31 | // Endf logs and exits successfully (e.g. exit 0) 32 | Endf(format string, args ...interface{}) 33 | // End logs and exits successfully (e.g. exit 0) 34 | End(args ...interface{}) 35 | // Endln logs and exits successfully (e.g. exit 0) 36 | Endln(args ...interface{}) 37 | } 38 | 39 | //LevelLogger contains common functions for printing logs at different levels 40 | type LevelLogger interface { 41 | Debugf(format string, args ...interface{}) 42 | Infof(format string, args ...interface{}) 43 | Printf(format string, args ...interface{}) 44 | Warnf(format string, args ...interface{}) 45 | Errorf(format string, args ...interface{}) 46 | Fatalf(format string, args ...interface{}) 47 | 48 | Debug(args ...interface{}) 49 | Info(args ...interface{}) 50 | Print(args ...interface{}) 51 | Warn(args ...interface{}) 52 | Error(args ...interface{}) 53 | Fatal(args ...interface{}) 54 | 55 | Debugln(args ...interface{}) 56 | Infoln(args ...interface{}) 57 | Println(args ...interface{}) 58 | Warnln(args ...interface{}) 59 | Errorln(args ...interface{}) 60 | Fatalln(args ...interface{}) 61 | } 62 | -------------------------------------------------------------------------------- /mocks/Leaser.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | import service "github.com/Optum/dce-cli/pkg/service" 7 | 8 | // Leaser is an autogenerated mock type for the Leaser type 9 | type Leaser struct { 10 | mock.Mock 11 | } 12 | 13 | // CreateLease provides a mock function with given fields: principalID, budgetAmount, budgetCurrency, email, expiresOn 14 | func (_m *Leaser) CreateLease(principalID string, budgetAmount float64, budgetCurrency string, email []string, expiresOn string) { 15 | _m.Called(principalID, budgetAmount, budgetCurrency, email, expiresOn) 16 | } 17 | 18 | // EndLease provides a mock function with given fields: accountID, principalID 19 | func (_m *Leaser) EndLease(accountID string, principalID string) { 20 | _m.Called(accountID, principalID) 21 | } 22 | 23 | // GetLease provides a mock function with given fields: leaseID 24 | func (_m *Leaser) GetLease(leaseID string) { 25 | _m.Called(leaseID) 26 | } 27 | 28 | // ListLeases provides a mock function with given fields: acctID, principalID, nextAcctID, nextPrincipalID, leaseStatus, pagLimit 29 | func (_m *Leaser) ListLeases(acctID string, principalID string, nextAcctID string, nextPrincipalID string, leaseStatus string, pagLimit int64) { 30 | _m.Called(acctID, principalID, nextAcctID, nextPrincipalID, leaseStatus, pagLimit) 31 | } 32 | 33 | // Login provides a mock function with given fields: opts 34 | func (_m *Leaser) Login(opts *service.LeaseLoginOptions) { 35 | _m.Called(opts) 36 | } 37 | 38 | // LoginByID provides a mock function with given fields: leaseID, opts 39 | func (_m *Leaser) LoginByID(leaseID string, opts *service.LeaseLoginOptions) { 40 | _m.Called(leaseID, opts) 41 | } 42 | -------------------------------------------------------------------------------- /models/usage.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package models 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | strfmt "github.com/go-openapi/strfmt" 10 | "github.com/go-openapi/swag" 11 | ) 12 | 13 | // Usage usage cost of the aws account from start date to end date 14 | // swagger:model usage 15 | type Usage struct { 16 | 17 | // accountId of the AWS account 18 | AccountID string `json:"accountId,omitempty"` 19 | 20 | // usage cost Amount of AWS account for given period 21 | CostAmount float64 `json:"costAmount,omitempty"` 22 | 23 | // usage cost currency 24 | CostCurrency string `json:"costCurrency,omitempty"` 25 | 26 | // usage end date as Epoch Timestamp 27 | EndDate float64 `json:"endDate,omitempty"` 28 | 29 | // principalId of the user who owns the lease of the AWS account 30 | // 31 | PrincipalID string `json:"principalId,omitempty"` 32 | 33 | // usage start date as Epoch Timestamp 34 | StartDate float64 `json:"startDate,omitempty"` 35 | 36 | // ttl attribute as Epoch Timestamp 37 | TimeToLive float64 `json:"timeToLive,omitempty"` 38 | } 39 | 40 | // Validate validates this usage 41 | func (m *Usage) Validate(formats strfmt.Registry) error { 42 | return nil 43 | } 44 | 45 | // MarshalBinary interface implementation 46 | func (m *Usage) MarshalBinary() ([]byte, error) { 47 | if m == nil { 48 | return nil, nil 49 | } 50 | return swag.WriteJSON(m) 51 | } 52 | 53 | // UnmarshalBinary interface implementation 54 | func (m *Usage) UnmarshalBinary(b []byte) error { 55 | var res Usage 56 | if err := swag.ReadJSON(b, &res); err != nil { 57 | return err 58 | } 59 | *m = res 60 | return nil 61 | } 62 | -------------------------------------------------------------------------------- /models/lease_status.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package models 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "encoding/json" 10 | 11 | "github.com/go-openapi/errors" 12 | strfmt "github.com/go-openapi/strfmt" 13 | "github.com/go-openapi/validate" 14 | ) 15 | 16 | // LeaseStatus Status of the Lease. 17 | // "Active": The principal is leased and has access to the account 18 | // "Inactive": The lease has become inactive, either through expiring, exceeding budget, or by request. 19 | // 20 | // swagger:model leaseStatus 21 | type LeaseStatus string 22 | 23 | const ( 24 | 25 | // LeaseStatusActive captures enum value "Active" 26 | LeaseStatusActive LeaseStatus = "Active" 27 | 28 | // LeaseStatusInactive captures enum value "Inactive" 29 | LeaseStatusInactive LeaseStatus = "Inactive" 30 | ) 31 | 32 | // for schema 33 | var leaseStatusEnum []interface{} 34 | 35 | func init() { 36 | var res []LeaseStatus 37 | if err := json.Unmarshal([]byte(`["Active","Inactive"]`), &res); err != nil { 38 | panic(err) 39 | } 40 | for _, v := range res { 41 | leaseStatusEnum = append(leaseStatusEnum, v) 42 | } 43 | } 44 | 45 | func (m LeaseStatus) validateLeaseStatusEnum(path, location string, value LeaseStatus) error { 46 | if err := validate.Enum(path, location, value, leaseStatusEnum); err != nil { 47 | return err 48 | } 49 | return nil 50 | } 51 | 52 | // Validate validates this lease status 53 | func (m LeaseStatus) Validate(formats strfmt.Registry) error { 54 | var res []error 55 | 56 | // value enum 57 | if err := m.validateLeaseStatusEnum("", "body", m); err != nil { 58 | return err 59 | } 60 | 61 | if len(res) > 0 { 62 | return errors.CompositeValidationError(res...) 63 | } 64 | return nil 65 | } 66 | -------------------------------------------------------------------------------- /pkg/service/auth.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "net/url" 7 | "path" 8 | "time" 9 | 10 | "github.com/Optum/dce-cli/configs" 11 | observ "github.com/Optum/dce-cli/internal/observation" 12 | utl "github.com/Optum/dce-cli/internal/util" 13 | ) 14 | 15 | type AuthService struct { 16 | Config *configs.Root 17 | Observation *observ.ObservationContainer 18 | Util *utl.UtilContainer 19 | } 20 | 21 | func (s *AuthService) Authenticate() error { 22 | // Check that our API is configured properly 23 | if s.Config.API.Host == nil || s.Config.API.BasePath == nil { 24 | return errors.New("Unable to authenticate against DCE API: missing API configuration") 25 | } 26 | 27 | log.Println("Opening web browser. Please Login and copy/paste the provided token into this terminal.") 28 | // Wait a moment, so the user can see our message, and know what's going on 29 | time.Sleep(1 * time.Second) 30 | 31 | // Open the DCE API's /auth URL 32 | // this will use Cognito to redirect the user to 33 | // their configured IDP, then back to the /auth page, 34 | // which will display a "auth code" to the end-user. 35 | // The user will then need to copy the auth code 36 | // into their CLI prompt. 37 | authUrl := url.URL{ 38 | Scheme: "https", 39 | Host: *s.Config.API.Host, 40 | Path: path.Join(*s.Config.API.BasePath, "/auth"), 41 | } 42 | s.Util.OpenURL(authUrl.String()) 43 | 44 | // Prompt for the auth code 45 | authCode := s.Util.PromptBasic( 46 | "Enter API Token: ", nil, 47 | ) 48 | 49 | // Update the dce.yml config, with the token 50 | log.Printf("Saving API Token to %s", s.Util.GetConfigFile()) 51 | s.Config.API.Token = authCode 52 | err := s.Util.WriteConfig() 53 | if err != nil { 54 | return fmt.Errorf("Failed to write to %s: %s", 55 | s.Util.GetConfigFile(), err) 56 | } 57 | 58 | return nil 59 | } 60 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## Proposed changes 2 | 3 | 6 | 7 | 8 | 9 | ## Types of changes 10 | 11 | 15 | 16 | - [ ] Bugfix (non-breaking change which fixes an issue) 17 | - [ ] New feature (non-breaking change which adds functionality) 18 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) 19 | - [ ] Refactor (changes to code, which do not change application behavior) 20 | 21 | ## Checklist 22 | 23 | 26 | 27 | - [ ] I have filled out this PR template 28 | - [ ] I have read the [CONTRIBUTING](https://github.com/Optum/dce/blob/master/docs/CONTRIBUTING.md) doc 29 | - [ ] I have added automated tests that prove my fix is effective or that my feature works 30 | - [ ] I have added necessary documentation (`README.md`, inline comments, etc.) 31 | - [ ] I have updated the `CHANGELOG.md` under a `## next` release, with a short summary of my changes 32 | 33 | ## Relevant Links 34 | 35 | 42 | 43 | 44 | ## Further comments 45 | 46 | -------------------------------------------------------------------------------- /tests/integration/util.go: -------------------------------------------------------------------------------- 1 | package integration 2 | 3 | import ( 4 | "archive/zip" 5 | "bytes" 6 | "encoding/json" 7 | "github.com/stretchr/testify/require" 8 | "io/ioutil" 9 | "os" 10 | "testing" 11 | ) 12 | 13 | type file struct{ Name, Body string } 14 | 15 | // Adapted from https://golang.org/pkg/archive/zip/#example_Writer 16 | func zipFiles(t *testing.T, files []file) []byte { 17 | // Create a buffer to write our archive to. 18 | buf := new(bytes.Buffer) 19 | 20 | // Create a new zip archive. 21 | w := zip.NewWriter(buf) 22 | 23 | // Add some files to the archive. 24 | for _, file := range files { 25 | f, err := w.Create(file.Name) 26 | require.Nil(t, err) 27 | _, err = f.Write([]byte(file.Body)) 28 | require.Nil(t, err) 29 | } 30 | 31 | // Make sure to check the error on Close. 32 | err := w.Close() 33 | require.Nil(t, err) 34 | 35 | zipBytes, err := ioutil.ReadAll(buf) 36 | require.Nil(t, err) 37 | 38 | return zipBytes 39 | } 40 | 41 | // mockEnvVar Sets an env var 42 | // returns a function to revert the env var back to its previous value 43 | func mockEnvVar(key, val string) func() { 44 | prevVal, ok := os.LookupEnv(key) 45 | _ = os.Setenv(key, val) 46 | 47 | return func() { 48 | if ok { 49 | _ = os.Setenv(key, prevVal) 50 | } else { 51 | _ = os.Unsetenv(key) 52 | } 53 | } 54 | } 55 | 56 | func stringp(str string) *string { 57 | return &str 58 | } 59 | 60 | func boolp(b bool) *bool { 61 | return &b 62 | } 63 | 64 | // copyStructVals copies all values from the source stuct 65 | // into the target struct 66 | // Structs must be JSON encode-able 67 | func copyStructVals(t *testing.T, source interface{}, target interface{}) { 68 | // We're using JSON as a means to copy values, 69 | // which has some limitations. 70 | // This could probably be done more reliably, but 71 | // with a lot more complex code, using reflection. 72 | sourceJSON, err := json.Marshal(&source) 73 | require.Nil(t, err) 74 | err = json.Unmarshal(sourceJSON, target) 75 | require.Nil(t, err) 76 | } 77 | -------------------------------------------------------------------------------- /internal/util/ifaces.go: -------------------------------------------------------------------------------- 1 | // Created by interfacer; DO NOT EDIT 2 | 3 | package util 4 | 5 | import ( 6 | "github.com/Optum/dce-cli/client/operations" 7 | "github.com/go-openapi/runtime" 8 | ) 9 | 10 | // APIer is an interface generated for "github.com/Optum/dce-cli/client/operations.Client". 11 | type APIer interface { 12 | DeleteAccountsID(*operations.DeleteAccountsIDParams, runtime.ClientAuthInfoWriter) (*operations.DeleteAccountsIDNoContent, error) 13 | DeleteLeases(*operations.DeleteLeasesParams, runtime.ClientAuthInfoWriter) (*operations.DeleteLeasesOK, error) 14 | DeleteLeasesID(*operations.DeleteLeasesIDParams, runtime.ClientAuthInfoWriter) (*operations.DeleteLeasesIDOK, error) 15 | GetAccounts(*operations.GetAccountsParams, runtime.ClientAuthInfoWriter) (*operations.GetAccountsOK, error) 16 | GetAccountsID(*operations.GetAccountsIDParams, runtime.ClientAuthInfoWriter) (*operations.GetAccountsIDOK, error) 17 | GetAuth(*operations.GetAuthParams) (*operations.GetAuthOK, error) 18 | GetAuthFile(*operations.GetAuthFileParams) (*operations.GetAuthFileOK, error) 19 | GetLeases(*operations.GetLeasesParams, runtime.ClientAuthInfoWriter) (*operations.GetLeasesOK, error) 20 | GetLeasesID(*operations.GetLeasesIDParams, runtime.ClientAuthInfoWriter) (*operations.GetLeasesIDOK, error) 21 | GetUsage(*operations.GetUsageParams, runtime.ClientAuthInfoWriter) (*operations.GetUsageOK, error) 22 | PostAccounts(*operations.PostAccountsParams, runtime.ClientAuthInfoWriter) (*operations.PostAccountsCreated, error) 23 | PostLeases(*operations.PostLeasesParams, runtime.ClientAuthInfoWriter) (*operations.PostLeasesCreated, error) 24 | PostLeasesAuth(*operations.PostLeasesAuthParams, runtime.ClientAuthInfoWriter) (*operations.PostLeasesAuthCreated, error) 25 | PostLeasesIDAuth(*operations.PostLeasesIDAuthParams, runtime.ClientAuthInfoWriter) (*operations.PostLeasesIDAuthCreated, error) 26 | PutAccountsID(*operations.PutAccountsIDParams, runtime.ClientAuthInfoWriter) (*operations.PutAccountsIDOK, error) 27 | SetTransport(runtime.ClientTransport) 28 | } 29 | -------------------------------------------------------------------------------- /tests/integration/mock_prompter.go: -------------------------------------------------------------------------------- 1 | package integration 2 | 3 | import ( 4 | "github.com/stretchr/testify/assert" 5 | "github.com/stretchr/testify/require" 6 | "reflect" 7 | "testing" 8 | ) 9 | 10 | type basicAnswer struct { 11 | question string 12 | answer string 13 | wasAsked bool 14 | } 15 | type selectAnswer struct { 16 | question string 17 | options []string 18 | answer string 19 | wasAsked bool 20 | } 21 | type MockPrompter struct { 22 | T *testing.T 23 | basicAnswers []*basicAnswer 24 | selectAnswers []*selectAnswer 25 | } 26 | 27 | func (m *MockPrompter) PromptBasic(label string, validator func(input string) error) *string { 28 | // Find a matching answer 29 | var answer *basicAnswer 30 | for _, ans := range m.basicAnswers { 31 | if ans.question == label && !ans.wasAsked { 32 | answer = ans 33 | break 34 | } 35 | } 36 | require.NotNilf(m.T, answer, "No matching answer for prompt '%s'", label) 37 | 38 | answer.wasAsked = true 39 | return &answer.answer 40 | } 41 | 42 | func (m *MockPrompter) PromptSelect(label string, items []string) *string { 43 | // Find a matching answer 44 | var answer *selectAnswer 45 | for _, ans := range m.selectAnswers { 46 | if ans.question == label && reflect.DeepEqual(items, ans.options) && !ans.wasAsked { 47 | answer = ans 48 | break 49 | } 50 | } 51 | require.NotNil(m.T, answer, "Failed to answer prompt '%s': no matching answer", label) 52 | 53 | answer.wasAsked = true 54 | return &answer.answer 55 | } 56 | 57 | func (m *MockPrompter) AnswerBasic(question string, answer string) { 58 | m.basicAnswers = append(m.basicAnswers, &basicAnswer{ 59 | question, answer, false, 60 | }) 61 | } 62 | 63 | func (m *MockPrompter) AnswerSelect(question string, expectedOptions []string, answer string) { 64 | m.selectAnswers = append(m.selectAnswers, &selectAnswer{ 65 | question, expectedOptions, answer, false, 66 | }) 67 | } 68 | 69 | func (m *MockPrompter) AssertAllPrompts() { 70 | for _, answer := range m.basicAnswers { 71 | assert.Truef(m.T, answer.wasAsked, "Prompt for '%s' was never asked", answer.question) 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /cmd/accounts.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "github.com/spf13/cobra" 5 | ) 6 | 7 | var accountID string 8 | var adminRoleARN string 9 | 10 | func init() { 11 | accountsCmd.AddCommand(accountsListCmd) 12 | 13 | accountsAddCmd.Flags().StringVarP(&accountID, "account-id", "a", "", "The ID of the existing account to add to the DCE accounts pool (WARNING: Account will be nuked.)") 14 | accountsAddCmd.Flags().StringVarP(&adminRoleARN, "admin-role-arn", "r", "", "The admin role arn to be assumed by the DCE master account. Trust policy must be configured with DCE master account as trusted entity.") 15 | if err := accountsAddCmd.MarkFlagRequired("account-id"); err != nil { 16 | log.Fatalln(err) 17 | } 18 | if err := accountsAddCmd.MarkFlagRequired("admin-role-arn"); err != nil { 19 | log.Fatalln(err) 20 | } 21 | accountsCmd.AddCommand(accountsAddCmd) 22 | 23 | accountsCmd.AddCommand(accountsRemoveCmd) 24 | accountsCmd.AddCommand(accountsDescribeCmd) 25 | RootCmd.AddCommand(accountsCmd) 26 | } 27 | 28 | var accountsCmd = &cobra.Command{ 29 | Use: "accounts", 30 | Short: "Manage dce accounts", 31 | } 32 | 33 | var accountsDescribeCmd = &cobra.Command{ 34 | Use: "describe [Accound ID]", 35 | Short: "describe an account", 36 | Args: cobra.ExactValidArgs(1), 37 | Run: func(cmd *cobra.Command, args []string) { 38 | Service.GetAccount(args[0]) 39 | }, 40 | } 41 | 42 | var accountsListCmd = &cobra.Command{ 43 | Use: "list", 44 | Short: "list accounts", 45 | Args: cobra.NoArgs, 46 | Run: func(cmd *cobra.Command, args []string) { 47 | Service.ListAccounts() 48 | }, 49 | } 50 | 51 | var accountsAddCmd = &cobra.Command{ 52 | Use: "add", 53 | Short: "Add an account to the accounts pool", 54 | Args: cobra.NoArgs, 55 | Run: func(cmd *cobra.Command, args []string) { 56 | Service.AddAccount(accountID, adminRoleARN) 57 | }, 58 | } 59 | 60 | var accountsRemoveCmd = &cobra.Command{ 61 | Use: "remove [Account ID]", 62 | Short: "Remove an account from the accounts pool.", 63 | Args: cobra.ExactValidArgs(1), 64 | Run: func(cmd *cobra.Command, args []string) { 65 | Service.RemoveAccount(args[0]) 66 | }, 67 | } 68 | -------------------------------------------------------------------------------- /tests/integration/auth_test.go: -------------------------------------------------------------------------------- 1 | package integration 2 | 3 | import ( 4 | "fmt" 5 | "github.com/Optum/dce-cli/configs" 6 | "github.com/Optum/dce-cli/mocks" 7 | "github.com/stretchr/testify/require" 8 | "go.uber.org/thriftrw/ptr" 9 | "testing" 10 | ) 11 | 12 | func TestAuthCommand(t *testing.T) { 13 | 14 | t.Run("GIVEN auth command is run", func(t *testing.T) { 15 | 16 | t.Run("THEN API token should be saved to config file", func(t *testing.T) { 17 | cli := NewCLITest(t) 18 | 19 | // Setup a basic config file 20 | confFile := writeTempConfig(t, &configs.Root{ 21 | API: configs.API{ 22 | Host: ptr.String("dce.example.com"), 23 | BasePath: ptr.String("/api"), 24 | }, 25 | }) 26 | 27 | // Mock Weber.OpenURL() 28 | mockWeber := &mocks.Weber{} 29 | cli.Inject(func(input *injectorInput) { 30 | input.service.Util.Weber = mockWeber 31 | }) 32 | mockWeber.On("OpenURL", "https://dce.example.com/api/auth") 33 | 34 | // Enter the API Token (IRL, would be provided by the web page) 35 | cli.AnswerBasic("Enter API Token: ", "my-api-token") 36 | 37 | // Run DCE auth 38 | err := cli.Execute([]string{"auth", "--config", confFile}) 39 | require.Nil(t, err) 40 | 41 | cli.AssertAllPrompts() 42 | mockWeber.AssertExpectations(t) 43 | 44 | output := cli.Output() 45 | require.Contains(t, output, "Opening web browser. Please Login and copy/paste the provided token into this terminal.") 46 | require.Contains(t, output, fmt.Sprintf("Saving API Token to %s", confFile)) 47 | }) 48 | 49 | t.Run("AND no API configuration is set", func(t *testing.T) { 50 | 51 | t.Run("THEN auth command should fail", func(t *testing.T) { 52 | cli := NewCLITest(t) 53 | 54 | // Setup a config file, missing API info 55 | confFile := writeTempConfig(t, &configs.Root{ 56 | API: configs.API{}, 57 | }) 58 | 59 | // Run DCE auth 60 | err := cli.Execute([]string{"auth", "--config", confFile}) 61 | require.NotNil(t, err) 62 | 63 | require.Equal(t, 64 | "Unable to authenticate against DCE API: missing API configuration", 65 | err.Error(), 66 | ) 67 | }) 68 | 69 | }) 70 | }) 71 | } 72 | -------------------------------------------------------------------------------- /tests/unit/config_test.go: -------------------------------------------------------------------------------- 1 | package unit 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | 7 | cfg "github.com/Optum/dce-cli/configs" 8 | ) 9 | 10 | const Empty string = "" 11 | 12 | func TestCoalesce(t *testing.T) { 13 | 14 | os.Setenv("TEST_CONFIG_VAL", "envval") 15 | 16 | tests := []struct { 17 | name string 18 | arg string 19 | config string 20 | envvar string 21 | def string 22 | want string 23 | }{ 24 | { 25 | name: "get default because everything else is empty", 26 | arg: Empty, 27 | config: Empty, 28 | envvar: Empty, 29 | def: "defaultval", 30 | want: "defaultval", 31 | }, 32 | { 33 | name: "get default because env doesn't exist", 34 | arg: Empty, 35 | config: Empty, 36 | envvar: "SOME_RANDOM_VAR_THAT_SHOULD_NOT_EXIST", 37 | def: "defaultval", 38 | want: "defaultval", 39 | }, 40 | { 41 | name: "get environment val because everything else is empty", 42 | arg: Empty, 43 | config: Empty, 44 | envvar: "TEST_CONFIG_VAL", 45 | def: "defaultval", 46 | want: "envval", 47 | }, 48 | { 49 | name: "get environment val over config", 50 | arg: Empty, 51 | config: "configval", 52 | envvar: "TEST_CONFIG_VAL", 53 | def: "defaultval", 54 | want: "envval", 55 | }, 56 | { 57 | name: "get config if env is empty", 58 | arg: Empty, 59 | config: "configval", 60 | envvar: Empty, 61 | def: "defaultval", 62 | want: "configval", 63 | }, 64 | { 65 | name: "get arg first", 66 | arg: "argval", 67 | config: "configval", 68 | envvar: "TEST_CONFIG_VAL", 69 | def: "defaultval", 70 | want: "argval", 71 | }, 72 | } 73 | for _, tt := range tests { 74 | t.Run(tt.name, func(t *testing.T) { 75 | if got := cfg.Coalesce(&tt.arg, &tt.config, &tt.envvar, &tt.def); *got != tt.want { 76 | t.Errorf("Coalesce() = %v, want %v", got, tt.want) 77 | } 78 | }) 79 | } 80 | } 81 | 82 | func TestCoalesce_WithNils(t *testing.T) { 83 | expected := "defaultval" 84 | if got := cfg.Coalesce(nil, nil, nil, &expected); *got != expected { 85 | t.Errorf("Coalesce() = %v, want %v", got, expected) 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /models/account_status.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package models 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "encoding/json" 10 | 11 | "github.com/go-openapi/errors" 12 | strfmt "github.com/go-openapi/strfmt" 13 | "github.com/go-openapi/validate" 14 | ) 15 | 16 | // AccountStatus Status of the Account. 17 | // "Ready": The account is clean and ready for lease 18 | // "NotReady": The account is in "dirty" state, and needs to be reset before it may be leased. 19 | // "Leased": The account is leased to a principal 20 | // 21 | // swagger:model accountStatus 22 | type AccountStatus string 23 | 24 | const ( 25 | 26 | // AccountStatusReady captures enum value "Ready" 27 | AccountStatusReady AccountStatus = "Ready" 28 | 29 | // AccountStatusNotReady captures enum value "NotReady" 30 | AccountStatusNotReady AccountStatus = "NotReady" 31 | 32 | // AccountStatusLeased captures enum value "Leased" 33 | AccountStatusLeased AccountStatus = "Leased" 34 | 35 | // AccountStatusOrphaned captures enum value "Orphaned" 36 | AccountStatusOrphaned AccountStatus = "Orphaned" 37 | ) 38 | 39 | // for schema 40 | var accountStatusEnum []interface{} 41 | 42 | func init() { 43 | var res []AccountStatus 44 | if err := json.Unmarshal([]byte(`["Ready","NotReady","Leased","Orphaned"]`), &res); err != nil { 45 | panic(err) 46 | } 47 | for _, v := range res { 48 | accountStatusEnum = append(accountStatusEnum, v) 49 | } 50 | } 51 | 52 | func (m AccountStatus) validateAccountStatusEnum(path, location string, value AccountStatus) error { 53 | if err := validate.Enum(path, location, value, accountStatusEnum); err != nil { 54 | return err 55 | } 56 | return nil 57 | } 58 | 59 | // Validate validates this account status 60 | func (m AccountStatus) Validate(formats strfmt.Registry) error { 61 | var res []error 62 | 63 | // value enum 64 | if err := m.validateAccountStatusEnum("", "body", m); err != nil { 65 | return err 66 | } 67 | 68 | if len(res) > 0 { 69 | return errors.CompositeValidationError(res...) 70 | } 71 | return nil 72 | } 73 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_auth_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | 11 | "github.com/go-openapi/runtime" 12 | 13 | strfmt "github.com/go-openapi/strfmt" 14 | ) 15 | 16 | // OptionsAuthReader is a Reader for the OptionsAuth structure. 17 | type OptionsAuthReader struct { 18 | formats strfmt.Registry 19 | } 20 | 21 | // ReadResponse reads a server response into the received o. 22 | func (o *OptionsAuthReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 23 | switch response.Code() { 24 | case 200: 25 | result := NewOptionsAuthOK() 26 | if err := result.readResponse(response, consumer, o.formats); err != nil { 27 | return nil, err 28 | } 29 | return result, nil 30 | 31 | default: 32 | return nil, runtime.NewAPIError("unknown error", response, response.Code()) 33 | } 34 | } 35 | 36 | // NewOptionsAuthOK creates a OptionsAuthOK with default headers values 37 | func NewOptionsAuthOK() *OptionsAuthOK { 38 | return &OptionsAuthOK{} 39 | } 40 | 41 | /*OptionsAuthOK handles this case with default header values. 42 | 43 | Default response for CORS method 44 | */ 45 | type OptionsAuthOK struct { 46 | AccessControlAllowHeaders string 47 | 48 | AccessControlAllowMethods string 49 | 50 | AccessControlAllowOrigin string 51 | } 52 | 53 | func (o *OptionsAuthOK) Error() string { 54 | return fmt.Sprintf("[OPTIONS /auth][%d] optionsAuthOK ", 200) 55 | } 56 | 57 | func (o *OptionsAuthOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 58 | 59 | // response header Access-Control-Allow-Headers 60 | o.AccessControlAllowHeaders = response.GetHeader("Access-Control-Allow-Headers") 61 | 62 | // response header Access-Control-Allow-Methods 63 | o.AccessControlAllowMethods = response.GetHeader("Access-Control-Allow-Methods") 64 | 65 | // response header Access-Control-Allow-Origin 66 | o.AccessControlAllowOrigin = response.GetHeader("Access-Control-Allow-Origin") 67 | 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /tests/unit/terraform_test.go: -------------------------------------------------------------------------------- 1 | package unit 2 | 3 | import ( 4 | "reflect" 5 | "testing" 6 | 7 | util "github.com/Optum/dce-cli/internal/util" 8 | ) 9 | 10 | func TestTerraformBinUtil_ParseOptions(t *testing.T) { 11 | 12 | tests := []struct { 13 | name string 14 | str string 15 | want []string 16 | wantErr bool 17 | }{ 18 | { 19 | name: "should return empty array with empty string", 20 | str: "", 21 | want: []string{}, 22 | }, 23 | { 24 | name: "should parse normal space-delimited string", 25 | str: "-backend-config=\"address=demo.consul.io\" -backend-config=\"path=example_app/terraform_state\"", 26 | want: []string{ 27 | "-backend-config=\"address=demo.consul.io\"", 28 | "-backend-config=\"path=example_app/terraform_state\"", 29 | }, 30 | }, 31 | { 32 | name: "should parse normal multi-space-delimited string", 33 | str: "-backend-config=\"address=demo.consul.io\" -backend-config=\"path=example_app/terraform_state\"", 34 | want: []string{ 35 | "-backend-config=\"address=demo.consul.io\"", 36 | "-backend-config=\"path=example_app/terraform_state\"", 37 | }, 38 | }, 39 | { 40 | name: "should parse normal tab-delimited string", 41 | str: `-backend-config="address=demo.consul.io" -backend-config="path=example_app/terraform_state"`, 42 | want: []string{ 43 | "-backend-config=\"address=demo.consul.io\"", 44 | "-backend-config=\"path=example_app/terraform_state\"", 45 | }, 46 | }, 47 | { 48 | name: "should parse normal newline-delimited string", 49 | str: `-backend-config="address=demo.consul.io" 50 | -backend-config="path=example_app/terraform_state"`, 51 | want: []string{ 52 | "-backend-config=\"address=demo.consul.io\"", 53 | "-backend-config=\"path=example_app/terraform_state\"", 54 | }, 55 | }, 56 | } 57 | for _, tt := range tests { 58 | t.Run(tt.name, func(t *testing.T) { 59 | got, err := util.ParseOptions(&tt.str) 60 | if (err != nil) != tt.wantErr { 61 | t.Errorf("ParseOptions() error = %v, wantErr %v", err, tt.wantErr) 62 | return 63 | } 64 | if !reflect.DeepEqual(got, tt.want) { 65 | t.Errorf("ParseOptions() = %v, want %v", got, tt.want) 66 | } 67 | }) 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_usage_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | 11 | "github.com/go-openapi/runtime" 12 | 13 | strfmt "github.com/go-openapi/strfmt" 14 | ) 15 | 16 | // OptionsUsageReader is a Reader for the OptionsUsage structure. 17 | type OptionsUsageReader struct { 18 | formats strfmt.Registry 19 | } 20 | 21 | // ReadResponse reads a server response into the received o. 22 | func (o *OptionsUsageReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 23 | switch response.Code() { 24 | case 200: 25 | result := NewOptionsUsageOK() 26 | if err := result.readResponse(response, consumer, o.formats); err != nil { 27 | return nil, err 28 | } 29 | return result, nil 30 | 31 | default: 32 | return nil, runtime.NewAPIError("unknown error", response, response.Code()) 33 | } 34 | } 35 | 36 | // NewOptionsUsageOK creates a OptionsUsageOK with default headers values 37 | func NewOptionsUsageOK() *OptionsUsageOK { 38 | return &OptionsUsageOK{} 39 | } 40 | 41 | /*OptionsUsageOK handles this case with default header values. 42 | 43 | Default response for CORS method 44 | */ 45 | type OptionsUsageOK struct { 46 | AccessControlAllowHeaders string 47 | 48 | AccessControlAllowMethods string 49 | 50 | AccessControlAllowOrigin string 51 | } 52 | 53 | func (o *OptionsUsageOK) Error() string { 54 | return fmt.Sprintf("[OPTIONS /usage][%d] optionsUsageOK ", 200) 55 | } 56 | 57 | func (o *OptionsUsageOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 58 | 59 | // response header Access-Control-Allow-Headers 60 | o.AccessControlAllowHeaders = response.GetHeader("Access-Control-Allow-Headers") 61 | 62 | // response header Access-Control-Allow-Methods 63 | o.AccessControlAllowMethods = response.GetHeader("Access-Control-Allow-Methods") 64 | 65 | // response header Access-Control-Allow-Origin 66 | o.AccessControlAllowOrigin = response.GetHeader("Access-Control-Allow-Origin") 67 | 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_leases_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | 11 | "github.com/go-openapi/runtime" 12 | 13 | strfmt "github.com/go-openapi/strfmt" 14 | ) 15 | 16 | // OptionsLeasesReader is a Reader for the OptionsLeases structure. 17 | type OptionsLeasesReader struct { 18 | formats strfmt.Registry 19 | } 20 | 21 | // ReadResponse reads a server response into the received o. 22 | func (o *OptionsLeasesReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 23 | switch response.Code() { 24 | case 200: 25 | result := NewOptionsLeasesOK() 26 | if err := result.readResponse(response, consumer, o.formats); err != nil { 27 | return nil, err 28 | } 29 | return result, nil 30 | 31 | default: 32 | return nil, runtime.NewAPIError("unknown error", response, response.Code()) 33 | } 34 | } 35 | 36 | // NewOptionsLeasesOK creates a OptionsLeasesOK with default headers values 37 | func NewOptionsLeasesOK() *OptionsLeasesOK { 38 | return &OptionsLeasesOK{} 39 | } 40 | 41 | /*OptionsLeasesOK handles this case with default header values. 42 | 43 | Default response for CORS method 44 | */ 45 | type OptionsLeasesOK struct { 46 | AccessControlAllowHeaders string 47 | 48 | AccessControlAllowMethods string 49 | 50 | AccessControlAllowOrigin string 51 | } 52 | 53 | func (o *OptionsLeasesOK) Error() string { 54 | return fmt.Sprintf("[OPTIONS /leases][%d] optionsLeasesOK ", 200) 55 | } 56 | 57 | func (o *OptionsLeasesOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 58 | 59 | // response header Access-Control-Allow-Headers 60 | o.AccessControlAllowHeaders = response.GetHeader("Access-Control-Allow-Headers") 61 | 62 | // response header Access-Control-Allow-Methods 63 | o.AccessControlAllowMethods = response.GetHeader("Access-Control-Allow-Methods") 64 | 65 | // response header Access-Control-Allow-Origin 66 | o.AccessControlAllowOrigin = response.GetHeader("Access-Control-Allow-Origin") 67 | 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /configs/config.go: -------------------------------------------------------------------------------- 1 | package configs 2 | 3 | import "os" 4 | 5 | // Root contains config 6 | type Root struct { 7 | API API 8 | Region *string 9 | Deploy Deploy `yaml:"deploy,omitempty"` 10 | Terraform Terraform 11 | } 12 | 13 | type API struct { 14 | Host *string 15 | BasePath *string 16 | // Token for authenticating against the API 17 | // token is base64 encoded JSON, containing an STS token. 18 | Token *string `yaml:"token,omitempty"` 19 | } 20 | 21 | type Deploy struct { 22 | // Path to the DCE repo to deploy 23 | // May be a local file path (eg. /path/to/dce) 24 | // or a github repo (eg. github.com/Optum/dce) 25 | Location *string `yaml:"location,omitempty"` 26 | // Version of DCE to deploy, eg 0.12.3 27 | Version *string `yaml:"version,omitempty"` 28 | // Deployment logs will be written to this location 29 | LogFile *string `yaml:"logFile,omitempty"` 30 | // AWS Region in which to deploy DCE 31 | AWSRegion *string `yaml:"region,omitempty"` 32 | // Namespace used as naming suffix for AWS resources 33 | Namespace *string `yaml:"namespace,omitempty"` 34 | BudgetNotificationFromEmail *string `yaml:"budgetNotificationFromEmail,omitempty"` 35 | } 36 | 37 | // Terraform contains configuration for the underlying terraform 38 | // command used to provision the DCE infrastructure. 39 | type Terraform struct { 40 | Bin *string 41 | Source *string // URL from which the Terraform release was downloaded 42 | TFInitOptions *string `yaml:"initOptions,omitempty"` 43 | TFApplyOptions *string `yaml:"applyOptions,omitempty"` 44 | } 45 | 46 | var Regions = []string{"us-east-1", "us-east-2", "us-west-1", "us-west-2"} 47 | 48 | // Coalesce returns the first non-empty value, but takes into account a loading order, 49 | // which is CLI args > environment variables > config file > some default 50 | func Coalesce(arg *string, config *string, envvar *string, def *string) *string { 51 | 52 | if arg != nil && len(*arg) > 0 { 53 | return arg 54 | } 55 | 56 | if envvar != nil { 57 | envval, ok := os.LookupEnv(*envvar) 58 | 59 | if ok && len(envval) > 0 { 60 | return &envval 61 | } 62 | } 63 | 64 | if config != nil && len(*config) > 0 { 65 | return config 66 | } 67 | 68 | return def 69 | } 70 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_accounts_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | 11 | "github.com/go-openapi/runtime" 12 | 13 | strfmt "github.com/go-openapi/strfmt" 14 | ) 15 | 16 | // OptionsAccountsReader is a Reader for the OptionsAccounts structure. 17 | type OptionsAccountsReader struct { 18 | formats strfmt.Registry 19 | } 20 | 21 | // ReadResponse reads a server response into the received o. 22 | func (o *OptionsAccountsReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 23 | switch response.Code() { 24 | case 200: 25 | result := NewOptionsAccountsOK() 26 | if err := result.readResponse(response, consumer, o.formats); err != nil { 27 | return nil, err 28 | } 29 | return result, nil 30 | 31 | default: 32 | return nil, runtime.NewAPIError("unknown error", response, response.Code()) 33 | } 34 | } 35 | 36 | // NewOptionsAccountsOK creates a OptionsAccountsOK with default headers values 37 | func NewOptionsAccountsOK() *OptionsAccountsOK { 38 | return &OptionsAccountsOK{} 39 | } 40 | 41 | /*OptionsAccountsOK handles this case with default header values. 42 | 43 | Default response for CORS method 44 | */ 45 | type OptionsAccountsOK struct { 46 | AccessControlAllowHeaders string 47 | 48 | AccessControlAllowMethods string 49 | 50 | AccessControlAllowOrigin string 51 | } 52 | 53 | func (o *OptionsAccountsOK) Error() string { 54 | return fmt.Sprintf("[OPTIONS /accounts][%d] optionsAccountsOK ", 200) 55 | } 56 | 57 | func (o *OptionsAccountsOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 58 | 59 | // response header Access-Control-Allow-Headers 60 | o.AccessControlAllowHeaders = response.GetHeader("Access-Control-Allow-Headers") 61 | 62 | // response header Access-Control-Allow-Methods 63 | o.AccessControlAllowMethods = response.GetHeader("Access-Control-Allow-Methods") 64 | 65 | // response header Access-Control-Allow-Origin 66 | o.AccessControlAllowOrigin = response.GetHeader("Access-Control-Allow-Origin") 67 | 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_auth_file_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | 11 | "github.com/go-openapi/runtime" 12 | 13 | strfmt "github.com/go-openapi/strfmt" 14 | ) 15 | 16 | // OptionsAuthFileReader is a Reader for the OptionsAuthFile structure. 17 | type OptionsAuthFileReader struct { 18 | formats strfmt.Registry 19 | } 20 | 21 | // ReadResponse reads a server response into the received o. 22 | func (o *OptionsAuthFileReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 23 | switch response.Code() { 24 | case 200: 25 | result := NewOptionsAuthFileOK() 26 | if err := result.readResponse(response, consumer, o.formats); err != nil { 27 | return nil, err 28 | } 29 | return result, nil 30 | 31 | default: 32 | return nil, runtime.NewAPIError("unknown error", response, response.Code()) 33 | } 34 | } 35 | 36 | // NewOptionsAuthFileOK creates a OptionsAuthFileOK with default headers values 37 | func NewOptionsAuthFileOK() *OptionsAuthFileOK { 38 | return &OptionsAuthFileOK{} 39 | } 40 | 41 | /*OptionsAuthFileOK handles this case with default header values. 42 | 43 | Default response for CORS method 44 | */ 45 | type OptionsAuthFileOK struct { 46 | AccessControlAllowHeaders string 47 | 48 | AccessControlAllowMethods string 49 | 50 | AccessControlAllowOrigin string 51 | } 52 | 53 | func (o *OptionsAuthFileOK) Error() string { 54 | return fmt.Sprintf("[OPTIONS /auth/{file+}][%d] optionsAuthFileOK ", 200) 55 | } 56 | 57 | func (o *OptionsAuthFileOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 58 | 59 | // response header Access-Control-Allow-Headers 60 | o.AccessControlAllowHeaders = response.GetHeader("Access-Control-Allow-Headers") 61 | 62 | // response header Access-Control-Allow-Methods 63 | o.AccessControlAllowMethods = response.GetHeader("Access-Control-Allow-Methods") 64 | 65 | // response header Access-Control-Allow-Origin 66 | o.AccessControlAllowOrigin = response.GetHeader("Access-Control-Allow-Origin") 67 | 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_leases_id_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | 11 | "github.com/go-openapi/runtime" 12 | 13 | strfmt "github.com/go-openapi/strfmt" 14 | ) 15 | 16 | // OptionsLeasesIDReader is a Reader for the OptionsLeasesID structure. 17 | type OptionsLeasesIDReader struct { 18 | formats strfmt.Registry 19 | } 20 | 21 | // ReadResponse reads a server response into the received o. 22 | func (o *OptionsLeasesIDReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 23 | switch response.Code() { 24 | case 200: 25 | result := NewOptionsLeasesIDOK() 26 | if err := result.readResponse(response, consumer, o.formats); err != nil { 27 | return nil, err 28 | } 29 | return result, nil 30 | 31 | default: 32 | return nil, runtime.NewAPIError("unknown error", response, response.Code()) 33 | } 34 | } 35 | 36 | // NewOptionsLeasesIDOK creates a OptionsLeasesIDOK with default headers values 37 | func NewOptionsLeasesIDOK() *OptionsLeasesIDOK { 38 | return &OptionsLeasesIDOK{} 39 | } 40 | 41 | /*OptionsLeasesIDOK handles this case with default header values. 42 | 43 | Default response for CORS method 44 | */ 45 | type OptionsLeasesIDOK struct { 46 | AccessControlAllowHeaders string 47 | 48 | AccessControlAllowMethods string 49 | 50 | AccessControlAllowOrigin string 51 | } 52 | 53 | func (o *OptionsLeasesIDOK) Error() string { 54 | return fmt.Sprintf("[OPTIONS /leases/{id}][%d] optionsLeasesIdOK ", 200) 55 | } 56 | 57 | func (o *OptionsLeasesIDOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 58 | 59 | // response header Access-Control-Allow-Headers 60 | o.AccessControlAllowHeaders = response.GetHeader("Access-Control-Allow-Headers") 61 | 62 | // response header Access-Control-Allow-Methods 63 | o.AccessControlAllowMethods = response.GetHeader("Access-Control-Allow-Methods") 64 | 65 | // response header Access-Control-Allow-Origin 66 | o.AccessControlAllowOrigin = response.GetHeader("Access-Control-Allow-Origin") 67 | 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_leases_auth_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | 11 | "github.com/go-openapi/runtime" 12 | 13 | strfmt "github.com/go-openapi/strfmt" 14 | ) 15 | 16 | // OptionsLeasesAuthReader is a Reader for the OptionsLeasesAuth structure. 17 | type OptionsLeasesAuthReader struct { 18 | formats strfmt.Registry 19 | } 20 | 21 | // ReadResponse reads a server response into the received o. 22 | func (o *OptionsLeasesAuthReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 23 | switch response.Code() { 24 | case 200: 25 | result := NewOptionsLeasesAuthOK() 26 | if err := result.readResponse(response, consumer, o.formats); err != nil { 27 | return nil, err 28 | } 29 | return result, nil 30 | 31 | default: 32 | return nil, runtime.NewAPIError("unknown error", response, response.Code()) 33 | } 34 | } 35 | 36 | // NewOptionsLeasesAuthOK creates a OptionsLeasesAuthOK with default headers values 37 | func NewOptionsLeasesAuthOK() *OptionsLeasesAuthOK { 38 | return &OptionsLeasesAuthOK{} 39 | } 40 | 41 | /*OptionsLeasesAuthOK handles this case with default header values. 42 | 43 | Default response for CORS method 44 | */ 45 | type OptionsLeasesAuthOK struct { 46 | AccessControlAllowHeaders string 47 | 48 | AccessControlAllowMethods string 49 | 50 | AccessControlAllowOrigin string 51 | } 52 | 53 | func (o *OptionsLeasesAuthOK) Error() string { 54 | return fmt.Sprintf("[OPTIONS /leases/auth][%d] optionsLeasesAuthOK ", 200) 55 | } 56 | 57 | func (o *OptionsLeasesAuthOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 58 | 59 | // response header Access-Control-Allow-Headers 60 | o.AccessControlAllowHeaders = response.GetHeader("Access-Control-Allow-Headers") 61 | 62 | // response header Access-Control-Allow-Methods 63 | o.AccessControlAllowMethods = response.GetHeader("Access-Control-Allow-Methods") 64 | 65 | // response header Access-Control-Allow-Origin 66 | o.AccessControlAllowOrigin = response.GetHeader("Access-Control-Allow-Origin") 67 | 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_accounts_id_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | 11 | "github.com/go-openapi/runtime" 12 | 13 | strfmt "github.com/go-openapi/strfmt" 14 | ) 15 | 16 | // OptionsAccountsIDReader is a Reader for the OptionsAccountsID structure. 17 | type OptionsAccountsIDReader struct { 18 | formats strfmt.Registry 19 | } 20 | 21 | // ReadResponse reads a server response into the received o. 22 | func (o *OptionsAccountsIDReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 23 | switch response.Code() { 24 | case 200: 25 | result := NewOptionsAccountsIDOK() 26 | if err := result.readResponse(response, consumer, o.formats); err != nil { 27 | return nil, err 28 | } 29 | return result, nil 30 | 31 | default: 32 | return nil, runtime.NewAPIError("unknown error", response, response.Code()) 33 | } 34 | } 35 | 36 | // NewOptionsAccountsIDOK creates a OptionsAccountsIDOK with default headers values 37 | func NewOptionsAccountsIDOK() *OptionsAccountsIDOK { 38 | return &OptionsAccountsIDOK{} 39 | } 40 | 41 | /*OptionsAccountsIDOK handles this case with default header values. 42 | 43 | Default response for CORS method 44 | */ 45 | type OptionsAccountsIDOK struct { 46 | AccessControlAllowHeaders string 47 | 48 | AccessControlAllowMethods string 49 | 50 | AccessControlAllowOrigin string 51 | } 52 | 53 | func (o *OptionsAccountsIDOK) Error() string { 54 | return fmt.Sprintf("[OPTIONS /accounts/{id}][%d] optionsAccountsIdOK ", 200) 55 | } 56 | 57 | func (o *OptionsAccountsIDOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 58 | 59 | // response header Access-Control-Allow-Headers 60 | o.AccessControlAllowHeaders = response.GetHeader("Access-Control-Allow-Headers") 61 | 62 | // response header Access-Control-Allow-Methods 63 | o.AccessControlAllowMethods = response.GetHeader("Access-Control-Allow-Methods") 64 | 65 | // response header Access-Control-Allow-Origin 66 | o.AccessControlAllowOrigin = response.GetHeader("Access-Control-Allow-Origin") 67 | 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /docs/dce_system_deploy.md: -------------------------------------------------------------------------------- 1 | ## dce system deploy 2 | 3 | Deploy DCE to a new master account 4 | 5 | ### Synopsis 6 | 7 | Deploy DCE to a new master account 8 | 9 | ``` 10 | dce system deploy [flags] 11 | ``` 12 | 13 | ### Options 14 | 15 | ``` 16 | -b, --batch-mode Skip prompting for resource creation. 17 | --budget-notification-bcc-emails stringArray Email address from which budget notifications will be sent 18 | --budget-notification-from-email string Email address from which budget notifications will be sent 19 | --budget-notification-template-html string HTML template for budget notification emails 20 | --budget-notification-template-subject string Subjet for budget notification emails 21 | --budget-notification-template-text string Text template for budget notification emails 22 | -d, --dce-version string Version of DCE to deploy. Defaults to v0.29.0 23 | -h, --help help for deploy 24 | --local string Path to a local DCE repo to deploy. 25 | -n, --namespace string Set a custom terraform namespace (Optional) 26 | -r, --region string The aws region that DCE will be deployed to (Default: us-east-1) 27 | --save-options If specified, saves the values provided by "--tf-init-options" and "--tf-apply-options" in the config file. 28 | -t, --tag stringArray Tags to be placed on all DCE resources. E.g. "dce system deploy --tag key1:value1 --tag key2:value2" 29 | --tf-apply-options string Options to pass to the underlying "tf apply" command. 30 | --tf-init-options string Options to pass to the underlying "tf init" command. 31 | -c, --use-cached Uses locally-cached files, if available. (default true) 32 | ``` 33 | 34 | ### Options inherited from parent commands 35 | 36 | ``` 37 | --config string config file (default is "$HOME/.dce/config.yaml") 38 | ``` 39 | 40 | ### SEE ALSO 41 | 42 | * [dce system](dce_system.md) - Deploy and configure the DCE system 43 | 44 | ###### Auto generated by spf13/cobra on 24-Apr-2020 45 | -------------------------------------------------------------------------------- /tests/unit/common.go: -------------------------------------------------------------------------------- 1 | package unit 2 | 3 | import ( 4 | "github.com/Optum/dce-cli/configs" 5 | observ "github.com/Optum/dce-cli/internal/observation" 6 | utl "github.com/Optum/dce-cli/internal/util" 7 | "github.com/Optum/dce-cli/mocks" 8 | svc "github.com/Optum/dce-cli/pkg/service" 9 | "github.com/sirupsen/logrus" 10 | ) 11 | 12 | type TestLogObservation struct { 13 | observ.LevelLogger 14 | Ended bool 15 | Msg string 16 | } 17 | 18 | func (l *TestLogObservation) Infoln(args ...interface{}) { 19 | l.Msg = args[0].(string) 20 | l.Ended = true 21 | } 22 | 23 | func (l *TestLogObservation) Endf(format string, args ...interface{}) { 24 | l.Ended = true 25 | } 26 | 27 | func (l *TestLogObservation) End(args ...interface{}) { 28 | l.Ended = true 29 | } 30 | 31 | func (l *TestLogObservation) Endln(args ...interface{}) { 32 | l.Ended = true 33 | } 34 | 35 | var mockPrompter mocks.Prompter 36 | var mockFileSystemer mocks.FileSystemer 37 | var mockWeber mocks.Weber 38 | var mockGithuber mocks.Githuber 39 | var mockAwser mocks.AWSer 40 | var mockTerraformer mocks.Terraformer 41 | var mockTFTemplater mocks.TFTemplater 42 | var mockAPIer mocks.APIer 43 | var spyLogger TestLogObservation 44 | var mockOutputWriter mocks.OutputWriter 45 | var service *svc.ServiceContainer 46 | 47 | func initMocks(config configs.Root) { 48 | mockPrompter = mocks.Prompter{} 49 | mockFileSystemer = mocks.FileSystemer{} 50 | mockWeber = mocks.Weber{} 51 | mockGithuber = mocks.Githuber{} 52 | mockAwser = mocks.AWSer{} 53 | mockTerraformer = mocks.Terraformer{} 54 | mockAPIer = mocks.APIer{} 55 | mockTFTemplater = mocks.TFTemplater{} 56 | mockOutputWriter = mocks.OutputWriter{} 57 | spyLogger = TestLogObservation{ 58 | logrus.New(), 59 | false, 60 | "", 61 | } 62 | spyObservation := observ.ObservationContainer{ 63 | Logger: &spyLogger, 64 | OutputWriter: &mockOutputWriter, 65 | } 66 | mockUtil := utl.UtilContainer{ 67 | Config: &config, 68 | Prompter: &mockPrompter, 69 | FileSystemer: &mockFileSystemer, 70 | Weber: &mockWeber, 71 | Observation: &spyObservation, 72 | Githuber: &mockGithuber, 73 | AWSer: &mockAwser, 74 | Terraformer: &mockTerraformer, 75 | APIer: &mockAPIer, 76 | TFTemplater: &mockTFTemplater, 77 | } 78 | service = svc.New(&config, &spyObservation, &mockUtil) 79 | } 80 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_leases_id_auth_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | 11 | "github.com/go-openapi/runtime" 12 | 13 | strfmt "github.com/go-openapi/strfmt" 14 | ) 15 | 16 | // OptionsLeasesIDAuthReader is a Reader for the OptionsLeasesIDAuth structure. 17 | type OptionsLeasesIDAuthReader struct { 18 | formats strfmt.Registry 19 | } 20 | 21 | // ReadResponse reads a server response into the received o. 22 | func (o *OptionsLeasesIDAuthReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 23 | switch response.Code() { 24 | case 200: 25 | result := NewOptionsLeasesIDAuthOK() 26 | if err := result.readResponse(response, consumer, o.formats); err != nil { 27 | return nil, err 28 | } 29 | return result, nil 30 | 31 | default: 32 | return nil, runtime.NewAPIError("unknown error", response, response.Code()) 33 | } 34 | } 35 | 36 | // NewOptionsLeasesIDAuthOK creates a OptionsLeasesIDAuthOK with default headers values 37 | func NewOptionsLeasesIDAuthOK() *OptionsLeasesIDAuthOK { 38 | return &OptionsLeasesIDAuthOK{} 39 | } 40 | 41 | /*OptionsLeasesIDAuthOK handles this case with default header values. 42 | 43 | Default response for CORS method 44 | */ 45 | type OptionsLeasesIDAuthOK struct { 46 | AccessControlAllowHeaders string 47 | 48 | AccessControlAllowMethods string 49 | 50 | AccessControlAllowOrigin string 51 | } 52 | 53 | func (o *OptionsLeasesIDAuthOK) Error() string { 54 | return fmt.Sprintf("[OPTIONS /leases/{id}/auth][%d] optionsLeasesIdAuthOK ", 200) 55 | } 56 | 57 | func (o *OptionsLeasesIDAuthOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 58 | 59 | // response header Access-Control-Allow-Headers 60 | o.AccessControlAllowHeaders = response.GetHeader("Access-Control-Allow-Headers") 61 | 62 | // response header Access-Control-Allow-Methods 63 | o.AccessControlAllowMethods = response.GetHeader("Access-Control-Allow-Methods") 64 | 65 | // response header Access-Control-Allow-Origin 66 | o.AccessControlAllowOrigin = response.GetHeader("Access-Control-Allow-Origin") 67 | 68 | return nil 69 | } 70 | -------------------------------------------------------------------------------- /pkg/service/accounts.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "encoding/json" 5 | "time" 6 | 7 | "github.com/Optum/dce-cli/client/operations" 8 | "github.com/Optum/dce-cli/configs" 9 | observ "github.com/Optum/dce-cli/internal/observation" 10 | utl "github.com/Optum/dce-cli/internal/util" 11 | ) 12 | 13 | type AccountsService struct { 14 | Config *configs.Root 15 | Observation *observ.ObservationContainer 16 | Util *utl.UtilContainer 17 | } 18 | 19 | func (s *AccountsService) AddAccount(accountID, adminRoleARN string) { 20 | params := &operations.PostAccountsParams{ 21 | Account: operations.PostAccountsBody{ 22 | ID: &accountID, 23 | AdminRoleArn: &adminRoleARN, 24 | }, 25 | } 26 | params.SetTimeout(5 * time.Second) 27 | _, err := ApiClient.PostAccounts(params, nil) 28 | if err != nil { 29 | log.Fatalln("err: ", err) 30 | } else { 31 | log.Infoln("Account added to DCE accounts pool") 32 | } 33 | } 34 | 35 | func (s *AccountsService) RemoveAccount(accountID string) { 36 | params := &operations.DeleteAccountsIDParams{ 37 | ID: accountID, 38 | } 39 | params.SetTimeout(5 * time.Second) 40 | _, err := ApiClient.DeleteAccountsID(params, nil) 41 | if err != nil { 42 | log.Fatalln("err: ", err) 43 | } else { 44 | log.Infoln("Account removed from DCE accounts pool") 45 | } 46 | } 47 | 48 | func (s *AccountsService) GetAccount(accountID string) { 49 | params := &operations.GetAccountsIDParams{ 50 | ID: accountID, 51 | } 52 | params.SetTimeout(5 * time.Second) 53 | res, err := ApiClient.GetAccountsID(params, nil) 54 | if err != nil { 55 | log.Fatalln("err: ", err) 56 | } 57 | jsonPayload, err := json.MarshalIndent(res.GetPayload(), "", "\t") 58 | if err != nil { 59 | log.Fatalln("err: ", err) 60 | } 61 | if _, err := Out.Write(jsonPayload); err != nil { 62 | log.Fatalln("err: ", err) 63 | } 64 | } 65 | 66 | // ListAccounts lists the accounts 67 | func (s *AccountsService) ListAccounts() { 68 | params := &operations.GetAccountsParams{} 69 | params.SetTimeout(5 * time.Second) 70 | res, err := ApiClient.GetAccounts(params, nil) 71 | if err != nil { 72 | log.Fatalln("err: ", err) 73 | } 74 | jsonPayload, err := json.MarshalIndent(res.GetPayload(), "", "\t") 75 | if err != nil { 76 | log.Fatalln("err: ", err) 77 | } 78 | if _, err := Out.Write(jsonPayload); err != nil { 79 | log.Fatalln("err: ", err) 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /client/operations/get_auth_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package operations 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | "io" 11 | 12 | "github.com/go-openapi/runtime" 13 | 14 | strfmt "github.com/go-openapi/strfmt" 15 | ) 16 | 17 | // GetAuthReader is a Reader for the GetAuth structure. 18 | type GetAuthReader struct { 19 | formats strfmt.Registry 20 | } 21 | 22 | // ReadResponse reads a server response into the received o. 23 | func (o *GetAuthReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 24 | switch response.Code() { 25 | case 200: 26 | result := NewGetAuthOK() 27 | if err := result.readResponse(response, consumer, o.formats); err != nil { 28 | return nil, err 29 | } 30 | return result, nil 31 | 32 | default: 33 | return nil, runtime.NewAPIError("unknown error", response, response.Code()) 34 | } 35 | } 36 | 37 | // NewGetAuthOK creates a GetAuthOK with default headers values 38 | func NewGetAuthOK() *GetAuthOK { 39 | return &GetAuthOK{} 40 | } 41 | 42 | /*GetAuthOK handles this case with default header values. 43 | 44 | GetAuthOK get auth o k 45 | */ 46 | type GetAuthOK struct { 47 | AccessControlAllowHeaders string 48 | 49 | AccessControlAllowMethods string 50 | 51 | AccessControlAllowOrigin string 52 | 53 | Payload interface{} 54 | } 55 | 56 | func (o *GetAuthOK) Error() string { 57 | return fmt.Sprintf("[GET /auth][%d] getAuthOK %+v", 200, o.Payload) 58 | } 59 | 60 | func (o *GetAuthOK) GetPayload() interface{} { 61 | return o.Payload 62 | } 63 | 64 | func (o *GetAuthOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 65 | 66 | // response header Access-Control-Allow-Headers 67 | o.AccessControlAllowHeaders = response.GetHeader("Access-Control-Allow-Headers") 68 | 69 | // response header Access-Control-Allow-Methods 70 | o.AccessControlAllowMethods = response.GetHeader("Access-Control-Allow-Methods") 71 | 72 | // response header Access-Control-Allow-Origin 73 | o.AccessControlAllowOrigin = response.GetHeader("Access-Control-Allow-Origin") 74 | 75 | // response payload 76 | if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF { 77 | return err 78 | } 79 | 80 | return nil 81 | } 82 | -------------------------------------------------------------------------------- /tests/unit/duration_test.go: -------------------------------------------------------------------------------- 1 | package unit 2 | 3 | import ( 4 | "strconv" 5 | "testing" 6 | "time" 7 | 8 | "github.com/stretchr/testify/assert" 9 | 10 | util "github.com/Optum/dce-cli/internal/util" 11 | ) 12 | 13 | func TestDurationUtil_ParseDuration(t *testing.T) { 14 | 15 | t.Run("Parse valid 7 days", func(t *testing.T) { 16 | 17 | now := time.Now() 18 | durUtil := util.NewDurationUtil() 19 | expectedDuration := time.Duration(7*24) * time.Hour 20 | 21 | actualDuration, err := durUtil.ParseDuration("7d") 22 | assert.Nil(t, err) 23 | assert.Equal(t, expectedDuration.Milliseconds(), actualDuration.Milliseconds()) 24 | assert.Equal(t, now.Add(actualDuration).Unix(), now.AddDate(0, 0, 7).Unix()) 25 | }) 26 | 27 | t.Run("Invalid 0 days", func(t *testing.T) { 28 | 29 | durUtil := util.NewDurationUtil() 30 | 31 | _, err := durUtil.ParseDuration("0d") 32 | assert.NotNil(t, err) 33 | assert.Equal(t, "invalid zero or negative date: 0", err.Error()) 34 | }) 35 | 36 | t.Run("Valid for 8 hours", func(t *testing.T) { 37 | 38 | now := time.Now() 39 | durUtil := util.NewDurationUtil() 40 | expectedDuration := time.Duration(8) * time.Hour 41 | 42 | actualDuration, err := durUtil.ParseDuration("8h") 43 | assert.Nil(t, err) 44 | assert.Equal(t, expectedDuration.Milliseconds(), actualDuration.Milliseconds()) 45 | assert.Equal(t, now.Add(actualDuration).Unix(), now.Add(time.Hour*8).Unix()) 46 | }) 47 | 48 | } 49 | 50 | func TestDurationUtil_ExpandEpochTime(t *testing.T) { 51 | 52 | durUtil := util.NewDurationUtil() 53 | 54 | t.Run("Expand epoch time", func(t *testing.T) { 55 | sevenDaysFromNow := time.Now().AddDate(0, 0, 7) 56 | epochAsString := strconv.FormatInt(sevenDaysFromNow.Unix(), 10) 57 | 58 | actualTime, err := durUtil.ExpandEpochTime(epochAsString) 59 | assert.Nil(t, err) 60 | assert.Equal(t, sevenDaysFromNow.Unix(), actualTime) 61 | }) 62 | 63 | t.Run("Expand string", func(t *testing.T) { 64 | sevenDaysFromNow := time.Now().AddDate(0, 0, 7) 65 | sevenDaysAsString := "7d" 66 | 67 | actualTime, err := durUtil.ExpandEpochTime(sevenDaysAsString) 68 | assert.Nil(t, err) 69 | assert.Equal(t, sevenDaysFromNow.Unix(), actualTime) 70 | }) 71 | 72 | t.Run("Bad input", func(t *testing.T) { 73 | sevenDaysAsString := "thisisbad" 74 | 75 | _, err := durUtil.ExpandEpochTime(sevenDaysAsString) 76 | assert.NotNil(t, err) 77 | assert.Equal(t, "invalid duration format: thisisbad", err.Error()) 78 | }) 79 | 80 | } 81 | -------------------------------------------------------------------------------- /internal/util/duration.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "fmt" 5 | "regexp" 6 | "strconv" 7 | "time" 8 | ) 9 | 10 | // DurationUtil has the 11 | type DurationUtil struct { 12 | DayFormatExp *regexp.Regexp 13 | TimeUnitFormatExp *regexp.Regexp 14 | } 15 | 16 | const ( 17 | EmptyDuration time.Duration = time.Duration(0) 18 | ) 19 | 20 | // ExpandEpochTime "expands" the given time from a string. If it is an int64, it assumes the time 21 | // is a UNIX epoch time and is "absolute" and so refers the time. If it is a string, it assumes 22 | // the time is "relative" to now and returns the UNIX epoch time with the duration added. 23 | func (d *DurationUtil) ExpandEpochTime(str string) (int64, error) { 24 | // if the incoming time can be used as a number, assume it's an "absolute" time 25 | epoch, err := strconv.ParseInt(str, 10, 64) 26 | if err == nil { 27 | return epoch, nil 28 | } 29 | 30 | // if it's a string, assume that it's "relative" to now, so return that... 31 | duration, err := d.ParseDuration(str) 32 | 33 | if err != nil { 34 | return 0, err 35 | } 36 | 37 | return time.Now().Add(duration).Unix(), nil 38 | 39 | } 40 | 41 | // ParseDuration accepts a string to parse and return a `time.Duration`. 42 | // This is used because the default time.Duration in go only supports up 43 | // to the hour, and for lease expirations we want to support days, 44 | func (d *DurationUtil) ParseDuration(str string) (time.Duration, error) { 45 | 46 | if d.TimeUnitFormatExp.Match([]byte(str)) { 47 | // use the default time.Duration behavior 48 | dur, err := time.ParseDuration(str) 49 | return dur, err 50 | } 51 | 52 | // calc for days.. 53 | if d.DayFormatExp.Match([]byte(str)) { 54 | matches := d.DayFormatExp.FindStringSubmatch(str) 55 | day, err := strconv.Atoi(matches[1]) 56 | if err != nil { 57 | return EmptyDuration, err 58 | } 59 | if day <= 0 { 60 | // Well, that's just silly... 61 | return EmptyDuration, fmt.Errorf("invalid zero or negative date: %d", day) 62 | } 63 | dur := time.Duration(day*24) * time.Hour 64 | return dur, nil 65 | } 66 | 67 | return EmptyDuration, fmt.Errorf("invalid duration format: %s", str) 68 | } 69 | 70 | // NewDurationUtil creates a new `DuractionUtil` 71 | func NewDurationUtil() *DurationUtil { 72 | durationUtil := &DurationUtil{ 73 | DayFormatExp: regexp.MustCompile(`([\d]+)(\s*)(?:d)`), 74 | TimeUnitFormatExp: regexp.MustCompile(`[\d]+(ns|us|ms|s|m|h)`), 75 | } 76 | 77 | return durationUtil 78 | } 79 | -------------------------------------------------------------------------------- /client/operations/get_auth_file_responses.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package operations 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "fmt" 10 | "io" 11 | 12 | "github.com/go-openapi/runtime" 13 | 14 | strfmt "github.com/go-openapi/strfmt" 15 | ) 16 | 17 | // GetAuthFileReader is a Reader for the GetAuthFile structure. 18 | type GetAuthFileReader struct { 19 | formats strfmt.Registry 20 | } 21 | 22 | // ReadResponse reads a server response into the received o. 23 | func (o *GetAuthFileReader) ReadResponse(response runtime.ClientResponse, consumer runtime.Consumer) (interface{}, error) { 24 | switch response.Code() { 25 | case 200: 26 | result := NewGetAuthFileOK() 27 | if err := result.readResponse(response, consumer, o.formats); err != nil { 28 | return nil, err 29 | } 30 | return result, nil 31 | 32 | default: 33 | return nil, runtime.NewAPIError("unknown error", response, response.Code()) 34 | } 35 | } 36 | 37 | // NewGetAuthFileOK creates a GetAuthFileOK with default headers values 38 | func NewGetAuthFileOK() *GetAuthFileOK { 39 | return &GetAuthFileOK{} 40 | } 41 | 42 | /*GetAuthFileOK handles this case with default header values. 43 | 44 | GetAuthFileOK get auth file o k 45 | */ 46 | type GetAuthFileOK struct { 47 | AccessControlAllowHeaders string 48 | 49 | AccessControlAllowMethods string 50 | 51 | AccessControlAllowOrigin string 52 | 53 | Payload interface{} 54 | } 55 | 56 | func (o *GetAuthFileOK) Error() string { 57 | return fmt.Sprintf("[GET /auth/{file+}][%d] getAuthFileOK %+v", 200, o.Payload) 58 | } 59 | 60 | func (o *GetAuthFileOK) GetPayload() interface{} { 61 | return o.Payload 62 | } 63 | 64 | func (o *GetAuthFileOK) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { 65 | 66 | // response header Access-Control-Allow-Headers 67 | o.AccessControlAllowHeaders = response.GetHeader("Access-Control-Allow-Headers") 68 | 69 | // response header Access-Control-Allow-Methods 70 | o.AccessControlAllowMethods = response.GetHeader("Access-Control-Allow-Methods") 71 | 72 | // response header Access-Control-Allow-Origin 73 | o.AccessControlAllowOrigin = response.GetHeader("Access-Control-Allow-Origin") 74 | 75 | // response payload 76 | if err := consumer.Consume(response.Body(), &o.Payload); err != nil && err != io.EOF { 77 | return err 78 | } 79 | 80 | return nil 81 | } 82 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/Optum/dce-cli 2 | 3 | go 1.13 4 | 5 | // Two bugs arise during the normal build. The first is the ambiguous import error shown here... 6 | // 7 | // cannot load github.com/ugorji/go/codec: ambiguous import: found github.com/ugorji/go/codec in multiple modules: 8 | // github.com/ugorji/go v1.1.4 (/go/pkg/mod/github.com/ugorji/go@v1.1.4/codec) 9 | // github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8 (/go/pkg/mod/github.com/ugorji/go/codec@v0.0.0-20181204163529-d75b2dcb6bc8) 10 | // 11 | // ...which can be fixed by replacing the first module with the second, as suggested in https://github.com/gin-gonic/gin/issues/1673#issuecomment-502203637 12 | // The following error manifests after fixing the first bug... 13 | // 14 | // panic: codecgen version mismatch: current: 8, need 10. Re-generate file: /go/pkg/mod/github.com/coreos/etcd@v3.3.10+incompatible/client/keys.generated.go 15 | // 16 | // ...which can be overcome by deleting the indicated file and rebuilding, as suggested in the panic itself and here https://github.com/spf13/viper/issues/644#issuecomment-466287597 17 | 18 | replace github.com/ugorji/go v1.1.4 => github.com/ugorji/go v0.0.0-20181204163529-d75b2dcb6bc8 19 | 20 | require ( 21 | github.com/aws/aws-sdk-go v1.25.16 22 | github.com/chzyer/logex v1.1.10 // indirect 23 | github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e 24 | github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 // indirect 25 | github.com/dsnet/compress v0.0.1 // indirect 26 | github.com/frankban/quicktest v1.7.0 // indirect 27 | github.com/go-openapi/errors v0.19.2 28 | github.com/go-openapi/runtime v0.19.7 29 | github.com/go-openapi/strfmt v0.19.3 30 | github.com/go-openapi/swag v0.19.5 31 | github.com/go-openapi/validate v0.19.3 32 | github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect 33 | github.com/mholt/archiver v3.1.1+incompatible 34 | github.com/mitchellh/go-homedir v1.1.0 35 | github.com/nwaples/rardecode v1.0.0 // indirect 36 | github.com/pierrec/lz4 v2.3.0+incompatible // indirect 37 | github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 38 | github.com/pkg/errors v0.8.0 39 | github.com/sirupsen/logrus v1.2.0 40 | github.com/spf13/cobra v0.0.5 41 | github.com/stretchr/testify v1.4.0 42 | github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect 43 | go.uber.org/thriftrw v1.20.2 44 | golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect 45 | golang.org/x/sys v0.0.0-20190804053845-51ab0e2deafa // indirect 46 | gopkg.in/yaml.v2 v2.2.4 47 | ) 48 | -------------------------------------------------------------------------------- /tests/unit/tftemplate_test.go: -------------------------------------------------------------------------------- 1 | package unit 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io/ioutil" 7 | "testing" 8 | 9 | util "github.com/Optum/dce-cli/internal/util" 10 | "github.com/stretchr/testify/assert" 11 | ) 12 | 13 | func TestMainTFTemplate_MissingRequiredValues(t *testing.T) { 14 | 15 | var actual bytes.Buffer 16 | var err error 17 | 18 | mockFS := &mockFileSystemer 19 | mockFS.On("GetCacheDir").Return("/Users/jexmple/.dce") 20 | mockFS.On("GetTerraformStateFile").Return("/Users/jexmple/.dce/terraform.tfstate") 21 | tf := util.NewMainTFTemplate(mockFS) 22 | tf.TFWorkspaceDir = "" 23 | 24 | err = tf.AddVariable("namespace", "string", "dcecliut") 25 | assert.Nil(t, err, "should have been able to add valid namespace") 26 | // Try to write without the required TFWorkspaceDir 27 | err = tf.Write(&actual) 28 | assert.NotNil(t, err) 29 | assert.Equal(t, "non-zero length value required for workspace dir", err.Error()) 30 | 31 | tf.TFWorkspaceDir = "/Users/jexmple/.dce/tf-workspace" 32 | tf.LocalTFStateFilePath = "" 33 | // Set it, but now try to write without the required LocalTFStateFilePath 34 | err = tf.Write(&actual) 35 | assert.NotNil(t, err) 36 | assert.Equal(t, "non-zero length value required for local tf state file path", err.Error()) 37 | 38 | } 39 | 40 | // TestMainTFTemplate_Write tests the `Write` happy path 41 | func TestMainTFTemplate_Write(t *testing.T) { 42 | 43 | var actual bytes.Buffer 44 | 45 | expected, err := ioutil.ReadFile("examples/maintf-basic.example") 46 | 47 | assert.Nil(t, err, "should have been able to read from file") 48 | 49 | mockFS := &mockFileSystemer 50 | mockFS.On("GetCacheDir").Return("/Users/jexmple/.dce") 51 | mockFS.On("GetTerraformStateFile").Return("/Users/jexmple/.dce/terraform.tfstate") 52 | tf := util.NewMainTFTemplate(mockFS) 53 | tf.LocalTFStateFilePath = "/Users/jexmple/.dce/terraform.tfstate" 54 | tf.TFWorkspaceDir = "/Users/jexmple/.dce/tf-workspace" 55 | 56 | err = tf.AddVariable("namespace", "string", "dcecliut") 57 | assert.Nil(t, err, "should have been able to add valid namespace") 58 | 59 | err = tf.AddVariable("budget_notification_from_email", "string", "noreply@example.com") 60 | assert.Nil(t, err, "should have been able to add valid budget_notification_from_email") 61 | 62 | tf.SetModuleSource("github.com/Optum/dce//modules?ref=v0.23.0") 63 | 64 | err = tf.Write(&actual) 65 | assert.Nil(t, err) 66 | assert.Equal(t, string(expected), actual.String(), fmt.Sprintf("templates should have same content: \"%s\" vs. \"%s\"", string(expected), actual.String())) 67 | 68 | } 69 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Disposable Cloud EnvironmentTM CLI 2 | > **DCETM is your playground in the cloud** 3 | 4 | This is the CLI for [DCE](https://github.com/Optum/dce). For usage information, view the complete [command reference](./docs/dce.md). 5 | 6 | Disposable Cloud Environment (DCE) manages ephemeral AWS accounts for easy and secure access to the cloud. 7 | 8 | DCE users can "lease" an AWS account for a defined period of time and with a limited budget. 9 | 10 | At the end of the lease, or if the lease's budget is reached, the account is wiped clean and returned to the account pool so it may be leased again. 11 | 12 | ## Getting Started & Documentation 13 | 14 | Documentation coming soon. 15 | 16 | # Feature Availability 17 | 18 | | Feature | *nix | Windows | Notes | 19 | | ----------- | ----------- | ----------- | ----------- | 20 | | Deployment (`dce system deploy`) | Available | [Unavailable](https://github.com/Optum/dce-cli/issues/21) | | 21 | | CLI Initialization (`dce init`) | Available | Available | | 22 | | Authentication (`dce auth`) | Available | Available | [Unavailable on Firefox](https://github.com/Optum/dce/issues/166) | 23 | | Account Management (`dce accounts ...`) | Available | Available | | 24 | | Lease Management (`dce leases ...`) | Available | Available | | 25 | | Usage (`dce usage ...`) | Available | Available | | 26 | 27 | # Logging 28 | 29 | To change the logging level of the DCE CLI, set the DCE_LOG_LEVEL environment variable to `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `FATAL`, or `PANIC`. When the log level is `INFO`, only un-prefixed log message will be output. This is the default behavior. 30 | 31 | ## Contributing to DCE 32 | 33 | DCE was born at Optum, but belongs to the community. Improve your cloud experience and [open a PR](https://github.com/Optum/dce-cli/pulls). 34 | 35 | [Contributor Guidelines](./CONTRIBUTING.md) 36 | -------------------------------------------------------------------------------- /models/lease_status_reason.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package models 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "encoding/json" 10 | 11 | "github.com/go-openapi/errors" 12 | strfmt "github.com/go-openapi/strfmt" 13 | "github.com/go-openapi/validate" 14 | ) 15 | 16 | // LeaseStatusReason A reason behind the lease status. 17 | // "LeaseExpired": The lease exceeded its expiration time ("expiresOn") and 18 | // the associated account was reset and returned to the account pool. 19 | // "LeaseOverBudget": The lease exceeded its budgeted amount and the 20 | // associated account was reset and returned to the account pool. 21 | // "LeaseDestroyed": The lease was adminstratively ended, which can be done 22 | // via the leases API. 23 | // "LeaseActive": The lease is active. 24 | // "LeaseRolledBack": A system error occurred while provisioning the lease. 25 | // and it was rolled back. 26 | // 27 | // swagger:model leaseStatusReason 28 | type LeaseStatusReason string 29 | 30 | const ( 31 | 32 | // LeaseStatusReasonLeaseExpired captures enum value "LeaseExpired" 33 | LeaseStatusReasonLeaseExpired LeaseStatusReason = "LeaseExpired" 34 | 35 | // LeaseStatusReasonLeaseOverBudget captures enum value "LeaseOverBudget" 36 | LeaseStatusReasonLeaseOverBudget LeaseStatusReason = "LeaseOverBudget" 37 | 38 | // LeaseStatusReasonLeaseDestroyed captures enum value "LeaseDestroyed" 39 | LeaseStatusReasonLeaseDestroyed LeaseStatusReason = "LeaseDestroyed" 40 | 41 | // LeaseStatusReasonLeaseActive captures enum value "LeaseActive" 42 | LeaseStatusReasonLeaseActive LeaseStatusReason = "LeaseActive" 43 | 44 | // LeaseStatusReasonLeaseRolledBack captures enum value "LeaseRolledBack" 45 | LeaseStatusReasonLeaseRolledBack LeaseStatusReason = "LeaseRolledBack" 46 | ) 47 | 48 | // for schema 49 | var leaseStatusReasonEnum []interface{} 50 | 51 | func init() { 52 | var res []LeaseStatusReason 53 | if err := json.Unmarshal([]byte(`["LeaseExpired","LeaseOverBudget","LeaseDestroyed","LeaseActive","LeaseRolledBack"]`), &res); err != nil { 54 | panic(err) 55 | } 56 | for _, v := range res { 57 | leaseStatusReasonEnum = append(leaseStatusReasonEnum, v) 58 | } 59 | } 60 | 61 | func (m LeaseStatusReason) validateLeaseStatusReasonEnum(path, location string, value LeaseStatusReason) error { 62 | if err := validate.Enum(path, location, value, leaseStatusReasonEnum); err != nil { 63 | return err 64 | } 65 | return nil 66 | } 67 | 68 | // Validate validates this lease status reason 69 | func (m LeaseStatusReason) Validate(formats strfmt.Registry) error { 70 | var res []error 71 | 72 | // value enum 73 | if err := m.validateLeaseStatusReasonEnum("", "body", m); err != nil { 74 | return err 75 | } 76 | 77 | if len(res) > 0 { 78 | return errors.CompositeValidationError(res...) 79 | } 80 | return nil 81 | } 82 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## vNext 2 | 3 | - Fix bug causing prompts to repeatedly echo input of large strings 4 | - dce leases end command can now accept leaseID 5 | 6 | ## v0.5.0 7 | 8 | - **Potential breaking change**: Updated commands to output logging messages to STDERR, while JSON 9 | and other output goes to STDOUT 10 | - Added `version` command to support viewing the current release version of the running binary 11 | - Add `dce leases login` command (without Lease ID) 12 | - Allow DCE version used by `dce system deploy` to be configured as CLI flag, in YAML config, or as env var 13 | - Accept YAML configuration and env vars for `dce system deploy` params for namespace and budget notification emails. 14 | - Fix bug where modified configuration values used by `dce system deploy` would not be reflected in the terraform deployment 15 | - Fix pre-run credentials check: was accepting expired credentials. 16 | - Fix parsing of `--expires-on` flag for `dce leases create` command 17 | - Upgraded the default backend DCE version from 0.23.0 to 0.29.0 18 | 19 | ## v0.4.0 20 | - Added `--tf-init-options` and `--tf-apply-options` for greater control over underlying provisioner 21 | - Added `--save-options` flag to persist the `--tf-init-options` and `--tf-apply-options` to the 22 | configuration file when specified. Default behavior is false. 23 | - Persist API host name and path after running `system deploy` 24 | - **Potential breaking change**: explicitly configured logging output to go to STDOUT; command output should go to STDOUT 25 | 26 | ## v0.3.1 27 | 28 | - **BREAKING CHANGE:** Move `~/.dce.yaml` file location to `~/.dce/config.yaml` 29 | - Use local terraform backend by default; located in `~/.dce/.cache/module/main.tf` 30 | - Use terraform binary directly, downloaded to `~/.dce/.cache/terraform/${terraform_version}/` folder. 31 | - Output from terraform now redirected to `~/.dce/deploy.log` 32 | - Moved quick start to readthedocs 33 | - Download deployment assets from the public url rather than using Github's GraphQL API 34 | - Added `--noprompt` flag for easier scripting 35 | 36 | **Migration Notes** 37 | 38 | dce-cli v0.3.1 introduces a breaking change, in that it expects your yaml configuration to be located at `~/.dce/config.yaml`, instead of `~/.dce.yaml`. If you are migrating from v0.3.0 or lower, you will need to manually move your existing config file to the new location before running any dce-cli commands. 39 | 40 | If you do not have an existing config file at `~/.dce.yaml`, you should be able to upgrade to v0.3.1 without problem. 41 | 42 | ## v0.3.0 43 | - Modified dce auth command to prompt for input and accept base64 encoded credentials string 44 | - Added cognito auth documentation to quickstart 45 | 46 | ## v0.2.0 47 | 48 | **BREAKING CHANGES** 49 | - Fix `--principle-id` flag to be `principal-id` 50 | - Remove MasterAccountCreds from dce.yml. Use default AWS CLI creds instead 51 | - Indent JSON output from CLI commands 52 | 53 | ## v0.1.0 54 | 55 | Initial release 56 | -------------------------------------------------------------------------------- /pkg/service/service.go: -------------------------------------------------------------------------------- 1 | package service 2 | 3 | import ( 4 | "github.com/Optum/dce-cli/configs" 5 | observ "github.com/Optum/dce-cli/internal/observation" 6 | utl "github.com/Optum/dce-cli/internal/util" 7 | ) 8 | 9 | // ServiceContainer is a service that injects its config and util into other services 10 | type ServiceContainer struct { 11 | Config *configs.Root 12 | Observation *observ.ObservationContainer 13 | Util *utl.UtilContainer 14 | Deployer 15 | Accounter 16 | Leaser 17 | Initer 18 | Authenticater 19 | Usager 20 | } 21 | 22 | var log observ.Logger 23 | var ApiClient utl.APIer 24 | var Out observ.OutputWriter 25 | 26 | // New returns a new ServiceContainer given config 27 | func New(config *configs.Root, observation *observ.ObservationContainer, util *utl.UtilContainer) *ServiceContainer { 28 | 29 | log = observation.Logger 30 | ApiClient = util.APIer 31 | Out = observation.OutputWriter 32 | 33 | serviceContainer := ServiceContainer{ 34 | Config: config, 35 | Observation: observation, 36 | Util: util, 37 | Deployer: &DeployService{Config: config, Util: util}, 38 | Accounter: &AccountsService{Config: config, Util: util}, 39 | Leaser: &LeasesService{Config: config, Util: util}, 40 | Initer: &InitService{Config: config, Util: util}, 41 | Authenticater: &AuthService{Config: config, Util: util}, 42 | Usager: &UsageService{Config: config, Util: util}, 43 | } 44 | 45 | return &serviceContainer 46 | } 47 | 48 | type DeployOverrides struct { 49 | AWSRegion string 50 | GlobalTags []string 51 | Namespace string 52 | BudgetNotificationFromEmail string 53 | BudgetNotificationBCCEmails []string 54 | BudgetNotificationTemplateHTML string 55 | BudgetNotificationTemplateText string 56 | BudgetNotificationTemplateSubject string 57 | DCEVersion string 58 | // Location of the DCE terraform module 59 | DCEModulePath string 60 | } 61 | type Deployer interface { 62 | Deploy(input *DeployConfig) error 63 | PostDeploy(input *DeployConfig) error 64 | } 65 | 66 | type Usager interface { 67 | GetUsage(startDate, endDate float64) 68 | } 69 | 70 | type Accounter interface { 71 | AddAccount(accountID, adminRoleARN string) 72 | RemoveAccount(accountID string) 73 | GetAccount(accountID string) 74 | ListAccounts() 75 | } 76 | 77 | type LeaseLoginOptions struct { 78 | CliProfile string 79 | OpenBrowser bool 80 | PrintCreds bool 81 | } 82 | 83 | type Leaser interface { 84 | CreateLease(principalID string, budgetAmount float64, budgetCurrency string, email []string, expiresOn string) 85 | EndLease(leaseID, accountID, principalID string) 86 | LoginByID(leaseID string, opts *LeaseLoginOptions) 87 | Login(opts *LeaseLoginOptions) 88 | ListLeases(acctID, principalID, nextAcctID, nextPrincipalID, leaseStatus string, pagLimit int64) 89 | GetLease(leaseID string) 90 | } 91 | 92 | type Initer interface { 93 | InitializeDCE() 94 | } 95 | 96 | type Authenticater interface { 97 | Authenticate() error 98 | } 99 | -------------------------------------------------------------------------------- /internal/util/api.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "bytes" 5 | "io/ioutil" 6 | "time" 7 | 8 | apiclient "github.com/Optum/dce-cli/client" 9 | "github.com/Optum/dce-cli/client/operations" 10 | "github.com/Optum/dce-cli/internal/observation" 11 | "github.com/aws/aws-sdk-go/aws/credentials" 12 | sigv4 "github.com/aws/aws-sdk-go/aws/signer/v4" 13 | httptransport "github.com/go-openapi/runtime/client" 14 | "github.com/go-openapi/strfmt" 15 | 16 | "net/http" 17 | "net/http/httputil" 18 | ) 19 | 20 | type NewAPIClientInput struct { 21 | credentials *credentials.Credentials 22 | region *string 23 | host *string 24 | basePath *string 25 | token *string 26 | } 27 | 28 | func NewAPIClient(input *NewAPIClientInput) *operations.Client { 29 | // Set default region 30 | var region string 31 | if input.region == nil { 32 | log.Infof("No region configured. Defaulting to us-east-1") 33 | region = "us-east-1" 34 | } else { 35 | region = *input.region 36 | } 37 | 38 | sig4RoundTripper := Sig4RoundTripper{ 39 | Proxied: http.DefaultTransport, 40 | Creds: input.credentials, 41 | Region: region, 42 | Logger: log, 43 | } 44 | sig4HTTTPClient := http.Client{Transport: &sig4RoundTripper} 45 | httpTransport := httptransport.NewWithClient( 46 | *input.host, 47 | *input.basePath, 48 | nil, 49 | &sig4HTTTPClient, 50 | ) 51 | client := apiclient.New(httpTransport, strfmt.Default) 52 | return client.Operations.(*operations.Client) 53 | } 54 | 55 | // Adapted from https://stackoverflow.com/questions/39527847/is-there-middleware-for-go-http-client 56 | type Sig4RoundTripper struct { 57 | Proxied http.RoundTripper 58 | Creds *credentials.Credentials 59 | Region string 60 | Logger observation.Logger 61 | } 62 | 63 | func (srt Sig4RoundTripper) RoundTrip(req *http.Request) (res *http.Response, e error) { 64 | log := srt.Logger 65 | dumpedReq, err := httputil.DumpRequest(req, true) 66 | if err != nil { 67 | srt.Logger.Fatalf(err.Error()) 68 | } 69 | log.Debugln("V4 Signing Request:\n", string(dumpedReq)) 70 | 71 | signer := sigv4.NewSigner(srt.Creds) 72 | now := time.Now().Add(time.Duration(30) * time.Second) 73 | 74 | // If there's a json provided, add it when signing 75 | // Body does not matter if added before the signing, it will be overwritten 76 | 77 | executeAPI := "execute-api" 78 | if req.Body != nil { 79 | body, err := ioutil.ReadAll(req.Body) 80 | if err != nil { 81 | log.Fatalln("Error reading payload for v4 signing. ", err) 82 | } 83 | 84 | req.Header.Set("Content-Type", "application/json") 85 | _, err = signer.Sign(req, bytes.NewReader(body), executeAPI, srt.Region, now) 86 | if err != nil { 87 | log.Fatalln("Error v4 signing payload. ", err) 88 | } 89 | } else { 90 | _, err := signer.Sign(req, nil, 91 | executeAPI, srt.Region, now) 92 | if err != nil { 93 | log.Fatalln("Error while v4 signing request. ", err) 94 | } 95 | } 96 | 97 | res, e = srt.Proxied.RoundTrip(req) 98 | 99 | log.Debugln("Response: ", res) 100 | return res, e 101 | } 102 | -------------------------------------------------------------------------------- /internal/util/session.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "encoding/base64" 5 | "encoding/json" 6 | "errors" 7 | "time" 8 | 9 | "github.com/aws/aws-sdk-go/aws" 10 | "github.com/aws/aws-sdk-go/aws/session" 11 | 12 | "github.com/aws/aws-sdk-go/aws/credentials" 13 | ) 14 | 15 | func NewAWSSession(token *string) (*session.Session, error) { 16 | // Setup the AWS credentials provider chain. 17 | // First, we'll check for credentials in the 18 | // configuration file's `api.token` config. 19 | // then we'll use AWS's standard chain (env vars, ~/aws/credentials file) 20 | creds := credentials.NewChainCredentials([]credentials.Provider{ 21 | NewAPITokenProvider(token), 22 | &credentials.EnvProvider{}, 23 | &credentials.SharedCredentialsProvider{}, 24 | }) 25 | return session.NewSession(&aws.Config{ 26 | Credentials: creds, 27 | }) 28 | } 29 | 30 | // APITokenProvider is a custom AWS Credentials provider 31 | // which uses a base64 encoded token containing a STS credentials as JSON 32 | // See https://docs.aws.amazon.com/sdk-for-go/api/aws/credentials/#hdr-Custom_Provider 33 | // 34 | // Using a custom Provider does a few things for us: 35 | // - Allows chaining credentials, so we can fall back to env vars, creds fil 36 | // - The `Retrieve` method is cached by the client, so we don't need to re-parse our API token at every call 37 | // - Provides a mechanism for handling expired creds 38 | type APITokenProvider struct { 39 | token *string 40 | expiration int64 41 | } 42 | 43 | const APITokenProviderName = "APITokenProvider" 44 | 45 | func NewAPITokenProvider(token *string) credentials.Provider { 46 | return &APITokenProvider{ 47 | token: token, 48 | } 49 | } 50 | 51 | func (t *APITokenProvider) Retrieve() (credentials.Value, error) { 52 | if t.token == nil { 53 | return credentials.Value{ProviderName: APITokenProviderName}, 54 | errors.New("no API token is configured") 55 | } 56 | 57 | stsTokenJSON, err := base64.StdEncoding.DecodeString(*t.token) 58 | if err != nil { 59 | return credentials.Value{ProviderName: APITokenProviderName}, 60 | errors.New("failed to decode token") 61 | } 62 | 63 | // Unmarshal the STS Token JSON 64 | var tokenValue APITokenValue 65 | err = json.Unmarshal(stsTokenJSON, &tokenValue) 66 | if err != nil { 67 | return credentials.Value{ProviderName: APITokenProviderName}, 68 | errors.New("decoded token contains invalid JSON") 69 | } 70 | 71 | // Remember the tokens `expired` time, 72 | // so we can implement `IsExpired` 73 | t.expiration = tokenValue.Expiration 74 | 75 | if t.IsExpired() { 76 | return credentials.Value{ProviderName: APITokenProviderName}, 77 | errors.New("token is expired") 78 | } 79 | 80 | return credentials.Value{ 81 | AccessKeyID: tokenValue.AccessKeyID, 82 | SecretAccessKey: tokenValue.SecretAccessKey, 83 | SessionToken: tokenValue.SessionToken, 84 | ProviderName: APITokenProviderName, 85 | }, nil 86 | } 87 | 88 | func (t *APITokenProvider) IsExpired() bool { 89 | return time.Now().Unix() > t.expiration 90 | } 91 | 92 | type APITokenValue struct { 93 | AccessKeyID string `json:"accessKeyId"` 94 | SecretAccessKey string `json:"secretAccessKey"` 95 | SessionToken string `json:"sessionToken"` 96 | Expiration int64 `json:"expireTime"` 97 | } 98 | -------------------------------------------------------------------------------- /mocks/TerraformBinFileSystemUtil.go: -------------------------------------------------------------------------------- 1 | // Code generated by mockery v1.0.0. DO NOT EDIT. 2 | 3 | package mocks 4 | 5 | import mock "github.com/stretchr/testify/mock" 6 | import os "os" 7 | 8 | // TerraformBinFileSystemUtil is an autogenerated mock type for the TerraformBinFileSystemUtil type 9 | type TerraformBinFileSystemUtil struct { 10 | mock.Mock 11 | } 12 | 13 | // GetConfigDir provides a mock function with given fields: 14 | func (_m *TerraformBinFileSystemUtil) GetConfigDir() string { 15 | ret := _m.Called() 16 | 17 | var r0 string 18 | if rf, ok := ret.Get(0).(func() string); ok { 19 | r0 = rf() 20 | } else { 21 | r0 = ret.Get(0).(string) 22 | } 23 | 24 | return r0 25 | } 26 | 27 | // GetLocalTFModuleDir provides a mock function with given fields: 28 | func (_m *TerraformBinFileSystemUtil) GetLocalTFModuleDir() string { 29 | ret := _m.Called() 30 | 31 | var r0 string 32 | if rf, ok := ret.Get(0).(func() string); ok { 33 | r0 = rf() 34 | } else { 35 | r0 = ret.Get(0).(string) 36 | } 37 | 38 | return r0 39 | } 40 | 41 | // GetTerraformBin provides a mock function with given fields: 42 | func (_m *TerraformBinFileSystemUtil) GetTerraformBin() string { 43 | ret := _m.Called() 44 | 45 | var r0 string 46 | if rf, ok := ret.Get(0).(func() string); ok { 47 | r0 = rf() 48 | } else { 49 | r0 = ret.Get(0).(string) 50 | } 51 | 52 | return r0 53 | } 54 | 55 | // GetTerraformBinDir provides a mock function with given fields: 56 | func (_m *TerraformBinFileSystemUtil) GetTerraformBinDir() string { 57 | ret := _m.Called() 58 | 59 | var r0 string 60 | if rf, ok := ret.Get(0).(func() string); ok { 61 | r0 = rf() 62 | } else { 63 | r0 = ret.Get(0).(string) 64 | } 65 | 66 | return r0 67 | } 68 | 69 | // IsExistingFile provides a mock function with given fields: path 70 | func (_m *TerraformBinFileSystemUtil) IsExistingFile(path string) bool { 71 | ret := _m.Called(path) 72 | 73 | var r0 bool 74 | if rf, ok := ret.Get(0).(func(string) bool); ok { 75 | r0 = rf(path) 76 | } else { 77 | r0 = ret.Get(0).(bool) 78 | } 79 | 80 | return r0 81 | } 82 | 83 | // OpenFileWriter provides a mock function with given fields: path 84 | func (_m *TerraformBinFileSystemUtil) OpenFileWriter(path string) (*os.File, error) { 85 | ret := _m.Called(path) 86 | 87 | var r0 *os.File 88 | if rf, ok := ret.Get(0).(func(string) *os.File); ok { 89 | r0 = rf(path) 90 | } else { 91 | if ret.Get(0) != nil { 92 | r0 = ret.Get(0).(*os.File) 93 | } 94 | } 95 | 96 | var r1 error 97 | if rf, ok := ret.Get(1).(func(string) error); ok { 98 | r1 = rf(path) 99 | } else { 100 | r1 = ret.Error(1) 101 | } 102 | 103 | return r0, r1 104 | } 105 | 106 | // RemoveAll provides a mock function with given fields: path 107 | func (_m *TerraformBinFileSystemUtil) RemoveAll(path string) { 108 | _m.Called(path) 109 | } 110 | 111 | // Unarchive provides a mock function with given fields: source, destination 112 | func (_m *TerraformBinFileSystemUtil) Unarchive(source string, destination string) error { 113 | ret := _m.Called(source, destination) 114 | 115 | var r0 error 116 | if rf, ok := ret.Get(0).(func(string, string) error); ok { 117 | r0 = rf(source, destination) 118 | } else { 119 | r0 = ret.Error(0) 120 | } 121 | 122 | return r0 123 | } 124 | -------------------------------------------------------------------------------- /client/operations/get_auth_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package operations 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | 17 | strfmt "github.com/go-openapi/strfmt" 18 | ) 19 | 20 | // NewGetAuthParams creates a new GetAuthParams object 21 | // with the default values initialized. 22 | func NewGetAuthParams() *GetAuthParams { 23 | 24 | return &GetAuthParams{ 25 | 26 | timeout: cr.DefaultTimeout, 27 | } 28 | } 29 | 30 | // NewGetAuthParamsWithTimeout creates a new GetAuthParams object 31 | // with the default values initialized, and the ability to set a timeout on a request 32 | func NewGetAuthParamsWithTimeout(timeout time.Duration) *GetAuthParams { 33 | 34 | return &GetAuthParams{ 35 | 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewGetAuthParamsWithContext creates a new GetAuthParams object 41 | // with the default values initialized, and the ability to set a context for a request 42 | func NewGetAuthParamsWithContext(ctx context.Context) *GetAuthParams { 43 | 44 | return &GetAuthParams{ 45 | 46 | Context: ctx, 47 | } 48 | } 49 | 50 | // NewGetAuthParamsWithHTTPClient creates a new GetAuthParams object 51 | // with the default values initialized, and the ability to set a custom HTTPClient for a request 52 | func NewGetAuthParamsWithHTTPClient(client *http.Client) *GetAuthParams { 53 | 54 | return &GetAuthParams{ 55 | HTTPClient: client, 56 | } 57 | } 58 | 59 | /*GetAuthParams contains all the parameters to send to the API endpoint 60 | for the get auth operation typically these are written to a http.Request 61 | */ 62 | type GetAuthParams struct { 63 | timeout time.Duration 64 | Context context.Context 65 | HTTPClient *http.Client 66 | } 67 | 68 | // WithTimeout adds the timeout to the get auth params 69 | func (o *GetAuthParams) WithTimeout(timeout time.Duration) *GetAuthParams { 70 | o.SetTimeout(timeout) 71 | return o 72 | } 73 | 74 | // SetTimeout adds the timeout to the get auth params 75 | func (o *GetAuthParams) SetTimeout(timeout time.Duration) { 76 | o.timeout = timeout 77 | } 78 | 79 | // WithContext adds the context to the get auth params 80 | func (o *GetAuthParams) WithContext(ctx context.Context) *GetAuthParams { 81 | o.SetContext(ctx) 82 | return o 83 | } 84 | 85 | // SetContext adds the context to the get auth params 86 | func (o *GetAuthParams) SetContext(ctx context.Context) { 87 | o.Context = ctx 88 | } 89 | 90 | // WithHTTPClient adds the HTTPClient to the get auth params 91 | func (o *GetAuthParams) WithHTTPClient(client *http.Client) *GetAuthParams { 92 | o.SetHTTPClient(client) 93 | return o 94 | } 95 | 96 | // SetHTTPClient adds the HTTPClient to the get auth params 97 | func (o *GetAuthParams) SetHTTPClient(client *http.Client) { 98 | o.HTTPClient = client 99 | } 100 | 101 | // WriteToRequest writes these params to a swagger request 102 | func (o *GetAuthParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 103 | 104 | if err := r.SetTimeout(o.timeout); err != nil { 105 | return err 106 | } 107 | var res []error 108 | 109 | if len(res) > 0 { 110 | return errors.CompositeValidationError(res...) 111 | } 112 | return nil 113 | } 114 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project email 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at [opensource@optum.com][email]. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | [email]: mailto:opensource@optum.com 76 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_auth_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | 17 | strfmt "github.com/go-openapi/strfmt" 18 | ) 19 | 20 | // NewOptionsAuthParams creates a new OptionsAuthParams object 21 | // with the default values initialized. 22 | func NewOptionsAuthParams() *OptionsAuthParams { 23 | 24 | return &OptionsAuthParams{ 25 | 26 | timeout: cr.DefaultTimeout, 27 | } 28 | } 29 | 30 | // NewOptionsAuthParamsWithTimeout creates a new OptionsAuthParams object 31 | // with the default values initialized, and the ability to set a timeout on a request 32 | func NewOptionsAuthParamsWithTimeout(timeout time.Duration) *OptionsAuthParams { 33 | 34 | return &OptionsAuthParams{ 35 | 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewOptionsAuthParamsWithContext creates a new OptionsAuthParams object 41 | // with the default values initialized, and the ability to set a context for a request 42 | func NewOptionsAuthParamsWithContext(ctx context.Context) *OptionsAuthParams { 43 | 44 | return &OptionsAuthParams{ 45 | 46 | Context: ctx, 47 | } 48 | } 49 | 50 | // NewOptionsAuthParamsWithHTTPClient creates a new OptionsAuthParams object 51 | // with the default values initialized, and the ability to set a custom HTTPClient for a request 52 | func NewOptionsAuthParamsWithHTTPClient(client *http.Client) *OptionsAuthParams { 53 | 54 | return &OptionsAuthParams{ 55 | HTTPClient: client, 56 | } 57 | } 58 | 59 | /*OptionsAuthParams contains all the parameters to send to the API endpoint 60 | for the options auth operation typically these are written to a http.Request 61 | */ 62 | type OptionsAuthParams struct { 63 | timeout time.Duration 64 | Context context.Context 65 | HTTPClient *http.Client 66 | } 67 | 68 | // WithTimeout adds the timeout to the options auth params 69 | func (o *OptionsAuthParams) WithTimeout(timeout time.Duration) *OptionsAuthParams { 70 | o.SetTimeout(timeout) 71 | return o 72 | } 73 | 74 | // SetTimeout adds the timeout to the options auth params 75 | func (o *OptionsAuthParams) SetTimeout(timeout time.Duration) { 76 | o.timeout = timeout 77 | } 78 | 79 | // WithContext adds the context to the options auth params 80 | func (o *OptionsAuthParams) WithContext(ctx context.Context) *OptionsAuthParams { 81 | o.SetContext(ctx) 82 | return o 83 | } 84 | 85 | // SetContext adds the context to the options auth params 86 | func (o *OptionsAuthParams) SetContext(ctx context.Context) { 87 | o.Context = ctx 88 | } 89 | 90 | // WithHTTPClient adds the HTTPClient to the options auth params 91 | func (o *OptionsAuthParams) WithHTTPClient(client *http.Client) *OptionsAuthParams { 92 | o.SetHTTPClient(client) 93 | return o 94 | } 95 | 96 | // SetHTTPClient adds the HTTPClient to the options auth params 97 | func (o *OptionsAuthParams) SetHTTPClient(client *http.Client) { 98 | o.HTTPClient = client 99 | } 100 | 101 | // WriteToRequest writes these params to a swagger request 102 | func (o *OptionsAuthParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 103 | 104 | if err := r.SetTimeout(o.timeout); err != nil { 105 | return err 106 | } 107 | var res []error 108 | 109 | if len(res) > 0 { 110 | return errors.CompositeValidationError(res...) 111 | } 112 | return nil 113 | } 114 | -------------------------------------------------------------------------------- /client/operations/get_auth_file_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package operations 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | 17 | strfmt "github.com/go-openapi/strfmt" 18 | ) 19 | 20 | // NewGetAuthFileParams creates a new GetAuthFileParams object 21 | // with the default values initialized. 22 | func NewGetAuthFileParams() *GetAuthFileParams { 23 | 24 | return &GetAuthFileParams{ 25 | 26 | timeout: cr.DefaultTimeout, 27 | } 28 | } 29 | 30 | // NewGetAuthFileParamsWithTimeout creates a new GetAuthFileParams object 31 | // with the default values initialized, and the ability to set a timeout on a request 32 | func NewGetAuthFileParamsWithTimeout(timeout time.Duration) *GetAuthFileParams { 33 | 34 | return &GetAuthFileParams{ 35 | 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewGetAuthFileParamsWithContext creates a new GetAuthFileParams object 41 | // with the default values initialized, and the ability to set a context for a request 42 | func NewGetAuthFileParamsWithContext(ctx context.Context) *GetAuthFileParams { 43 | 44 | return &GetAuthFileParams{ 45 | 46 | Context: ctx, 47 | } 48 | } 49 | 50 | // NewGetAuthFileParamsWithHTTPClient creates a new GetAuthFileParams object 51 | // with the default values initialized, and the ability to set a custom HTTPClient for a request 52 | func NewGetAuthFileParamsWithHTTPClient(client *http.Client) *GetAuthFileParams { 53 | 54 | return &GetAuthFileParams{ 55 | HTTPClient: client, 56 | } 57 | } 58 | 59 | /*GetAuthFileParams contains all the parameters to send to the API endpoint 60 | for the get auth file operation typically these are written to a http.Request 61 | */ 62 | type GetAuthFileParams struct { 63 | timeout time.Duration 64 | Context context.Context 65 | HTTPClient *http.Client 66 | } 67 | 68 | // WithTimeout adds the timeout to the get auth file params 69 | func (o *GetAuthFileParams) WithTimeout(timeout time.Duration) *GetAuthFileParams { 70 | o.SetTimeout(timeout) 71 | return o 72 | } 73 | 74 | // SetTimeout adds the timeout to the get auth file params 75 | func (o *GetAuthFileParams) SetTimeout(timeout time.Duration) { 76 | o.timeout = timeout 77 | } 78 | 79 | // WithContext adds the context to the get auth file params 80 | func (o *GetAuthFileParams) WithContext(ctx context.Context) *GetAuthFileParams { 81 | o.SetContext(ctx) 82 | return o 83 | } 84 | 85 | // SetContext adds the context to the get auth file params 86 | func (o *GetAuthFileParams) SetContext(ctx context.Context) { 87 | o.Context = ctx 88 | } 89 | 90 | // WithHTTPClient adds the HTTPClient to the get auth file params 91 | func (o *GetAuthFileParams) WithHTTPClient(client *http.Client) *GetAuthFileParams { 92 | o.SetHTTPClient(client) 93 | return o 94 | } 95 | 96 | // SetHTTPClient adds the HTTPClient to the get auth file params 97 | func (o *GetAuthFileParams) SetHTTPClient(client *http.Client) { 98 | o.HTTPClient = client 99 | } 100 | 101 | // WriteToRequest writes these params to a swagger request 102 | func (o *GetAuthFileParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 103 | 104 | if err := r.SetTimeout(o.timeout); err != nil { 105 | return err 106 | } 107 | var res []error 108 | 109 | if len(res) > 0 { 110 | return errors.CompositeValidationError(res...) 111 | } 112 | return nil 113 | } 114 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_usage_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | 17 | strfmt "github.com/go-openapi/strfmt" 18 | ) 19 | 20 | // NewOptionsUsageParams creates a new OptionsUsageParams object 21 | // with the default values initialized. 22 | func NewOptionsUsageParams() *OptionsUsageParams { 23 | 24 | return &OptionsUsageParams{ 25 | 26 | timeout: cr.DefaultTimeout, 27 | } 28 | } 29 | 30 | // NewOptionsUsageParamsWithTimeout creates a new OptionsUsageParams object 31 | // with the default values initialized, and the ability to set a timeout on a request 32 | func NewOptionsUsageParamsWithTimeout(timeout time.Duration) *OptionsUsageParams { 33 | 34 | return &OptionsUsageParams{ 35 | 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewOptionsUsageParamsWithContext creates a new OptionsUsageParams object 41 | // with the default values initialized, and the ability to set a context for a request 42 | func NewOptionsUsageParamsWithContext(ctx context.Context) *OptionsUsageParams { 43 | 44 | return &OptionsUsageParams{ 45 | 46 | Context: ctx, 47 | } 48 | } 49 | 50 | // NewOptionsUsageParamsWithHTTPClient creates a new OptionsUsageParams object 51 | // with the default values initialized, and the ability to set a custom HTTPClient for a request 52 | func NewOptionsUsageParamsWithHTTPClient(client *http.Client) *OptionsUsageParams { 53 | 54 | return &OptionsUsageParams{ 55 | HTTPClient: client, 56 | } 57 | } 58 | 59 | /*OptionsUsageParams contains all the parameters to send to the API endpoint 60 | for the options usage operation typically these are written to a http.Request 61 | */ 62 | type OptionsUsageParams struct { 63 | timeout time.Duration 64 | Context context.Context 65 | HTTPClient *http.Client 66 | } 67 | 68 | // WithTimeout adds the timeout to the options usage params 69 | func (o *OptionsUsageParams) WithTimeout(timeout time.Duration) *OptionsUsageParams { 70 | o.SetTimeout(timeout) 71 | return o 72 | } 73 | 74 | // SetTimeout adds the timeout to the options usage params 75 | func (o *OptionsUsageParams) SetTimeout(timeout time.Duration) { 76 | o.timeout = timeout 77 | } 78 | 79 | // WithContext adds the context to the options usage params 80 | func (o *OptionsUsageParams) WithContext(ctx context.Context) *OptionsUsageParams { 81 | o.SetContext(ctx) 82 | return o 83 | } 84 | 85 | // SetContext adds the context to the options usage params 86 | func (o *OptionsUsageParams) SetContext(ctx context.Context) { 87 | o.Context = ctx 88 | } 89 | 90 | // WithHTTPClient adds the HTTPClient to the options usage params 91 | func (o *OptionsUsageParams) WithHTTPClient(client *http.Client) *OptionsUsageParams { 92 | o.SetHTTPClient(client) 93 | return o 94 | } 95 | 96 | // SetHTTPClient adds the HTTPClient to the options usage params 97 | func (o *OptionsUsageParams) SetHTTPClient(client *http.Client) { 98 | o.HTTPClient = client 99 | } 100 | 101 | // WriteToRequest writes these params to a swagger request 102 | func (o *OptionsUsageParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 103 | 104 | if err := r.SetTimeout(o.timeout); err != nil { 105 | return err 106 | } 107 | var res []error 108 | 109 | if len(res) > 0 { 110 | return errors.CompositeValidationError(res...) 111 | } 112 | return nil 113 | } 114 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_leases_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | 17 | strfmt "github.com/go-openapi/strfmt" 18 | ) 19 | 20 | // NewOptionsLeasesParams creates a new OptionsLeasesParams object 21 | // with the default values initialized. 22 | func NewOptionsLeasesParams() *OptionsLeasesParams { 23 | 24 | return &OptionsLeasesParams{ 25 | 26 | timeout: cr.DefaultTimeout, 27 | } 28 | } 29 | 30 | // NewOptionsLeasesParamsWithTimeout creates a new OptionsLeasesParams object 31 | // with the default values initialized, and the ability to set a timeout on a request 32 | func NewOptionsLeasesParamsWithTimeout(timeout time.Duration) *OptionsLeasesParams { 33 | 34 | return &OptionsLeasesParams{ 35 | 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewOptionsLeasesParamsWithContext creates a new OptionsLeasesParams object 41 | // with the default values initialized, and the ability to set a context for a request 42 | func NewOptionsLeasesParamsWithContext(ctx context.Context) *OptionsLeasesParams { 43 | 44 | return &OptionsLeasesParams{ 45 | 46 | Context: ctx, 47 | } 48 | } 49 | 50 | // NewOptionsLeasesParamsWithHTTPClient creates a new OptionsLeasesParams object 51 | // with the default values initialized, and the ability to set a custom HTTPClient for a request 52 | func NewOptionsLeasesParamsWithHTTPClient(client *http.Client) *OptionsLeasesParams { 53 | 54 | return &OptionsLeasesParams{ 55 | HTTPClient: client, 56 | } 57 | } 58 | 59 | /*OptionsLeasesParams contains all the parameters to send to the API endpoint 60 | for the options leases operation typically these are written to a http.Request 61 | */ 62 | type OptionsLeasesParams struct { 63 | timeout time.Duration 64 | Context context.Context 65 | HTTPClient *http.Client 66 | } 67 | 68 | // WithTimeout adds the timeout to the options leases params 69 | func (o *OptionsLeasesParams) WithTimeout(timeout time.Duration) *OptionsLeasesParams { 70 | o.SetTimeout(timeout) 71 | return o 72 | } 73 | 74 | // SetTimeout adds the timeout to the options leases params 75 | func (o *OptionsLeasesParams) SetTimeout(timeout time.Duration) { 76 | o.timeout = timeout 77 | } 78 | 79 | // WithContext adds the context to the options leases params 80 | func (o *OptionsLeasesParams) WithContext(ctx context.Context) *OptionsLeasesParams { 81 | o.SetContext(ctx) 82 | return o 83 | } 84 | 85 | // SetContext adds the context to the options leases params 86 | func (o *OptionsLeasesParams) SetContext(ctx context.Context) { 87 | o.Context = ctx 88 | } 89 | 90 | // WithHTTPClient adds the HTTPClient to the options leases params 91 | func (o *OptionsLeasesParams) WithHTTPClient(client *http.Client) *OptionsLeasesParams { 92 | o.SetHTTPClient(client) 93 | return o 94 | } 95 | 96 | // SetHTTPClient adds the HTTPClient to the options leases params 97 | func (o *OptionsLeasesParams) SetHTTPClient(client *http.Client) { 98 | o.HTTPClient = client 99 | } 100 | 101 | // WriteToRequest writes these params to a swagger request 102 | func (o *OptionsLeasesParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 103 | 104 | if err := r.SetTimeout(o.timeout); err != nil { 105 | return err 106 | } 107 | var res []error 108 | 109 | if len(res) > 0 { 110 | return errors.CompositeValidationError(res...) 111 | } 112 | return nil 113 | } 114 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidelines 2 | 3 | Please note that this project is released with a [Contributor Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms. Please also review our [Contributor License Agreement ("CLA")](INDIVIDUAL_CONTRIBUTOR_LICENSE.md) prior to submitting changes to the project. You will need to attest to this agreement following the instructions in the [Paperwork for Pull Requests](#paperwork-for-pull-requests) section below. 4 | 5 | --- 6 | 7 | # How to Contribute 8 | 9 | Now that we have the disclaimer out of the way, let's get into how you can be a part of our project. There are many different ways to contribute. 10 | 11 | ## Issues 12 | 13 | We track our work using Issues in GitHub. Feel free to open up your own issue to point out areas for improvement or to suggest your own new experiment. If you are comfortable with signing the waiver linked above and contributing code or documentation, grab your own issue and start working. 14 | 15 | ## Coding Standards 16 | 17 | We have some general guidelines towards contributing to this project. 18 | 19 | ### Languages 20 | 21 | *Go* 22 | 23 | The source code for this project is written in Go. You are welcome to add versions of files for other languages, however the core code will remain in Go. 24 | 25 | ## Pull Requests 26 | 27 | If you've gotten as far as reading this section, then thank you for your suggestions. 28 | 29 | ## Paperwork for Pull Requests 30 | 31 | * Please read this guide and make sure you agree with our [Contributor License Agreement ("CLA")](INDIVIDUAL_CONTRIBUTOR_LICENSE.md). 32 | * Make sure git knows your name and email address: 33 | ``` 34 | $ git config user.name "J. Random User" 35 | $ git config user.email "j.random.user@example.com" 36 | ``` 37 | >The name and email address must be valid as we cannot accept anonymous contributions. 38 | * Write good commit messages. 39 | > Concise commit messages that describe your changes help us better understand your contributions. 40 | * The first time you open a pull request in this repository, you will see a comment on your PR with a link that will allow you to sign our Contributor License Agreement (CLA) if necessary. 41 | > The link will take you to a page that allows you to view our CLA. You will need to click the `Sign in with GitHub to agree button` and authorize the cla-assistant application to access the email addresses associated with your GitHub account. Agreeing to the CLA is also considered to be an attestation that you either wrote or have the rights to contribute the code. All committers to the PR branch will be required to sign the CLA, but you will only need to sign once. This CLA applies to all repositories in the Optum org. 42 | 43 | ## General Guidelines 44 | 45 | Ensure your pull request (PR) adheres to the following guidelines: 46 | 47 | * Try to make the name concise and descriptive. 48 | * Give a good description of the change being made. Since this is very subjective, see the [Updating Your Pull Request (PR)](#updating-your-pull-request-pr) section below for further details. 49 | * Every pull request should be associated with one or more issues. If no issue exists yet, please create your own. 50 | * Make sure that all applicable issues are mentioned somewhere in the PR description. This can be done by typing # to bring up a list of issues. 51 | 52 | ### Updating Your Pull Request (PR) 53 | 54 | A lot of times, making a PR adhere to the standards above can be difficult. If the maintainers notice anything that we'd like changed, we'll ask you to edit your PR before we merge it. This applies to both the content documented in the PR and the changed contained within the branch being merged. There's no need to open a new PR. Just edit the existing one. 55 | 56 | [email]: mailto:opensource@optum.com 57 | -------------------------------------------------------------------------------- /client/operations/post_leases_auth_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package operations 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | 17 | strfmt "github.com/go-openapi/strfmt" 18 | ) 19 | 20 | // NewPostLeasesAuthParams creates a new PostLeasesAuthParams object 21 | // with the default values initialized. 22 | func NewPostLeasesAuthParams() *PostLeasesAuthParams { 23 | 24 | return &PostLeasesAuthParams{ 25 | 26 | timeout: cr.DefaultTimeout, 27 | } 28 | } 29 | 30 | // NewPostLeasesAuthParamsWithTimeout creates a new PostLeasesAuthParams object 31 | // with the default values initialized, and the ability to set a timeout on a request 32 | func NewPostLeasesAuthParamsWithTimeout(timeout time.Duration) *PostLeasesAuthParams { 33 | 34 | return &PostLeasesAuthParams{ 35 | 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewPostLeasesAuthParamsWithContext creates a new PostLeasesAuthParams object 41 | // with the default values initialized, and the ability to set a context for a request 42 | func NewPostLeasesAuthParamsWithContext(ctx context.Context) *PostLeasesAuthParams { 43 | 44 | return &PostLeasesAuthParams{ 45 | 46 | Context: ctx, 47 | } 48 | } 49 | 50 | // NewPostLeasesAuthParamsWithHTTPClient creates a new PostLeasesAuthParams object 51 | // with the default values initialized, and the ability to set a custom HTTPClient for a request 52 | func NewPostLeasesAuthParamsWithHTTPClient(client *http.Client) *PostLeasesAuthParams { 53 | 54 | return &PostLeasesAuthParams{ 55 | HTTPClient: client, 56 | } 57 | } 58 | 59 | /*PostLeasesAuthParams contains all the parameters to send to the API endpoint 60 | for the post leases auth operation typically these are written to a http.Request 61 | */ 62 | type PostLeasesAuthParams struct { 63 | timeout time.Duration 64 | Context context.Context 65 | HTTPClient *http.Client 66 | } 67 | 68 | // WithTimeout adds the timeout to the post leases auth params 69 | func (o *PostLeasesAuthParams) WithTimeout(timeout time.Duration) *PostLeasesAuthParams { 70 | o.SetTimeout(timeout) 71 | return o 72 | } 73 | 74 | // SetTimeout adds the timeout to the post leases auth params 75 | func (o *PostLeasesAuthParams) SetTimeout(timeout time.Duration) { 76 | o.timeout = timeout 77 | } 78 | 79 | // WithContext adds the context to the post leases auth params 80 | func (o *PostLeasesAuthParams) WithContext(ctx context.Context) *PostLeasesAuthParams { 81 | o.SetContext(ctx) 82 | return o 83 | } 84 | 85 | // SetContext adds the context to the post leases auth params 86 | func (o *PostLeasesAuthParams) SetContext(ctx context.Context) { 87 | o.Context = ctx 88 | } 89 | 90 | // WithHTTPClient adds the HTTPClient to the post leases auth params 91 | func (o *PostLeasesAuthParams) WithHTTPClient(client *http.Client) *PostLeasesAuthParams { 92 | o.SetHTTPClient(client) 93 | return o 94 | } 95 | 96 | // SetHTTPClient adds the HTTPClient to the post leases auth params 97 | func (o *PostLeasesAuthParams) SetHTTPClient(client *http.Client) { 98 | o.HTTPClient = client 99 | } 100 | 101 | // WriteToRequest writes these params to a swagger request 102 | func (o *PostLeasesAuthParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 103 | 104 | if err := r.SetTimeout(o.timeout); err != nil { 105 | return err 106 | } 107 | var res []error 108 | 109 | if len(res) > 0 { 110 | return errors.CompositeValidationError(res...) 111 | } 112 | return nil 113 | } 114 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_accounts_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | 17 | strfmt "github.com/go-openapi/strfmt" 18 | ) 19 | 20 | // NewOptionsAccountsParams creates a new OptionsAccountsParams object 21 | // with the default values initialized. 22 | func NewOptionsAccountsParams() *OptionsAccountsParams { 23 | 24 | return &OptionsAccountsParams{ 25 | 26 | timeout: cr.DefaultTimeout, 27 | } 28 | } 29 | 30 | // NewOptionsAccountsParamsWithTimeout creates a new OptionsAccountsParams object 31 | // with the default values initialized, and the ability to set a timeout on a request 32 | func NewOptionsAccountsParamsWithTimeout(timeout time.Duration) *OptionsAccountsParams { 33 | 34 | return &OptionsAccountsParams{ 35 | 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewOptionsAccountsParamsWithContext creates a new OptionsAccountsParams object 41 | // with the default values initialized, and the ability to set a context for a request 42 | func NewOptionsAccountsParamsWithContext(ctx context.Context) *OptionsAccountsParams { 43 | 44 | return &OptionsAccountsParams{ 45 | 46 | Context: ctx, 47 | } 48 | } 49 | 50 | // NewOptionsAccountsParamsWithHTTPClient creates a new OptionsAccountsParams object 51 | // with the default values initialized, and the ability to set a custom HTTPClient for a request 52 | func NewOptionsAccountsParamsWithHTTPClient(client *http.Client) *OptionsAccountsParams { 53 | 54 | return &OptionsAccountsParams{ 55 | HTTPClient: client, 56 | } 57 | } 58 | 59 | /*OptionsAccountsParams contains all the parameters to send to the API endpoint 60 | for the options accounts operation typically these are written to a http.Request 61 | */ 62 | type OptionsAccountsParams struct { 63 | timeout time.Duration 64 | Context context.Context 65 | HTTPClient *http.Client 66 | } 67 | 68 | // WithTimeout adds the timeout to the options accounts params 69 | func (o *OptionsAccountsParams) WithTimeout(timeout time.Duration) *OptionsAccountsParams { 70 | o.SetTimeout(timeout) 71 | return o 72 | } 73 | 74 | // SetTimeout adds the timeout to the options accounts params 75 | func (o *OptionsAccountsParams) SetTimeout(timeout time.Duration) { 76 | o.timeout = timeout 77 | } 78 | 79 | // WithContext adds the context to the options accounts params 80 | func (o *OptionsAccountsParams) WithContext(ctx context.Context) *OptionsAccountsParams { 81 | o.SetContext(ctx) 82 | return o 83 | } 84 | 85 | // SetContext adds the context to the options accounts params 86 | func (o *OptionsAccountsParams) SetContext(ctx context.Context) { 87 | o.Context = ctx 88 | } 89 | 90 | // WithHTTPClient adds the HTTPClient to the options accounts params 91 | func (o *OptionsAccountsParams) WithHTTPClient(client *http.Client) *OptionsAccountsParams { 92 | o.SetHTTPClient(client) 93 | return o 94 | } 95 | 96 | // SetHTTPClient adds the HTTPClient to the options accounts params 97 | func (o *OptionsAccountsParams) SetHTTPClient(client *http.Client) { 98 | o.HTTPClient = client 99 | } 100 | 101 | // WriteToRequest writes these params to a swagger request 102 | func (o *OptionsAccountsParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 103 | 104 | if err := r.SetTimeout(o.timeout); err != nil { 105 | return err 106 | } 107 | var res []error 108 | 109 | if len(res) > 0 { 110 | return errors.CompositeValidationError(res...) 111 | } 112 | return nil 113 | } 114 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_auth_file_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | 17 | strfmt "github.com/go-openapi/strfmt" 18 | ) 19 | 20 | // NewOptionsAuthFileParams creates a new OptionsAuthFileParams object 21 | // with the default values initialized. 22 | func NewOptionsAuthFileParams() *OptionsAuthFileParams { 23 | 24 | return &OptionsAuthFileParams{ 25 | 26 | timeout: cr.DefaultTimeout, 27 | } 28 | } 29 | 30 | // NewOptionsAuthFileParamsWithTimeout creates a new OptionsAuthFileParams object 31 | // with the default values initialized, and the ability to set a timeout on a request 32 | func NewOptionsAuthFileParamsWithTimeout(timeout time.Duration) *OptionsAuthFileParams { 33 | 34 | return &OptionsAuthFileParams{ 35 | 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewOptionsAuthFileParamsWithContext creates a new OptionsAuthFileParams object 41 | // with the default values initialized, and the ability to set a context for a request 42 | func NewOptionsAuthFileParamsWithContext(ctx context.Context) *OptionsAuthFileParams { 43 | 44 | return &OptionsAuthFileParams{ 45 | 46 | Context: ctx, 47 | } 48 | } 49 | 50 | // NewOptionsAuthFileParamsWithHTTPClient creates a new OptionsAuthFileParams object 51 | // with the default values initialized, and the ability to set a custom HTTPClient for a request 52 | func NewOptionsAuthFileParamsWithHTTPClient(client *http.Client) *OptionsAuthFileParams { 53 | 54 | return &OptionsAuthFileParams{ 55 | HTTPClient: client, 56 | } 57 | } 58 | 59 | /*OptionsAuthFileParams contains all the parameters to send to the API endpoint 60 | for the options auth file operation typically these are written to a http.Request 61 | */ 62 | type OptionsAuthFileParams struct { 63 | timeout time.Duration 64 | Context context.Context 65 | HTTPClient *http.Client 66 | } 67 | 68 | // WithTimeout adds the timeout to the options auth file params 69 | func (o *OptionsAuthFileParams) WithTimeout(timeout time.Duration) *OptionsAuthFileParams { 70 | o.SetTimeout(timeout) 71 | return o 72 | } 73 | 74 | // SetTimeout adds the timeout to the options auth file params 75 | func (o *OptionsAuthFileParams) SetTimeout(timeout time.Duration) { 76 | o.timeout = timeout 77 | } 78 | 79 | // WithContext adds the context to the options auth file params 80 | func (o *OptionsAuthFileParams) WithContext(ctx context.Context) *OptionsAuthFileParams { 81 | o.SetContext(ctx) 82 | return o 83 | } 84 | 85 | // SetContext adds the context to the options auth file params 86 | func (o *OptionsAuthFileParams) SetContext(ctx context.Context) { 87 | o.Context = ctx 88 | } 89 | 90 | // WithHTTPClient adds the HTTPClient to the options auth file params 91 | func (o *OptionsAuthFileParams) WithHTTPClient(client *http.Client) *OptionsAuthFileParams { 92 | o.SetHTTPClient(client) 93 | return o 94 | } 95 | 96 | // SetHTTPClient adds the HTTPClient to the options auth file params 97 | func (o *OptionsAuthFileParams) SetHTTPClient(client *http.Client) { 98 | o.HTTPClient = client 99 | } 100 | 101 | // WriteToRequest writes these params to a swagger request 102 | func (o *OptionsAuthFileParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 103 | 104 | if err := r.SetTimeout(o.timeout); err != nil { 105 | return err 106 | } 107 | var res []error 108 | 109 | if len(res) > 0 { 110 | return errors.CompositeValidationError(res...) 111 | } 112 | return nil 113 | } 114 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_leases_id_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | 17 | strfmt "github.com/go-openapi/strfmt" 18 | ) 19 | 20 | // NewOptionsLeasesIDParams creates a new OptionsLeasesIDParams object 21 | // with the default values initialized. 22 | func NewOptionsLeasesIDParams() *OptionsLeasesIDParams { 23 | 24 | return &OptionsLeasesIDParams{ 25 | 26 | timeout: cr.DefaultTimeout, 27 | } 28 | } 29 | 30 | // NewOptionsLeasesIDParamsWithTimeout creates a new OptionsLeasesIDParams object 31 | // with the default values initialized, and the ability to set a timeout on a request 32 | func NewOptionsLeasesIDParamsWithTimeout(timeout time.Duration) *OptionsLeasesIDParams { 33 | 34 | return &OptionsLeasesIDParams{ 35 | 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewOptionsLeasesIDParamsWithContext creates a new OptionsLeasesIDParams object 41 | // with the default values initialized, and the ability to set a context for a request 42 | func NewOptionsLeasesIDParamsWithContext(ctx context.Context) *OptionsLeasesIDParams { 43 | 44 | return &OptionsLeasesIDParams{ 45 | 46 | Context: ctx, 47 | } 48 | } 49 | 50 | // NewOptionsLeasesIDParamsWithHTTPClient creates a new OptionsLeasesIDParams object 51 | // with the default values initialized, and the ability to set a custom HTTPClient for a request 52 | func NewOptionsLeasesIDParamsWithHTTPClient(client *http.Client) *OptionsLeasesIDParams { 53 | 54 | return &OptionsLeasesIDParams{ 55 | HTTPClient: client, 56 | } 57 | } 58 | 59 | /*OptionsLeasesIDParams contains all the parameters to send to the API endpoint 60 | for the options leases ID operation typically these are written to a http.Request 61 | */ 62 | type OptionsLeasesIDParams struct { 63 | timeout time.Duration 64 | Context context.Context 65 | HTTPClient *http.Client 66 | } 67 | 68 | // WithTimeout adds the timeout to the options leases ID params 69 | func (o *OptionsLeasesIDParams) WithTimeout(timeout time.Duration) *OptionsLeasesIDParams { 70 | o.SetTimeout(timeout) 71 | return o 72 | } 73 | 74 | // SetTimeout adds the timeout to the options leases ID params 75 | func (o *OptionsLeasesIDParams) SetTimeout(timeout time.Duration) { 76 | o.timeout = timeout 77 | } 78 | 79 | // WithContext adds the context to the options leases ID params 80 | func (o *OptionsLeasesIDParams) WithContext(ctx context.Context) *OptionsLeasesIDParams { 81 | o.SetContext(ctx) 82 | return o 83 | } 84 | 85 | // SetContext adds the context to the options leases ID params 86 | func (o *OptionsLeasesIDParams) SetContext(ctx context.Context) { 87 | o.Context = ctx 88 | } 89 | 90 | // WithHTTPClient adds the HTTPClient to the options leases ID params 91 | func (o *OptionsLeasesIDParams) WithHTTPClient(client *http.Client) *OptionsLeasesIDParams { 92 | o.SetHTTPClient(client) 93 | return o 94 | } 95 | 96 | // SetHTTPClient adds the HTTPClient to the options leases ID params 97 | func (o *OptionsLeasesIDParams) SetHTTPClient(client *http.Client) { 98 | o.HTTPClient = client 99 | } 100 | 101 | // WriteToRequest writes these params to a swagger request 102 | func (o *OptionsLeasesIDParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 103 | 104 | if err := r.SetTimeout(o.timeout); err != nil { 105 | return err 106 | } 107 | var res []error 108 | 109 | if len(res) > 0 { 110 | return errors.CompositeValidationError(res...) 111 | } 112 | return nil 113 | } 114 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_accounts_id_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | 17 | strfmt "github.com/go-openapi/strfmt" 18 | ) 19 | 20 | // NewOptionsAccountsIDParams creates a new OptionsAccountsIDParams object 21 | // with the default values initialized. 22 | func NewOptionsAccountsIDParams() *OptionsAccountsIDParams { 23 | 24 | return &OptionsAccountsIDParams{ 25 | 26 | timeout: cr.DefaultTimeout, 27 | } 28 | } 29 | 30 | // NewOptionsAccountsIDParamsWithTimeout creates a new OptionsAccountsIDParams object 31 | // with the default values initialized, and the ability to set a timeout on a request 32 | func NewOptionsAccountsIDParamsWithTimeout(timeout time.Duration) *OptionsAccountsIDParams { 33 | 34 | return &OptionsAccountsIDParams{ 35 | 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewOptionsAccountsIDParamsWithContext creates a new OptionsAccountsIDParams object 41 | // with the default values initialized, and the ability to set a context for a request 42 | func NewOptionsAccountsIDParamsWithContext(ctx context.Context) *OptionsAccountsIDParams { 43 | 44 | return &OptionsAccountsIDParams{ 45 | 46 | Context: ctx, 47 | } 48 | } 49 | 50 | // NewOptionsAccountsIDParamsWithHTTPClient creates a new OptionsAccountsIDParams object 51 | // with the default values initialized, and the ability to set a custom HTTPClient for a request 52 | func NewOptionsAccountsIDParamsWithHTTPClient(client *http.Client) *OptionsAccountsIDParams { 53 | 54 | return &OptionsAccountsIDParams{ 55 | HTTPClient: client, 56 | } 57 | } 58 | 59 | /*OptionsAccountsIDParams contains all the parameters to send to the API endpoint 60 | for the options accounts ID operation typically these are written to a http.Request 61 | */ 62 | type OptionsAccountsIDParams struct { 63 | timeout time.Duration 64 | Context context.Context 65 | HTTPClient *http.Client 66 | } 67 | 68 | // WithTimeout adds the timeout to the options accounts ID params 69 | func (o *OptionsAccountsIDParams) WithTimeout(timeout time.Duration) *OptionsAccountsIDParams { 70 | o.SetTimeout(timeout) 71 | return o 72 | } 73 | 74 | // SetTimeout adds the timeout to the options accounts ID params 75 | func (o *OptionsAccountsIDParams) SetTimeout(timeout time.Duration) { 76 | o.timeout = timeout 77 | } 78 | 79 | // WithContext adds the context to the options accounts ID params 80 | func (o *OptionsAccountsIDParams) WithContext(ctx context.Context) *OptionsAccountsIDParams { 81 | o.SetContext(ctx) 82 | return o 83 | } 84 | 85 | // SetContext adds the context to the options accounts ID params 86 | func (o *OptionsAccountsIDParams) SetContext(ctx context.Context) { 87 | o.Context = ctx 88 | } 89 | 90 | // WithHTTPClient adds the HTTPClient to the options accounts ID params 91 | func (o *OptionsAccountsIDParams) WithHTTPClient(client *http.Client) *OptionsAccountsIDParams { 92 | o.SetHTTPClient(client) 93 | return o 94 | } 95 | 96 | // SetHTTPClient adds the HTTPClient to the options accounts ID params 97 | func (o *OptionsAccountsIDParams) SetHTTPClient(client *http.Client) { 98 | o.HTTPClient = client 99 | } 100 | 101 | // WriteToRequest writes these params to a swagger request 102 | func (o *OptionsAccountsIDParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 103 | 104 | if err := r.SetTimeout(o.timeout); err != nil { 105 | return err 106 | } 107 | var res []error 108 | 109 | if len(res) > 0 { 110 | return errors.CompositeValidationError(res...) 111 | } 112 | return nil 113 | } 114 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_leases_auth_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | 17 | strfmt "github.com/go-openapi/strfmt" 18 | ) 19 | 20 | // NewOptionsLeasesAuthParams creates a new OptionsLeasesAuthParams object 21 | // with the default values initialized. 22 | func NewOptionsLeasesAuthParams() *OptionsLeasesAuthParams { 23 | 24 | return &OptionsLeasesAuthParams{ 25 | 26 | timeout: cr.DefaultTimeout, 27 | } 28 | } 29 | 30 | // NewOptionsLeasesAuthParamsWithTimeout creates a new OptionsLeasesAuthParams object 31 | // with the default values initialized, and the ability to set a timeout on a request 32 | func NewOptionsLeasesAuthParamsWithTimeout(timeout time.Duration) *OptionsLeasesAuthParams { 33 | 34 | return &OptionsLeasesAuthParams{ 35 | 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewOptionsLeasesAuthParamsWithContext creates a new OptionsLeasesAuthParams object 41 | // with the default values initialized, and the ability to set a context for a request 42 | func NewOptionsLeasesAuthParamsWithContext(ctx context.Context) *OptionsLeasesAuthParams { 43 | 44 | return &OptionsLeasesAuthParams{ 45 | 46 | Context: ctx, 47 | } 48 | } 49 | 50 | // NewOptionsLeasesAuthParamsWithHTTPClient creates a new OptionsLeasesAuthParams object 51 | // with the default values initialized, and the ability to set a custom HTTPClient for a request 52 | func NewOptionsLeasesAuthParamsWithHTTPClient(client *http.Client) *OptionsLeasesAuthParams { 53 | 54 | return &OptionsLeasesAuthParams{ 55 | HTTPClient: client, 56 | } 57 | } 58 | 59 | /*OptionsLeasesAuthParams contains all the parameters to send to the API endpoint 60 | for the options leases auth operation typically these are written to a http.Request 61 | */ 62 | type OptionsLeasesAuthParams struct { 63 | timeout time.Duration 64 | Context context.Context 65 | HTTPClient *http.Client 66 | } 67 | 68 | // WithTimeout adds the timeout to the options leases auth params 69 | func (o *OptionsLeasesAuthParams) WithTimeout(timeout time.Duration) *OptionsLeasesAuthParams { 70 | o.SetTimeout(timeout) 71 | return o 72 | } 73 | 74 | // SetTimeout adds the timeout to the options leases auth params 75 | func (o *OptionsLeasesAuthParams) SetTimeout(timeout time.Duration) { 76 | o.timeout = timeout 77 | } 78 | 79 | // WithContext adds the context to the options leases auth params 80 | func (o *OptionsLeasesAuthParams) WithContext(ctx context.Context) *OptionsLeasesAuthParams { 81 | o.SetContext(ctx) 82 | return o 83 | } 84 | 85 | // SetContext adds the context to the options leases auth params 86 | func (o *OptionsLeasesAuthParams) SetContext(ctx context.Context) { 87 | o.Context = ctx 88 | } 89 | 90 | // WithHTTPClient adds the HTTPClient to the options leases auth params 91 | func (o *OptionsLeasesAuthParams) WithHTTPClient(client *http.Client) *OptionsLeasesAuthParams { 92 | o.SetHTTPClient(client) 93 | return o 94 | } 95 | 96 | // SetHTTPClient adds the HTTPClient to the options leases auth params 97 | func (o *OptionsLeasesAuthParams) SetHTTPClient(client *http.Client) { 98 | o.HTTPClient = client 99 | } 100 | 101 | // WriteToRequest writes these params to a swagger request 102 | func (o *OptionsLeasesAuthParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 103 | 104 | if err := r.SetTimeout(o.timeout); err != nil { 105 | return err 106 | } 107 | var res []error 108 | 109 | if len(res) > 0 { 110 | return errors.CompositeValidationError(res...) 111 | } 112 | return nil 113 | } 114 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | # Go 2 | # Build your Go project. 3 | # Add steps that test, save build artifacts, deploy, and more: 4 | # https://docs.microsoft.com/azure/devops/pipelines/languages/go 5 | 6 | trigger: 7 | # Do not build branches 8 | branches: 9 | exclude: 10 | - "*" 11 | # Run build on tagged versions 12 | tags: 13 | include: 14 | - "v*" 15 | 16 | # Run builds for PRs against `master` 17 | pr: 18 | - master 19 | - release/* 20 | 21 | pool: 22 | vmImage: 'ubuntu-latest' 23 | 24 | steps: 25 | 26 | - bash: | 27 | GIT_VERSION="$(git describe --always --long --dirty)" 28 | echo "##vso[task.setvariable variable=VERSION]${GIT_VERSION}" 29 | 30 | # Install GO 31 | - task: GoTool@0 32 | inputs: 33 | version: "1.13.4" 34 | displayName: "Set up the Go workspace" 35 | 36 | # Install tools needed for CI environment 37 | - script: | 38 | ./scripts/install_ci.sh 39 | displayName: "Set up Golang CI Tools" 40 | 41 | - script: | 42 | set -x 43 | go version 44 | go get -v -t -d ./... 45 | displayName: 'Get dependencies' 46 | 47 | # Install tools needed for CI environment 48 | - script: | 49 | ./scripts/install_ci.sh 50 | displayName: "Set up Golang CI Tools" 51 | 52 | - script: | 53 | set -ex 54 | # etcd depdendency bug workaround. See commends in go.mod for more details. 55 | go build -ldflags "-X github.com/Optum/dce-cli/cmd.version=$(VERSION)" -v . 56 | sudo rm /home/vsts/go/pkg/mod/github.com/coreos/etcd@v3.3.10+incompatible/client/keys.generated.go || true 57 | 58 | which go-junit-report 59 | 60 | make test 61 | displayName: 'Run tests' 62 | 63 | 64 | 65 | # Publish junit test results (for unit and functional tests) 66 | - task: PublishTestResults@2 67 | inputs: 68 | testRunner: JUnit 69 | testResultsFiles: $(System.DefaultWorkingDirectory)/junit-report/*.xml 70 | testRunTitle: Unit Tests 71 | condition: always() 72 | 73 | 74 | # Publish code coverage results 75 | - task: PublishCodeCoverageResults@1 76 | inputs: 77 | codeCoverageTool: Cobertura 78 | summaryFileLocation: $(System.DefaultWorkingDirectory)/coverage.xml 79 | condition: always() 80 | 81 | - script: | 82 | set -x 83 | mkdir dist && cd dist 84 | # zip for windows and calculate sha256 hash 85 | WINFILE=dce_windows_amd64.zip 86 | env GOOS=windows GOARCH=amd64 go build -ldflags "-X github.com/Optum/dce-cli/cmd.version=$(VERSION)" -v -o ./dce .. 87 | zip -m $WINFILE ./dce 88 | WINSHA=$(IFS=' '; read -ra ADDR <<< $(sha256sum $WINFILE); echo "${ADDR[0]}") 89 | 90 | # zip for linux and calculate sha256 hash 91 | LINFILE=dce_linux_amd64.zip 92 | env GOOS=linux GOARCH=amd64 go build -ldflags "-X github.com/Optum/dce-cli/cmd.version=$(VERSION)" -v -o ./dce .. 93 | zip -m $LINFILE ./dce 94 | LINSHA=$(IFS=' '; read -ra ADDR <<< $(sha256sum $LINFILE); echo "${ADDR[0]}") 95 | 96 | # zip for mac and calculate sha256 hash 97 | MACFILE=dce_darwin_amd64.zip 98 | env GOOS=darwin GOARCH=amd64 go build -ldflags "-X github.com/Optum/dce-cli/cmd.version=$(VERSION)" -v -o ./dce .. 99 | zip -m $MACFILE ./dce 100 | MACSHA=$(IFS=' '; read -ra ADDR <<< $(sha256sum $MACFILE); echo "${ADDR[0]}") 101 | cat> ../release.md <<- EOF 102 | | File | SHA256 | 103 | |---|---| 104 | | $MACFILE | $MACSHA | 105 | | $LINFILE | $LINSHA | 106 | | $WINFILE | $WINSHA | 107 | EOF 108 | displayName: 'Build and zip' 109 | 110 | # Publish a Github Release for tagged commits 111 | # See https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/github-release?view=azure-devops 112 | - task: GithubRelease@0 113 | displayName: 'Create GitHub Release' 114 | inputs: 115 | action: create 116 | tagSource: 'auto' 117 | gitHubConnection: Github 118 | repositoryName: Optum/dce-cli 119 | releaseNotesFile: | 120 | ./release.md 121 | assets: | 122 | ./dist/* 123 | -------------------------------------------------------------------------------- /client/c_o_r_s/options_leases_id_auth_parameters.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-swagger; DO NOT EDIT. 2 | 3 | package c_o_r_s 4 | 5 | // This file was generated by the swagger tool. 6 | // Editing this file might prove futile when you re-run the swagger generate command 7 | 8 | import ( 9 | "context" 10 | "net/http" 11 | "time" 12 | 13 | "github.com/go-openapi/errors" 14 | "github.com/go-openapi/runtime" 15 | cr "github.com/go-openapi/runtime/client" 16 | 17 | strfmt "github.com/go-openapi/strfmt" 18 | ) 19 | 20 | // NewOptionsLeasesIDAuthParams creates a new OptionsLeasesIDAuthParams object 21 | // with the default values initialized. 22 | func NewOptionsLeasesIDAuthParams() *OptionsLeasesIDAuthParams { 23 | 24 | return &OptionsLeasesIDAuthParams{ 25 | 26 | timeout: cr.DefaultTimeout, 27 | } 28 | } 29 | 30 | // NewOptionsLeasesIDAuthParamsWithTimeout creates a new OptionsLeasesIDAuthParams object 31 | // with the default values initialized, and the ability to set a timeout on a request 32 | func NewOptionsLeasesIDAuthParamsWithTimeout(timeout time.Duration) *OptionsLeasesIDAuthParams { 33 | 34 | return &OptionsLeasesIDAuthParams{ 35 | 36 | timeout: timeout, 37 | } 38 | } 39 | 40 | // NewOptionsLeasesIDAuthParamsWithContext creates a new OptionsLeasesIDAuthParams object 41 | // with the default values initialized, and the ability to set a context for a request 42 | func NewOptionsLeasesIDAuthParamsWithContext(ctx context.Context) *OptionsLeasesIDAuthParams { 43 | 44 | return &OptionsLeasesIDAuthParams{ 45 | 46 | Context: ctx, 47 | } 48 | } 49 | 50 | // NewOptionsLeasesIDAuthParamsWithHTTPClient creates a new OptionsLeasesIDAuthParams object 51 | // with the default values initialized, and the ability to set a custom HTTPClient for a request 52 | func NewOptionsLeasesIDAuthParamsWithHTTPClient(client *http.Client) *OptionsLeasesIDAuthParams { 53 | 54 | return &OptionsLeasesIDAuthParams{ 55 | HTTPClient: client, 56 | } 57 | } 58 | 59 | /*OptionsLeasesIDAuthParams contains all the parameters to send to the API endpoint 60 | for the options leases ID auth operation typically these are written to a http.Request 61 | */ 62 | type OptionsLeasesIDAuthParams struct { 63 | timeout time.Duration 64 | Context context.Context 65 | HTTPClient *http.Client 66 | } 67 | 68 | // WithTimeout adds the timeout to the options leases ID auth params 69 | func (o *OptionsLeasesIDAuthParams) WithTimeout(timeout time.Duration) *OptionsLeasesIDAuthParams { 70 | o.SetTimeout(timeout) 71 | return o 72 | } 73 | 74 | // SetTimeout adds the timeout to the options leases ID auth params 75 | func (o *OptionsLeasesIDAuthParams) SetTimeout(timeout time.Duration) { 76 | o.timeout = timeout 77 | } 78 | 79 | // WithContext adds the context to the options leases ID auth params 80 | func (o *OptionsLeasesIDAuthParams) WithContext(ctx context.Context) *OptionsLeasesIDAuthParams { 81 | o.SetContext(ctx) 82 | return o 83 | } 84 | 85 | // SetContext adds the context to the options leases ID auth params 86 | func (o *OptionsLeasesIDAuthParams) SetContext(ctx context.Context) { 87 | o.Context = ctx 88 | } 89 | 90 | // WithHTTPClient adds the HTTPClient to the options leases ID auth params 91 | func (o *OptionsLeasesIDAuthParams) WithHTTPClient(client *http.Client) *OptionsLeasesIDAuthParams { 92 | o.SetHTTPClient(client) 93 | return o 94 | } 95 | 96 | // SetHTTPClient adds the HTTPClient to the options leases ID auth params 97 | func (o *OptionsLeasesIDAuthParams) SetHTTPClient(client *http.Client) { 98 | o.HTTPClient = client 99 | } 100 | 101 | // WriteToRequest writes these params to a swagger request 102 | func (o *OptionsLeasesIDAuthParams) WriteToRequest(r runtime.ClientRequest, reg strfmt.Registry) error { 103 | 104 | if err := r.SetTimeout(o.timeout); err != nil { 105 | return err 106 | } 107 | var res []error 108 | 109 | if len(res) > 0 { 110 | return errors.CompositeValidationError(res...) 111 | } 112 | return nil 113 | } 114 | --------------------------------------------------------------------------------