Repository navigation
Adding a token for deploy-from-url LMCROSSITXSADEPLOY-3391 #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
s-yonkov-yonkov
wants to merge
1
commit into
master
Choose a base branch
from
feature/LMCROSSITXSADEPLOY-3391
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,8 +58,14 @@ const ( | |
| shouldBackupPreviousVersionOpt = "backup-previous-version" | ||
| requireSecureParameters = "require-secure-parameters" | ||
| disposableUserProvidedServiceOpt = "disposable-user-provided-service" | ||
| urlTokenOpt = "url-token" | ||
| ) | ||
|
|
||
| // urlTokenEnv is the environment variable fallback for the deploy-from-URL bearer token. Preferring | ||
| // an env var keeps the secret out of shell history and the process list; the --url-token flag | ||
| // overrides it when both are set. | ||
| const urlTokenEnv = "MULTIAPPS_URL_TOKEN" | ||
|
|
||
| type listFlag struct { | ||
| elements []string | ||
| } | ||
|
|
@@ -123,7 +129,7 @@ func (c *DeployCommand) GetPluginCommand() plugin.Command { | |
| cf deploy -i OPERATION_ID -a ACTION [-u URL] | ||
|
|
||
| Deploy a multi-target app archive referenced by a remote URL | ||
| <write MTA archive URL to STDOUT> | cf deploy [-e EXT_DESCRIPTOR[,...]] [-t TIMEOUT] [--version-rule VERSION_RULE] [-u MTA_CONTROLLER_URL] [--retries RETRIES] [--no-start] [--namespace NAMESPACE] [--apply-namespace-app-names true/false] [--apply-namespace-service-names true/false] [--apply-namespace-app-routes true/false] [--apply-namespace-as-suffix true/false ] [--delete-services] [--delete-service-keys] [--delete-service-brokers] [--keep-files] [--no-restart-subscribed-apps] [--do-not-fail-on-missing-permissions] [--abort-on-error] [--strategy STRATEGY] [--skip-testing-phase] [--skip-idle-start] [require-secure-parameters] [--disposable-user-provided-service] [--apps-start-timeout TIMEOUT] [--apps-stage-timeout TIMEOUT] [--apps-upload-timeout TIMEOUT] [--apps-task-execution-timeout TIMEOUT]` + util.UploadEnvHelpText, | ||
| <write MTA archive URL to STDOUT> | cf deploy [-e EXT_DESCRIPTOR[,...]] [-t TIMEOUT] [--version-rule VERSION_RULE] [-u MTA_CONTROLLER_URL] [--retries RETRIES] [--no-start] [--namespace NAMESPACE] [--apply-namespace-app-names true/false] [--apply-namespace-service-names true/false] [--apply-namespace-app-routes true/false] [--apply-namespace-as-suffix true/false ] [--delete-services] [--delete-service-keys] [--delete-service-brokers] [--keep-files] [--no-restart-subscribed-apps] [--do-not-fail-on-missing-permissions] [--abort-on-error] [--strategy STRATEGY] [--skip-testing-phase] [--skip-idle-start] [require-secure-parameters] [--disposable-user-provided-service] [--url-token TOKEN] [--apps-start-timeout TIMEOUT] [--apps-stage-timeout TIMEOUT] [--apps-upload-timeout TIMEOUT] [--apps-task-execution-timeout TIMEOUT]` + util.UploadEnvHelpText, | ||
|
|
||
| Options: map[string]string{ | ||
| extDescriptorsOpt: "Extension descriptors", | ||
|
|
@@ -161,6 +167,7 @@ func (c *DeployCommand) GetPluginCommand() plugin.Command { | |
| util.GetShortOption(dependencyAwareStopOrderOpt): "(EXPERIMENTAL) (STRATEGY: BLUE-GREEN, INCREMENTAL-BLUE-GREEN) Stop apps in a dependency-aware order during the resume phase of a blue-green deployment", | ||
| util.GetShortOption(requireSecureParameters): "(EXPERIMENTAL) Pass secrets to the deploy service in a secure way", | ||
| util.GetShortOption(disposableUserProvidedServiceOpt): "Deploy when --require-secure-parameters flag is active for disposable UPS to be created and then deleted at the of the operation", | ||
| util.GetShortOption(urlTokenOpt): "(URL DEPLOY) Bearer token used to authenticate the fetch of the MTA archive from the remote URL (e.g. a GitHub token). Falls back to the MULTIAPPS_URL_TOKEN environment variable, which is preferred so the token does not appear in shell history", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why did you add (URL DEPLOY) to the description? |
||
| }, | ||
| }, | ||
| } | ||
|
|
@@ -217,6 +224,7 @@ func (c *DeployCommand) defineCommandOptions(flags *flag.FlagSet) { | |
| flags.Bool(deleteServicesOpt, false, "") | ||
| flags.Bool(noStartOpt, false, "") | ||
| flags.String(namespaceOpt, "", "") | ||
| flags.String(urlTokenOpt, "", "") | ||
| flags.String(applyNamespaceAppNamesOpt, "", "") | ||
| flags.String(applyNamespaceServiceNamesOpt, "", "") | ||
| flags.String(applyNamespaceAppRoutesOpt, "", "") | ||
|
|
@@ -298,7 +306,8 @@ func (c *DeployCommand) executeInternal(positionalArgs []string, dsHost string, | |
| var fileId string | ||
| var schemaVersion string | ||
|
|
||
| asyncUploadJobResult := c.uploadFromUrl(mtaArchive, mtaClient, namespace, disableProgressBar) | ||
| urlToken := resolveUrlToken(GetStringOpt(urlTokenOpt, flags)) | ||
| asyncUploadJobResult := c.uploadFromUrl(mtaArchive, urlToken, mtaClient, namespace, disableProgressBar) | ||
| if asyncUploadJobResult.ExecutionStatus == Failure { | ||
| return Failure | ||
| } | ||
|
|
@@ -498,21 +507,31 @@ func parseMtaArchiveArgument(rawMtaArchive interface{}) (bool, string) { | |
| return false, "" | ||
| } | ||
|
|
||
| func (c *DeployCommand) uploadFromUrl(url string, mtaClient mtaclient.MtaClientOperations, namespace string, | ||
| // resolveUrlToken returns the deploy-from-URL bearer token, preferring the --url-token flag value and | ||
| // falling back to the MULTIAPPS_URL_TOKEN environment variable. Returns "" when neither is set, in | ||
| // which case no credentials are sent and the fetch behaves as before. | ||
| func resolveUrlToken(flagValue string) string { | ||
| if flagValue != "" { | ||
| return flagValue | ||
| } | ||
| return os.Getenv(urlTokenEnv) | ||
| } | ||
|
|
||
| func (c *DeployCommand) uploadFromUrl(url string, token string, mtaClient mtaclient.MtaClientOperations, namespace string, | ||
| disableProgressBar bool) UploadFromUrlStatus { | ||
| encodedFileUrl := base64.URLEncoding.EncodeToString([]byte(url)) | ||
| uploadStatus, _ := retrier.Execute[UploadFromUrlStatus](3, func() (UploadFromUrlStatus, error) { | ||
| progressBar := c.tryFetchMtarSize(url, disableProgressBar) | ||
| uploadFromUrlStatus := c.doUploadFromUrl(encodedFileUrl, mtaClient, namespace, progressBar) | ||
| uploadFromUrlStatus := c.doUploadFromUrl(encodedFileUrl, token, mtaClient, namespace, progressBar) | ||
| return uploadFromUrlStatus, nil | ||
| }, func(result UploadFromUrlStatus, err error) bool { | ||
| return shouldRetryUpload(result) | ||
| }) | ||
| return uploadStatus | ||
| } | ||
|
|
||
| func (c *DeployCommand) doUploadFromUrl(encodedFileUrl string, mtaClient mtaclient.MtaClientOperations, namespace string, progressBar *pb.ProgressBar) UploadFromUrlStatus { | ||
| responseHeaders, err := mtaClient.StartUploadMtaArchiveFromUrl(encodedFileUrl, &namespace) | ||
| func (c *DeployCommand) doUploadFromUrl(encodedFileUrl string, token string, mtaClient mtaclient.MtaClientOperations, namespace string, progressBar *pb.ProgressBar) UploadFromUrlStatus { | ||
| responseHeaders, err := mtaClient.StartUploadMtaArchiveFromUrl(encodedFileUrl, token, &namespace) | ||
| if err != nil { | ||
| var retryErr *baseclient.RetryAfterError | ||
| if errors.As(err, &retryErr) { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have to add this flag also to blue-green delpoy