Skip to content

Commit 2cfd1f4

Browse files
Object file parameter (#3487)
* feat: support @ prefix for object parameters from files Enable users to load object-type parameters from JSON files using the @ prefix syntax, similar to curl and kubectl. This provides a convenient way to pass complex configuration objects without inline JSON strings. Usage: porter install --param config=@/path/to/config.json porter install --param config='{"key": "value"}' Parameter sets also support @ prefix: parameters: - name: config source: value: @/path/to/config.json Security considerations: - Only applies to user-provided values (CLI flags/parameter sets) - Does NOT work with default values in bundle definitions - Validates JSON structure before processing - Clear error messages for missing files or invalid JSON Changes: - Add @ prefix detection in getUnconvertedValueFromRaw() - Read and validate JSON file contents for object parameters - Add comprehensive unit tests covering success/error cases - Add test fixtures for valid/invalid JSON scenarios Signed-off-by: Kim Christensen <[email protected]> * test: add integration tests for object parameter files Add comprehensive integration tests for object-type parameters loaded from files using the @ prefix syntax. Tests cover: - CLI parameter with @ prefix reading from file - Inline JSON parameter without @ prefix - Parameter set with @ prefix - Error handling for missing files - Error handling for invalid JSON files Also adds test bundle that uses template syntax to access object parameter fields in bundle execution steps. Signed-off-by: Kim <[email protected]> Signed-off-by: Kim Christensen <[email protected]> * docs: add documentation for @ prefix file loading Update CLI help text and user documentation to describe the @ prefix syntax for loading object parameters from JSON files. Changes include: - Updated --param flag help text with @ prefix example - Added @ prefix examples to install/upgrade/invoke commands - Added "Object Parameters from Files" section to intro docs - Updated quickstart guide with @ prefix usage - Enhanced parameter set file format documentation - Added example of @ prefix in parameter set YAML The documentation emphasizes the security constraint that @ prefix only works for user-provided values, not defaults. Signed-off-by: Kim <[email protected]> Signed-off-by: Kim Christensen <[email protected]> * docs: Update generated documentation files Signed-off-by: Kim Christensen <[email protected]> * docs: use path source in parameter sets for file loading Update documentation to describe the proper `path` source syntax for parameter set definitions instead of the `@` prefix. Changes: - Clarify that `@` prefix is only for CLI --param flags - Add comprehensive examples showing `path` source in both YAML and JSON format for parameter set definitions - Update parameter set example to use schemaVersion 1.1.0 - Remove incorrect documentation about `@` prefix in value sources - Distinguish between CLI usage (@Prefix) and parameter set usage (path source) The `path` source is the correct way to reference files in parameter set definitions, while the `@` prefix remains a convenient shortcut for command-line parameter overrides. Signed-off-by: Kim Christensen <[email protected]> * ci: add object_param_test to integration test workflows Signed-off-by: Kim Christensen <[email protected]> --------- Signed-off-by: Kim Christensen <[email protected]> Signed-off-by: Kim <[email protected]>
1 parent 25490ab commit 2cfd1f4

File tree

22 files changed

+486
-14
lines changed

22 files changed

+486
-14
lines changed

.github/workflows/porter-integration-pr.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ jobs:
8181
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
8282
with:
8383
test_name: outputs_test
84+
object_param_integration_test:
85+
name: Object Param Integration Test
86+
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
87+
with:
88+
test_name: object_param_test
8489
publish_integration_test:
8590
name: Publish Integration Test
8691
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main

.github/workflows/porter-integration-release.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ jobs:
9292
with:
9393
test_name: outputs_test
9494
registry: ${{inputs.registry}}
95+
object_param_integration_test:
96+
name: Object Param Integration Test
97+
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main
98+
with:
99+
test_name: object_param_test
100+
registry: ${{inputs.registry}}
95101
publish_integration_test:
96102
name: Publish Integration Test
97103
uses: getporter/porter/.github/workflows/integ-reuseable-workflow.yml@main

cmd/porter/installations.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ The docker driver runs the bundle container using the local Docker host. To use
237237
porter installation install --reference localhost:5000/ghcr.io/getporter/examples/kubernetes:v0.2.0 --insecure-registry --force
238238
porter installation install MyAppInDev --file myapp/bundle.json
239239
porter installation install --parameter-set azure --param test-mode=true --param header-color=blue
240+
porter installation install --param [email protected]
240241
porter installation install --credential-set azure --credential-set kubernetes
241242
porter installation install --driver debug
242243
porter installation install --label env=dev --label owner=myuser
@@ -287,6 +288,7 @@ The docker driver runs the bundle container using the local Docker host. To use
287288
porter installation upgrade --reference localhost:5000/ghcr.io/getporter/examples/kubernetes:v0.2.0 --insecure-registry --force
288289
porter installation upgrade MyAppInDev --file myapp/bundle.json
289290
porter installation upgrade --parameter-set azure --param test-mode=true --param header-color=blue
291+
porter installation upgrade --param [email protected]
290292
porter installation upgrade --credential-set azure --credential-set kubernetes
291293
porter installation upgrade --driver debug
292294
`,
@@ -337,6 +339,7 @@ The docker driver runs the bundle container using the local Docker host. To use
337339
porter installation invoke --reference localhost:5000/ghcr.io/getporter/examples/kubernetes:v0.2.0 --insecure-registry --force
338340
porter installation invoke --action ACTION MyAppInDev --file myapp/bundle.json
339341
porter installation invoke --action ACTION --parameter-set azure --param test-mode=true --param header-color=blue
342+
porter installation invoke --action ACTION --param [email protected]
340343
porter installation invoke --action ACTION --credential-set azure --credential-set kubernetes
341344
porter installation invoke --action ACTION --driver debug
342345
`,
@@ -427,7 +430,7 @@ func addBundleActionFlags(f *pflag.FlagSet, actionOpts porter.BundleAction) {
427430
f.StringArrayVarP(&opts.ParameterSets, "parameter-set", "p", nil,
428431
"Parameter sets to use when running the bundle. It should be a named set of parameters and may be specified multiple times.")
429432
f.StringArrayVar(&opts.Params, "param", nil,
430-
"Define an individual parameter in the form NAME=VALUE. Overrides parameters otherwise set via --parameter-set. May be specified multiple times.")
433+
"Define an individual parameter in the form NAME=VALUE. Overrides parameters otherwise set via --parameter-set. May be specified multiple times. For object parameters, use @FILEPATH to load JSON from a file (e.g., --param [email protected]).")
431434
f.StringArrayVarP(&opts.CredentialIdentifiers, "credential-set", "c", nil,
432435
"Credential sets to use when running the bundle. It should be a named set of credentials and may be specified multiple times.")
433436
f.StringVarP(&opts.Driver, "driver", "d", porter.DefaultDriver,

docs/content/docs/introduction/concepts-and-components/intro-parameters.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,56 @@ parameter override is `--param`.
6464
For example, you may decide to override the `db_name` parameter for a given
6565
installation via `porter install --param db_name=mydb -p myparamset`.
6666

67+
### Object Parameters from Files
68+
69+
For object-type parameters, you can load JSON data from a file in two ways:
70+
71+
**Using the `@` prefix with CLI flags:**
72+
73+
```bash
74+
porter install --param [email protected]
75+
```
76+
77+
The `@` prefix is a convenient shortcut when passing parameters via the command line.
78+
79+
**Using the `path` source in parameter sets:**
80+
81+
For parameter set definitions, use the `path` source to reference files:
82+
83+
```yaml
84+
schemaType: ParameterSet
85+
schemaVersion: 1.1.0
86+
name: myparams
87+
parameters:
88+
- name: config
89+
source:
90+
path: "/path/to/config.json"
91+
```
92+
93+
Or in JSON format:
94+
95+
```json
96+
{
97+
"schemaType": "ParameterSet",
98+
"schemaVersion": "1.1.0",
99+
"name": "myparams",
100+
"parameters": [
101+
{
102+
"name": "config",
103+
"source": {
104+
"path": "/path/to/config.json"
105+
}
106+
}
107+
]
108+
}
109+
```
110+
111+
This feature:
112+
- Works with both `--param` CLI flags (using `@` prefix) and parameter sets (using `path` source)
113+
- The `path` source works for any parameter type, not just objects
114+
- Validates that the file contains valid JSON for object-type parameters before processing
115+
- **Security note**: Only user-provided values support file loading. Default values in bundle definitions cannot reference files for security reasons.
116+
67117
When a parameter's bundle definition is set to `sensitive=true`, the user-specified
68118
value will be stored into a secret store to prevent security leakage. See the [secrets
69119
plugin docs](/plugins/types/#secrets) to learn how porter uses an external secret store

docs/content/docs/quickstart/parameters.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,23 @@ For example:
4545
porter install --param name=Robin
4646
```
4747

48+
For object-type parameters, you can load JSON data from a file by prefixing the file path with `@`:
49+
50+
```
51+
porter install --param [email protected]
52+
```
53+
54+
The `@` prefix is supported for CLI parameters, allowing you to manage complex configurations in separate JSON files.
55+
This is particularly useful for object parameters that contain nested data structures.
56+
4857
When trying out a bundle, it might work well to set individual parameter values on the command line with the --param flag.
4958
Parameter sets store multiple parameters and pass them to a bundle using the parameter set name.
5059
With parameter sets you can avoid errors, and the requirement of remembering and manually configuring parameters at the command line.
5160
Parameter sets store the parameter name, and the source of the parameter value which could be a:
5261

5362
- hard-coded value
5463
- environment variable
55-
- file
64+
- file path
5665
- command
5766
- secret
5867

@@ -100,7 +109,7 @@ $ cat hello-llama.json
100109
# modify hello-llama.json with your editor to the content below
101110
{
102111
"schemaType": "ParameterSet",
103-
"schemaVersion": "1.0.1",
112+
"schemaVersion": "1.1.0",
104113
"name": "hello-llama",
105114
"parameters": [
106115
{
@@ -112,7 +121,7 @@ $ cat hello-llama.json
112121
]
113122
}
114123
$ porter parameters apply hello-llama.json
115-
Applied /hello-llama parameter se
124+
Applied /hello-llama parameter set
116125
```
117126

118127
This creates a parameter set named hello-llama.

docs/content/docs/references/cli/install.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ porter install [INSTALLATION] [flags]
3636
porter install --reference localhost:5000/ghcr.io/getporter/examples/kubernetes:v0.2.0 --insecure-registry --force
3737
porter install MyAppInDev --file myapp/bundle.json
3838
porter install --parameter-set azure --param test-mode=true --param header-color=blue
39+
porter install --param [email protected]
3940
porter install --credential-set azure --credential-set kubernetes
4041
porter install --driver debug
4142
porter install --label env=dev --label owner=myuser
@@ -59,7 +60,7 @@ porter install [INSTALLATION] [flags]
5960
--mount-host-volume stringArray Mount a host volume into the bundle. Format is <host path>:<container path>[:<option>]. May be specified multiple times. Option can be ro (read-only), rw (read-write), default is ro.
6061
-n, --namespace string Create the installation in the specified namespace. Defaults to the global namespace.
6162
--no-logs Do not persist the bundle execution logs
62-
--param stringArray Define an individual parameter in the form NAME=VALUE. Overrides parameters otherwise set via --parameter-set. May be specified multiple times.
63+
--param stringArray Define an individual parameter in the form NAME=VALUE. Overrides parameters otherwise set via --parameter-set. May be specified multiple times. For object parameters, use @FILEPATH to load JSON from a file (e.g., --param [email protected]).
6364
-p, --parameter-set stringArray Parameter sets to use when running the bundle. It should be a named set of parameters and may be specified multiple times.
6465
-r, --reference string Use a bundle in an OCI registry specified by the given reference.
6566
--verify-bundle Verify the bundle signature before executing

docs/content/docs/references/cli/installations_install.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ porter installations install [INSTALLATION] [flags]
3636
porter installation install --reference localhost:5000/ghcr.io/getporter/examples/kubernetes:v0.2.0 --insecure-registry --force
3737
porter installation install MyAppInDev --file myapp/bundle.json
3838
porter installation install --parameter-set azure --param test-mode=true --param header-color=blue
39+
porter installation install --param [email protected]
3940
porter installation install --credential-set azure --credential-set kubernetes
4041
porter installation install --driver debug
4142
porter installation install --label env=dev --label owner=myuser
@@ -59,7 +60,7 @@ porter installations install [INSTALLATION] [flags]
5960
--mount-host-volume stringArray Mount a host volume into the bundle. Format is <host path>:<container path>[:<option>]. May be specified multiple times. Option can be ro (read-only), rw (read-write), default is ro.
6061
-n, --namespace string Create the installation in the specified namespace. Defaults to the global namespace.
6162
--no-logs Do not persist the bundle execution logs
62-
--param stringArray Define an individual parameter in the form NAME=VALUE. Overrides parameters otherwise set via --parameter-set. May be specified multiple times.
63+
--param stringArray Define an individual parameter in the form NAME=VALUE. Overrides parameters otherwise set via --parameter-set. May be specified multiple times. For object parameters, use @FILEPATH to load JSON from a file (e.g., --param [email protected]).
6364
-p, --parameter-set stringArray Parameter sets to use when running the bundle. It should be a named set of parameters and may be specified multiple times.
6465
-r, --reference string Use a bundle in an OCI registry specified by the given reference.
6566
--verify-bundle Verify the bundle signature before executing

docs/content/docs/references/cli/installations_invoke.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ porter installations invoke [INSTALLATION] --action ACTION [flags]
3434
porter installation invoke --reference localhost:5000/ghcr.io/getporter/examples/kubernetes:v0.2.0 --insecure-registry --force
3535
porter installation invoke --action ACTION MyAppInDev --file myapp/bundle.json
3636
porter installation invoke --action ACTION --parameter-set azure --param test-mode=true --param header-color=blue
37+
porter installation invoke --action ACTION --param [email protected]
3738
porter installation invoke --action ACTION --credential-set azure --credential-set kubernetes
3839
porter installation invoke --action ACTION --driver debug
3940
@@ -56,7 +57,7 @@ porter installations invoke [INSTALLATION] --action ACTION [flags]
5657
--mount-host-volume stringArray Mount a host volume into the bundle. Format is <host path>:<container path>[:<option>]. May be specified multiple times. Option can be ro (read-only), rw (read-write), default is ro.
5758
-n, --namespace string Namespace of the specified installation. Defaults to the global namespace.
5859
--no-logs Do not persist the bundle execution logs
59-
--param stringArray Define an individual parameter in the form NAME=VALUE. Overrides parameters otherwise set via --parameter-set. May be specified multiple times.
60+
--param stringArray Define an individual parameter in the form NAME=VALUE. Overrides parameters otherwise set via --parameter-set. May be specified multiple times. For object parameters, use @FILEPATH to load JSON from a file (e.g., --param [email protected]).
6061
-p, --parameter-set stringArray Parameter sets to use when running the bundle. It should be a named set of parameters and may be specified multiple times.
6162
-r, --reference string Use a bundle in an OCI registry specified by the given reference.
6263
```

docs/content/docs/references/cli/installations_uninstall.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ porter installations uninstall [INSTALLATION] [flags]
5959
--mount-host-volume stringArray Mount a host volume into the bundle. Format is <host path>:<container path>[:<option>]. May be specified multiple times. Option can be ro (read-only), rw (read-write), default is ro.
6060
-n, --namespace string Namespace of the specified installation. Defaults to the global namespace.
6161
--no-logs Do not persist the bundle execution logs
62-
--param stringArray Define an individual parameter in the form NAME=VALUE. Overrides parameters otherwise set via --parameter-set. May be specified multiple times.
62+
--param stringArray Define an individual parameter in the form NAME=VALUE. Overrides parameters otherwise set via --parameter-set. May be specified multiple times. For object parameters, use @FILEPATH to load JSON from a file (e.g., --param [email protected]).
6363
-p, --parameter-set stringArray Parameter sets to use when running the bundle. It should be a named set of parameters and may be specified multiple times.
6464
-r, --reference string Use a bundle in an OCI registry specified by the given reference.
6565
```

docs/content/docs/references/cli/installations_upgrade.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ porter installations upgrade [INSTALLATION] [flags]
3434
porter installation upgrade --reference localhost:5000/ghcr.io/getporter/examples/kubernetes:v0.2.0 --insecure-registry --force
3535
porter installation upgrade MyAppInDev --file myapp/bundle.json
3636
porter installation upgrade --parameter-set azure --param test-mode=true --param header-color=blue
37+
porter installation upgrade --param [email protected]
3738
porter installation upgrade --credential-set azure --credential-set kubernetes
3839
porter installation upgrade --driver debug
3940
@@ -56,7 +57,7 @@ porter installations upgrade [INSTALLATION] [flags]
5657
--mount-host-volume stringArray Mount a host volume into the bundle. Format is <host path>:<container path>[:<option>]. May be specified multiple times. Option can be ro (read-only), rw (read-write), default is ro.
5758
-n, --namespace string Namespace of the specified installation. Defaults to the global namespace.
5859
--no-logs Do not persist the bundle execution logs
59-
--param stringArray Define an individual parameter in the form NAME=VALUE. Overrides parameters otherwise set via --parameter-set. May be specified multiple times.
60+
--param stringArray Define an individual parameter in the form NAME=VALUE. Overrides parameters otherwise set via --parameter-set. May be specified multiple times. For object parameters, use @FILEPATH to load JSON from a file (e.g., --param [email protected]).
6061
-p, --parameter-set stringArray Parameter sets to use when running the bundle. It should be a named set of parameters and may be specified multiple times.
6162
-r, --reference string Use a bundle in an OCI registry specified by the given reference.
6263
--version string Version to which the installation should be upgraded. This represents the version of the bundle, which assumes the convention of setting the bundle tag to its version.

0 commit comments

Comments
 (0)