Skip to content
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

Merged
merged 5 commits into from
Jan 9, 2025
Merged

Conversation

jortel
Copy link
Contributor

@jortel jortel commented Jan 9, 2025

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:

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

jortel added 4 commits January 8, 2025 16:19
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]>
@jortel jortel changed the title Inject typed values. ✨ Inject typed values. Jan 9, 2025
@dymurray dymurray added the cherry-pick/release-0.6 This PR should be cherry-picked to release-0.6 branch label Jan 9, 2025
cmd/injector.go Outdated
err = errors.New("expected: int|boolean|string")
}
default:
err = errors.New("expected: integer|boolean")
Copy link
Contributor

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?

Copy link
Contributor Author

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":
Copy link
Contributor

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"

Copy link
Contributor Author

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.

Copy link
Contributor

@dymurray dymurray left a 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]>
@jortel jortel merged commit 5e4a70d into konveyor:main Jan 9, 2025
7 checks passed
github-actions bot pushed a commit that referenced this pull request Jan 9, 2025
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]>
dymurray pushed a commit that referenced this pull request Jan 10, 2025
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick/release-0.6 This PR should be cherry-picked to release-0.6 branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants