-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require EULA acceptance for install only (#405)
- Loading branch information
1 parent
4cb3231
commit bf4e4b9
Showing
12 changed files
with
171 additions
and
466 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
|
||
qapi "github.com/qlik-oss/sense-installer/pkg/api" | ||
|
||
"github.com/qlik-oss/sense-installer/pkg/qliksense" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func applyCmd(q *qliksense.Qliksense) *cobra.Command { | ||
opts := &qliksense.InstallCommandOptions{} | ||
opts := &qliksense.InstallCommandOptions{ | ||
CleanPatchFiles: true, | ||
} | ||
filePath := "" | ||
cleanPatchFiles, pull, push := true, false, false | ||
c := &cobra.Command{ | ||
Use: "apply", | ||
Short: "install qliksense based on provided cr file", | ||
Long: `install qliksense based on provided cr file`, | ||
Example: `qliksense apply -f file_name or cat cr_file | qliksense apply -f -`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return runLoadOrApplyCommandE(cmd, func(crBytes []byte) error { | ||
if cr, crBytesWithEula, err := getCrWithEulaInserted(crBytes); err != nil { | ||
return err | ||
} else if err := validatePullPushFlagsOnApply(cr, pull, push); err != nil { | ||
return err | ||
} else { | ||
return q.ApplyCRFromReader(bytes.NewReader(crBytesWithEula), opts, cleanPatchFiles, true, pull, push) | ||
} | ||
}) | ||
return apply(q, cmd, opts) | ||
}, | ||
} | ||
|
||
f := c.Flags() | ||
f.StringVarP(&filePath, "file", "f", "", "Install from a CR file") | ||
c.MarkFlagRequired("file") | ||
f.StringVarP(&opts.StorageClass, "storageClass", "s", "", "Storage class for qliksense") | ||
f.StringVarP(&opts.MongodbUri, "mongodbUri", "m", "", "mongodbUri for qliksense (i.e. mongodb://qlik-default-mongodb:27017/qliksense?ssl=false)") | ||
f.StringVarP(&opts.RotateKeys, "rotateKeys", "r", "", "Rotate JWT keys for qliksense (yes:rotate keys/ no:use exising keys from cluster/ None: use default EJSON_KEY from env") | ||
f.BoolVar(&cleanPatchFiles, cleanPatchFilesFlagName, cleanPatchFiles, cleanPatchFilesFlagUsage) | ||
f.BoolVarP(&pull, pullFlagName, pullFlagShorthand, pull, pullFlagUsage) | ||
f.BoolVarP(&push, pushFlagName, pushFlagShorthand, push, pushFlagUsage) | ||
f.BoolVar(&opts.CleanPatchFiles, cleanPatchFilesFlagName, opts.CleanPatchFiles, cleanPatchFilesFlagUsage) | ||
f.BoolVarP(&opts.Pull, pullFlagName, pullFlagShorthand, opts.Pull, pullFlagUsage) | ||
f.BoolVarP(&opts.Push, pushFlagName, pushFlagShorthand, opts.Push, pushFlagUsage) | ||
f.StringVarP(&opts.AcceptEULA, "acceptEULA", "a", opts.AcceptEULA, "Accept EULA for qliksense") | ||
|
||
eulaPreRunHooks.addValidator(fmt.Sprintf("%v %v", rootCommandName, c.Name()), loadOrApplyCommandEulaPreRunHook) | ||
|
||
return c | ||
} | ||
|
||
func validatePullPushFlagsOnApply(cr *qapi.QliksenseCR, pull, push bool) error { | ||
if pull && !push { | ||
fmt.Printf("WARNING: pulling images without pushing them") | ||
if err := c.MarkFlagRequired("file"); err != nil { | ||
panic(err) | ||
} | ||
if push { | ||
if registry := cr.Spec.GetImageRegistry(); registry == "" { | ||
return errors.New("no image registry set in the CR; to set it use: qliksense config set-image-registry") | ||
} | ||
} | ||
return nil | ||
return c | ||
} | ||
|
||
func getCrWithEulaInserted(crBytes []byte) (*qapi.QliksenseCR, []byte, error) { | ||
if cr, err := qapi.CreateCRObjectFromString(string(crBytes)); err != nil { | ||
return nil, nil, err | ||
func apply(q *qliksense.Qliksense, cmd *cobra.Command, opts *qliksense.InstallCommandOptions) error { | ||
if crBytes, err := getCrBytesFromFileFlag(cmd); err != nil { | ||
return err | ||
} else { | ||
cr.SetEULA("yes") | ||
if crBytesWithEula, err := qapi.K8sToYaml(cr); err != nil { | ||
return nil, nil, err | ||
} else { | ||
return cr, crBytesWithEula, nil | ||
} | ||
return q.ApplyCRFromBytes(crBytes, opts, true) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.