@@ -20,12 +20,10 @@ package cmd
2020import (
2121 "bytes"
2222 "context"
23- "errors"
2423 "fmt"
2524 "hpc-toolkit/pkg/config"
2625 "hpc-toolkit/pkg/logging"
2726 "hpc-toolkit/pkg/modulewriter"
28- "hpc-toolkit/pkg/validators"
2927 "os"
3028 "os/exec"
3129 "os/user"
@@ -34,8 +32,6 @@ import (
3432 "time"
3533
3634 "github.com/spf13/cobra"
37- "github.com/zclconf/go-cty/cty"
38- "gopkg.in/yaml.v3"
3935)
4036
4137func addCreateFlags (c * cobra.Command ) * cobra.Command {
@@ -183,82 +179,6 @@ func expandOrDie(cmd *cobra.Command, path string) (config.Blueprint, *config.Yam
183179 return bp , ctx
184180}
185181
186- // TODO: move to expand.go
187- func validateMaybeDie (bp config.Blueprint , ctx config.YamlCtx ) {
188- err := validators .Execute (bp )
189- if err == nil {
190- return
191- }
192- logging .Error ("%s" , renderError (err , ctx ))
193-
194- const errorMsg = `One or more blueprint validators has failed. See messages above for suggested
195- actions. General troubleshooting guidance and instructions for configuring validators are shown below.
196-
197- - https://goo.gle/hpc-toolkit-troubleshooting
198- - https://goo.gle/hpc-toolkit-validation
199-
200- Validators can be silenced or treated as warnings or errors:
201-
202- - https://goo.gle/hpc-toolkit-validation-levels
203- `
204- logging .Error ("%s" , errorMsg )
205-
206- switch bp .ValidationLevel {
207- case config .ValidationWarning :
208- {
209- logging .Error ("%s\n " , boldYellow ("Validation failures were treated as a warning, continuing to create blueprint." ))
210- }
211- case config .ValidationError :
212- {
213- logging .Fatal ("%s" , boldRed ("Validation failed due to the issues listed above" ))
214- }
215- }
216- }
217-
218- // TODO: move to expand.go
219- func setCLIVariables (ds * config.DeploymentSettings , s []string ) error {
220- for _ , cliVar := range s {
221- arr := strings .SplitN (cliVar , "=" , 2 )
222-
223- if len (arr ) != 2 {
224- return fmt .Errorf ("invalid format: '%s' should follow the 'name=value' format" , cliVar )
225- }
226- // Convert the variable's string literal to its equivalent default type.
227- key := arr [0 ]
228- var v config.YamlValue
229- if err := yaml .Unmarshal ([]byte (arr [1 ]), & v ); err != nil {
230- return fmt .Errorf ("invalid input: unable to convert '%s' value '%s' to known type" , key , arr [1 ])
231- }
232- ds .Vars = ds .Vars .With (key , v .Unwrap ())
233- }
234- return nil
235- }
236-
237- // TODO: move to expand.go
238- func setBackendConfig (ds * config.DeploymentSettings , s []string ) error {
239- if len (s ) == 0 {
240- return nil // no op
241- }
242- be := config.TerraformBackend {Type : "gcs" }
243- for _ , config := range s {
244- arr := strings .SplitN (config , "=" , 2 )
245-
246- if len (arr ) != 2 {
247- return fmt .Errorf ("invalid format: '%s' should follow the 'name=value' format" , config )
248- }
249-
250- key , value := arr [0 ], arr [1 ]
251- switch key {
252- case "type" :
253- be .Type = value
254- default :
255- be .Configuration = be .Configuration .With (key , cty .StringVal (value ))
256- }
257- }
258- ds .TerraformBackendDefaults = be
259- return nil
260- }
261-
262182func mergeDeploymentSettings (bp * config.Blueprint , ds config.DeploymentSettings ) error {
263183 for k , v := range ds .Vars .Items () {
264184 bp .Vars = bp .Vars .With (k , v )
@@ -269,29 +189,6 @@ func mergeDeploymentSettings(bp *config.Blueprint, ds config.DeploymentSettings)
269189 return nil
270190}
271191
272- // SetValidationLevel allows command-line tools to set the validation level
273- // TODO: move to expand.go
274- func setValidationLevel (bp * config.Blueprint , s string ) error {
275- switch s {
276- case "ERROR" :
277- bp .ValidationLevel = config .ValidationError
278- case "WARNING" :
279- bp .ValidationLevel = config .ValidationWarning
280- case "IGNORE" :
281- bp .ValidationLevel = config .ValidationIgnore
282- default :
283- return errors .New ("invalid validation level (\" ERROR\" , \" WARNING\" , \" IGNORE\" )" )
284- }
285- return nil
286- }
287-
288- // TODO: move to expand.go
289- func skipValidators (bp * config.Blueprint ) {
290- for _ , v := range expandFlags .validatorsToSkip {
291- bp .SkipValidator (v )
292- }
293- }
294-
295192func forceErr (err error ) error {
296193 return config.HintError {
297194 Err : err ,
0 commit comments