@@ -4,15 +4,13 @@ import (
4
4
"context"
5
5
"errors"
6
6
"fmt"
7
- "strings"
8
7
9
8
"get.porter.sh/porter/pkg/cache"
10
9
"get.porter.sh/porter/pkg/cnab"
11
10
"get.porter.sh/porter/pkg/cnab/bundleruntime"
12
11
"get.porter.sh/porter/pkg/cnab/drivers"
13
12
"get.porter.sh/porter/pkg/encoding"
14
13
"get.porter.sh/porter/pkg/portercontext"
15
- "get.porter.sh/porter/pkg/secrets"
16
14
"get.porter.sh/porter/pkg/storage"
17
15
"get.porter.sh/porter/pkg/tracing"
18
16
"github.com/opencontainers/go-digest"
@@ -61,14 +59,8 @@ type BundleExecutionOptions struct {
61
59
// Driver is the CNAB-compliant driver used to run bundle actions.
62
60
Driver string
63
61
64
- // parsedParams is the parsed set of parameters from Params.
65
- parsedParams map [string ]string
66
-
67
- // parsedParamSets is the parsed set of parameter from ParameterSets
68
- parsedParamSets map [string ]string
69
-
70
- // combinedParameters is parsedParams merged on top of parsedParamSets.
71
- combinedParameters map [string ]string
62
+ // parameters that are intended for dependencies
63
+ depParams map [string ]string
72
64
}
73
65
74
66
func NewBundleExecutionOptions () * BundleExecutionOptions {
@@ -86,12 +78,6 @@ func (o *BundleExecutionOptions) Validate(ctx context.Context, args []string, p
86
78
return err
87
79
}
88
80
89
- // Only validate the syntax of the --param flags
90
- // We will validate the parameter sets later once we have the bundle loaded.
91
- if err := o .parseParams (); err != nil {
92
- return err
93
- }
94
-
95
81
o .defaultDriver (p )
96
82
if err := o .validateDriver (p .Context ); err != nil {
97
83
return err
@@ -100,101 +86,6 @@ func (o *BundleExecutionOptions) Validate(ctx context.Context, args []string, p
100
86
return nil
101
87
}
102
88
103
- // LoadParameters validates and resolves the parameters and sets. It must be
104
- // called after porter has loaded the bundle definition.
105
- func (o * BundleExecutionOptions ) LoadParameters (ctx context.Context , p * Porter , bun cnab.ExtendedBundle ) error {
106
- // This is called in multiple code paths, so exit early if
107
- // we have already loaded the parameters into combinedParameters
108
- if o .combinedParameters != nil {
109
- return nil
110
- }
111
-
112
- err := o .parseParams ()
113
- if err != nil {
114
- return err
115
- }
116
-
117
- err = o .parseParamSets (ctx , p , bun )
118
- if err != nil {
119
- return err
120
- }
121
-
122
- o .combinedParameters = o .combineParameters (p .Context )
123
-
124
- return nil
125
- }
126
-
127
- // parsedParams parses the variable assignments in Params.
128
- func (o * BundleExecutionOptions ) parseParams () error {
129
- p , err := storage .ParseVariableAssignments (o .Params )
130
- if err != nil {
131
- return err
132
- }
133
-
134
- o .parsedParams = p
135
- return nil
136
- }
137
-
138
- func (o * BundleExecutionOptions ) populateInternalParameterSet (ctx context.Context , p * Porter , bun cnab.ExtendedBundle , i * storage.Installation ) error {
139
- strategies := make ([]secrets.Strategy , 0 , len (o .parsedParams ))
140
- for name , value := range o .parsedParams {
141
- strategies = append (strategies , storage .ValueStrategy (name , value ))
142
- }
143
-
144
- strategies , err := p .Sanitizer .CleanParameters (ctx , strategies , bun , i .ID )
145
- if err != nil {
146
- return err
147
- }
148
-
149
- if len (strategies ) == 0 {
150
- // if no override is specified, clear out the old parameters on the
151
- // installation record
152
- i .Parameters .Parameters = nil
153
- return nil
154
- }
155
-
156
- i .Parameters = i .NewInternalParameterSet (strategies ... )
157
-
158
- return nil
159
- }
160
-
161
- // parseParamSets parses the variable assignments in ParameterSets.
162
- func (o * BundleExecutionOptions ) parseParamSets (ctx context.Context , p * Porter , bun cnab.ExtendedBundle ) error {
163
- if len (o .ParameterSets ) > 0 {
164
- parsed , err := p .loadParameterSets (ctx , bun , o .Namespace , o .ParameterSets )
165
- if err != nil {
166
- return fmt .Errorf ("unable to process provided parameter sets: %w" , err )
167
- }
168
- o .parsedParamSets = parsed
169
- }
170
- return nil
171
- }
172
-
173
- // Combine the parameters into a single map
174
- // The params set on the command line take precedence over the params set in
175
- // parameter set files
176
- // Anything set multiple times, is decided by "last one set wins"
177
- func (o * BundleExecutionOptions ) combineParameters (c * portercontext.Context ) map [string ]string {
178
- final := make (map [string ]string )
179
-
180
- for k , v := range o .parsedParamSets {
181
- final [k ] = v
182
- }
183
-
184
- for k , v := range o .parsedParams {
185
- final [k ] = v
186
- }
187
-
188
- //
189
- // Default the porter-debug param to --debug
190
- //
191
- if o .DebugMode {
192
- final ["porter-debug" ] = "true"
193
- }
194
-
195
- return final
196
- }
197
-
198
89
// defaultDriver supplies the default driver if none is specified
199
90
func (o * BundleExecutionOptions ) defaultDriver (p * Porter ) {
200
91
//
@@ -358,23 +249,10 @@ func (p *Porter) BuildActionArgs(ctx context.Context, installation storage.Insta
358
249
359
250
// Resolve the final set of typed parameters, taking into account the user overrides, parameter sources
360
251
// and defaults
361
- err = opts .LoadParameters (ctx , p , opts .bundleRef .Definition )
362
- if err != nil {
363
- return bundleruntime.ActionArguments {}, err
364
- }
365
-
366
252
log .Debugf ("resolving parameters for installation %s" , installation )
367
253
368
- // Do not resolve parameters from dependencies
369
- params := make (map [string ]string , len (opts .combinedParameters ))
370
- for k , v := range opts .combinedParameters {
371
- if strings .Contains (k , "#" ) {
372
- continue
373
- }
374
- params [k ] = v
375
- }
376
-
377
- resolvedParams , err := p .resolveParameters (ctx , installation , bundleRef .Definition , action .GetAction (), params )
254
+ // TODO: I think this gets called twice sometimes, maybe have a short circuit check that we've done it already? Can we remove it from here and assume it was done elsewhere?
255
+ resolvedParams , err := p .applyActionToInstallation (ctx , action , & installation )
378
256
if err != nil {
379
257
return bundleruntime.ActionArguments {}, log .Error (err )
380
258
}
0 commit comments