-
Notifications
You must be signed in to change notification settings - Fork 12
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
✨ Inject typed values. #142
Conversation
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
Signed-off-by: Jeff Ortel <[email protected]>
cmd/injector.go
Outdated
err = errors.New("expected: int|boolean|string") | ||
} | ||
default: | ||
err = errors.New("expected: integer|boolean") |
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 is this only integer|boolean
?
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 added string afterwards and forgot to add here. Fixed.
switch strings.ToLower(f.Type) { | ||
case "string": | ||
cast = fmt.Sprintf("%v", object) | ||
case "integer": |
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.
Consider supporting case "integer" | "int"
and case "boolean" | "bool"
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.
Thinking longer form of integer|boolean|string would be more language (Go) agnostic. Also, supporting the shorter forms would be more to document. Seemed like less/simpler choices would be best.
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.
Overall changes look good, tests look good too
Signed-off-by: Jeff Ortel <[email protected]>
Inject variables using true or _cast_ types when variable references not embedded in other text. Consider: ``` metadata: provider: address: localhost:$(PORT) initConfig: - providerSpecificConfig: mavenInsecure: $(maven.insecure) mavenSettingsFile: $(maven.settings.path) name: java resources: - selector: identity:kind=maven fields: - key: maven.settings.path name: settings path: /shared/creds/maven/settings.xml - selector: setting:key=mvn.insecure.enabled fields: - key: maven.insecure name: value ``` For example: ``` mavenInsecure = $(maven.insecure) ``` $(maven.insecure) has a _true_ type of boolean (as stored in the db) so it will be injected as: ```yaml mavenInsecure: true ``` For cases when the _true_ type is different, an optional `type` field may be used to cast. In the previous example, if maven.insecure was stored as a string "true" but need to be injected as a boolean, the type field may be used. ``` - selector: setting:key=mvn.insecure.enabled fields: - key: maven.insecure name: value type: boolean ``` While we're at it, (and to help with testing), support for _default_ values added. ``` - selector: setting:key=mvn.insecure.enabled fields: - key: maven.insecure name: value type: boolean default: false ``` --------- Signed-off-by: Jeff Ortel <[email protected]> Signed-off-by: Cherry Picker <[email protected]>
Inject variables using true or _cast_ types when variable references not embedded in other text. Consider: ``` metadata: provider: address: localhost:$(PORT) initConfig: - providerSpecificConfig: mavenInsecure: $(maven.insecure) mavenSettingsFile: $(maven.settings.path) name: java resources: - selector: identity:kind=maven fields: - key: maven.settings.path name: settings path: /shared/creds/maven/settings.xml - selector: setting:key=mvn.insecure.enabled fields: - key: maven.insecure name: value ``` For example: ``` mavenInsecure = $(maven.insecure) ``` $(maven.insecure) has a _true_ type of boolean (as stored in the db) so it will be injected as: ```yaml mavenInsecure: true ``` For cases when the _true_ type is different, an optional `type` field may be used to cast. In the previous example, if maven.insecure was stored as a string "true" but need to be injected as a boolean, the type field may be used. ``` - selector: setting:key=mvn.insecure.enabled fields: - key: maven.insecure name: value type: boolean ``` While we're at it, (and to help with testing), support for _default_ values added. ``` - selector: setting:key=mvn.insecure.enabled fields: - key: maven.insecure name: value type: boolean default: false ``` --------- Signed-off-by: Jeff Ortel <[email protected]> (cherry picked from commit 5e4a70d)
Inject variables using true or cast types when variable references not embedded in other text.
Consider:
For example:
$(maven.insecure) has a true type of boolean (as stored in the db) so it will be injected as:
For cases when the true type is different, an optional
type
field may be used to cast. In the previous example, if maven.insecure was stored as a string "true" but need to be injected as a boolean, the type field may be used.While we're at it, (and to help with testing), support for default values added.