github.com/Racer159/jackal@v0.32.7-0.20240401174413-0bd2339e4f2e/src/types/packager.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: 2021-Present The Jackal Authors 3 4 // Package types contains all the types used by Jackal. 5 package types 6 7 import ( 8 "fmt" 9 "regexp" 10 ) 11 12 // PackagerConfig is the main struct that the packager uses to hold high-level options. 13 type PackagerConfig struct { 14 // CreateOpts tracks the user-defined options used to create the package 15 CreateOpts JackalCreateOptions 16 17 // PkgOpts tracks user-defined options 18 PkgOpts JackalPackageOptions 19 20 // DeployOpts tracks user-defined values for the active deployment 21 DeployOpts JackalDeployOptions 22 23 // MirrorOpts tracks user-defined values for the active mirror 24 MirrorOpts JackalMirrorOptions 25 26 // InitOpts tracks user-defined values for the active Jackal initialization. 27 InitOpts JackalInitOptions 28 29 // InspectOpts tracks user-defined options used to inspect the package 30 InspectOpts JackalInspectOptions 31 32 // PublishOpts tracks user-defined options used to publish the package 33 PublishOpts JackalPublishOptions 34 35 // PullOpts tracks user-defined options used to pull packages 36 PullOpts JackalPullOptions 37 38 // FindImagesOpts tracks user-defined options used to find images 39 FindImagesOpts JackalFindImagesOptions 40 41 // GenerateOpts tracks user-defined values for package generation. 42 GenerateOpts JackalGenerateOptions 43 44 // The package data 45 Pkg JackalPackage 46 47 // The active jackal state 48 State *JackalState 49 50 // Variables set by the user 51 SetVariableMap map[string]*JackalSetVariable 52 } 53 54 // SetVariable sets a value for a variable in PackagerConfig.SetVariableMap. 55 func (cfg *PackagerConfig) SetVariable(name, value string, sensitive bool, autoIndent bool, varType VariableType) { 56 cfg.SetVariableMap[name] = &JackalSetVariable{ 57 Name: name, 58 Value: value, 59 Sensitive: sensitive, 60 AutoIndent: autoIndent, 61 Type: varType, 62 } 63 } 64 65 // CheckVariablePattern checks to see if a variable is set to a value that matches its pattern. 66 func (cfg *PackagerConfig) CheckVariablePattern(name, pattern string) error { 67 if regexp.MustCompile(pattern).MatchString(cfg.SetVariableMap[name].Value) { 68 return nil 69 } 70 return fmt.Errorf("provided value for variable %q does not match pattern \"%s\"", name, pattern) 71 }