-
Notifications
You must be signed in to change notification settings - Fork 42
Adding a new flag to the deploy command and the related new functionality in order to support the collecting of secrets and sending them to the backend #252
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
base: master
Are you sure you want to change the base?
Conversation
…lity in order to support the collecting of secrets and sending them to the backend LMCROSSITXSADEPLOY-2301
| 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] [--apps-start-timeout TIMEOUT] [--apps-stage-timeout TIMEOUT] [--apps-upload-timeout TIMEOUT] [--apps-task-execution-timeout TIMEOUT]` + util.UploadEnvHelpText, | ||
| (EXPERIMENTAL) Deploy a multi-target app archive referenced by a remote URL |
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.
why experimental here?
|
|
||
| var jsonObject map[string]interface{} | ||
|
|
||
| err2 := json.Unmarshal([]byte(envValue), &jsonObject) |
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.
can you reuse err?
| if GetBoolOpt(requireSecureParameters, flags) { | ||
| // Collect special ENVs: __MTA___<name>, __MTA_JSON___<name>, __MTA_CERT___<name> | ||
| parameters, err := secure_parameters.CollectFromEnv("__MTA") |
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.
This check happens after the upload of the mtar. Could be optimized so the validation is earlier to avoid unnecessary upload in case of some failure
| return result, nil | ||
| } | ||
|
|
||
| func BuildSecureExtension(parameters map[string]ParameterValue, mtaID string, schemaVersion string) ([]byte, error) { |
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.
extract in a separate file
| if schemaVersion == "" { | ||
| schemaVersion = "3.3" | ||
| } |
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.
let's not hardcode versions in client
| switch currentParameterValue.Type { | ||
| case typeJSON: | ||
| parametersDescriptor[name] = currentParameterValue.ObjectContent | ||
| default: | ||
| parametersDescriptor[name] = currentParameterValue.StringContent | ||
| } |
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.
You can add a new method on ParameterValue and use it here (currentParameterValue.getValue())
| func CollectFromEnv(prefix string) (map[string]ParameterValue, error) { | ||
| plainValue := prefix + "___" | ||
| jsonValue := prefix + "_JSON___" | ||
| certificateValue := prefix + "_CERT___" //X509value beacuse the certiciates are of type X509 (should be renamed) |
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.
Improve or remove the comment description
| return nil | ||
| } | ||
|
|
||
| func CollectFromEnv(prefix string) (map[string]ParameterValue, error) { |
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.
This method is quite long, try to shorten it, split in functions
| ObjectContent map[string]interface{} | ||
| } | ||
|
|
||
| func nameDuplicated(name, prefix string, result map[string]ParameterValue) error { |
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.
rename to something including "validate"
| envName := nameValuePair[:equalsIndex] | ||
| envValue := nameValuePair[equalsIndex+1:] | ||
|
|
||
| var name string |
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.
do you need to define here?
| func (c *DeployCommand) doesUpsExist(userProvidedServiceName string) (bool, error) { | ||
| servicesOutput, err := c.cliConnection.CliCommandWithoutTerminalOutput("services") | ||
| if err != nil { | ||
| return false, fmt.Errorf("Error while checking if the UPS for secure encryption exists: %w", err) | ||
| } | ||
| stringTable := strings.Join(servicesOutput, "\n") | ||
| return findServiceName(stringTable, userProvidedServiceName), nil |
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.
Can we call the v3/services here instead a command?
| return true, encryptionKey, nil | ||
| } | ||
|
|
||
| func getRandomEncryptionKey() (string, error) { |
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.
is there some library that can do this for us?
|
|
||
| userProvidedServiceName := getUpsName(mtaId, namespace) | ||
|
|
||
| isUpsCreated, _, err := c.validateUpsExistsOrElseCreateIt(userProvidedServiceName, "v1") |
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.
what is the idea of:
"keyId": "v1"
| for i := range encryptionKeyBytes { | ||
| encryptionKeyBytes[i] = alphabet[int(encryptionKeyBytes[i]&63)] | ||
| } | ||
|
|
||
| return string(encryptionKeyBytes), nil |
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.
Does this really creates a proper 256 bits keys? Why not something like:
func generateAES256Key() ([]byte, error) {
key := make([]byte, 32) // 256 bits
_, err := rand.Read(key)
if err != nil {
return nil, err
}
return string([]byte(fmt.Sprintf("%x", key))), nil
}
Why is alphabet needed?
LMCROSSITXSADEPLOY-2301