Compare commits
2 Commits
pf_mongo_v
...
config_uns
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f78aca62b6 | ||
|
|
4b4348df38 |
@@ -64,6 +64,25 @@ qliksense config set <key>=<value>
|
||||
return cmd
|
||||
}
|
||||
|
||||
func unsetOtherConfigsCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
var (
|
||||
cmd *cobra.Command
|
||||
)
|
||||
|
||||
cmd = &cobra.Command{
|
||||
Use: "un-set",
|
||||
Short: "remove a key value pair in the current context",
|
||||
Example: `
|
||||
qliksense config unset <key>
|
||||
- The above configuration will be removed in the CR
|
||||
`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return q.UnsetOtherConfigs(args)
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func setConfigsCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
var (
|
||||
cmd *cobra.Command
|
||||
@@ -82,6 +101,24 @@ qliksense config set-configs <service_name>.<attribute>="<value>"
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
func unsetConfigsCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
var (
|
||||
cmd *cobra.Command
|
||||
)
|
||||
|
||||
cmd = &cobra.Command{
|
||||
Use: "unset-configs",
|
||||
Short: "unset configurations in the qliksense context as key-value pairs",
|
||||
Example: `
|
||||
qliksense config unset-configs <service_name>.<attribute>="<value>"
|
||||
- The above configuration will be removed in the CR
|
||||
`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return q.UnsetConfigs(args)
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func setSecretsCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
var (
|
||||
|
||||
@@ -80,6 +80,31 @@ func ProcessConfigArgs(args []string) ([]*ServiceKeyValue, error) {
|
||||
return resultSvcKV, nil
|
||||
}
|
||||
|
||||
// ProcessUnsetConfigArgs processes args and returns an service, key, nil slice
|
||||
func ProcessUnsetConfigArgs(args []string) ([]*ServiceKeyValue, error) {
|
||||
if len(args) == 0 {
|
||||
err := fmt.Errorf("No args were provided. Please provide args to configure the current context")
|
||||
return nil, err
|
||||
}
|
||||
resultSvcKV := make([]*ServiceKeyValue, len(args))
|
||||
re1 := regexp.MustCompile(`(\w{1,}).(\w{1,})`)
|
||||
for i, arg := range args {
|
||||
LogDebugMessage("Arg received: %s", arg)
|
||||
result := re1.FindStringSubmatch(arg)
|
||||
// check if result array's length is == 3 (index 0 - is the full match & indices 1,2,- are the fields we need)
|
||||
if len(result) != 3 {
|
||||
err := fmt.Errorf("Please provide valid args for this command")
|
||||
return nil, err
|
||||
}
|
||||
resultSvcKV[i] = &ServiceKeyValue{
|
||||
SvcName: result[1],
|
||||
Key: result[2],
|
||||
Value: "",
|
||||
}
|
||||
}
|
||||
return resultSvcKV, nil
|
||||
}
|
||||
|
||||
func ExecuteTaskWithBlinkingStdoutFeedback(task func() (interface{}, error), feedback string) (result interface{}, err error) {
|
||||
taskDone := make(chan bool)
|
||||
go func() {
|
||||
|
||||
@@ -147,6 +147,27 @@ func (q *Qliksense) SetConfigs(args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetConfigs - set-configs <key>=<value> commands
|
||||
func (q *Qliksense) UnsetConfigs(args []string) error {
|
||||
// retieve current context from config.yaml
|
||||
qliksenseCR, qliksenseContextsFile, err := retrieveCurrentContextInfo(q)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resultArgs, err := api.ProcessUnsetConfigArgs(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, ra := range resultArgs {
|
||||
qliksenseCR.Spec.AddToConfigs(ra.SvcName, ra.Key, ra.Value)
|
||||
}
|
||||
// write modified content into context.yaml
|
||||
api.WriteToFile(&qliksenseCR, qliksenseContextsFile)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func retrieveCurrentContextInfo(q *Qliksense) (*api.QliksenseCR, string, error) {
|
||||
var qliksenseConfig api.QliksenseConfig
|
||||
qliksenseConfigFile := filepath.Join(q.QliksenseHome, QliksenseConfigFile)
|
||||
@@ -238,6 +259,49 @@ func (q *Qliksense) SetOtherConfigs(args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetOtherConfigs - set profile/storageclassname/git.repository/manifestRoot commands
|
||||
func (q *Qliksense) UnsetOtherConfigs(args []string) error {
|
||||
// retieve current context from config.yaml
|
||||
qliksenseCR, qliksenseContextsFile, err := retrieveCurrentContextInfo(q)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// modify appropriate fields
|
||||
if len(args) == 0 {
|
||||
err := fmt.Errorf("No args were provided. Please provide args to configure the current context")
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
|
||||
for _, arg := range args {
|
||||
switch arg {
|
||||
case "profile":
|
||||
qliksenseCR.Spec.Profile = ""
|
||||
api.LogDebugMessage("Current profile after modification: %s ", qliksenseCR.Spec.Profile)
|
||||
case "git.repository":
|
||||
qliksenseCR.Spec.Git.Repository = ""
|
||||
api.LogDebugMessage("Current git repository after modification: %s ", qliksenseCR.Spec.Git.Repository)
|
||||
case "storageClassName":
|
||||
qliksenseCR.Spec.StorageClassName = ""
|
||||
api.LogDebugMessage("Current StorageClassName after modification: %s ", qliksenseCR.Spec.StorageClassName)
|
||||
case "manifestsRoot":
|
||||
qliksenseCR.Spec.ManifestsRoot = ""
|
||||
case "rotateKeys":
|
||||
qliksenseCR.Spec.RotateKeys = ""
|
||||
api.LogDebugMessage("Current rotateKeys after modification: %s ", qliksenseCR.Spec.RotateKeys)
|
||||
default:
|
||||
err := fmt.Errorf("Please enter one of: profile, storageClassName,rotateKeys, manifestRoot or git.repository arguments to configure the current context")
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
// write modified content into context.yaml
|
||||
api.WriteToFile(&qliksenseCR, qliksenseContextsFile)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetContextConfig - set the context for qliksense kubernetes resources to live in
|
||||
func (q *Qliksense) SetContextConfig(args []string) error {
|
||||
if len(args) == 1 {
|
||||
|
||||
@@ -370,6 +370,60 @@ func TestSetOtherConfigs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnsetOtherConfigs(t *testing.T) {
|
||||
type args struct {
|
||||
q *Qliksense
|
||||
args []string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "valid case",
|
||||
args: args{
|
||||
q: &Qliksense{
|
||||
QliksenseHome: testDir,
|
||||
},
|
||||
args: []string{"profile", "rotateKeys", "storageClassName"},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "invalid configs",
|
||||
args: args{
|
||||
q: &Qliksense{
|
||||
QliksenseHome: testDir,
|
||||
},
|
||||
args: []string{"someconfig"},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "empty configs",
|
||||
args: args{
|
||||
q: &Qliksense{
|
||||
QliksenseHome: testDir,
|
||||
},
|
||||
args: []string{},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
tearDown := setup()
|
||||
defer tearDown()
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
//set arguments to be removed
|
||||
_ = tt.args.q.SetOtherConfigs([]string{"profile=minikube", "rotateKeys=yes", "storageClassName=efs"})
|
||||
if err := tt.args.q.UnsetOtherConfigs(tt.args.args); (err != nil) != tt.wantErr {
|
||||
t.Errorf("SetOtherConfigs() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetConfigs(t *testing.T) {
|
||||
type args struct {
|
||||
q *Qliksense
|
||||
@@ -402,6 +456,40 @@ func TestSetConfigs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnsetConfigs(t *testing.T) {
|
||||
type args struct {
|
||||
q *Qliksense
|
||||
args []string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "valid case",
|
||||
args: args{
|
||||
q: &Qliksense{
|
||||
QliksenseHome: testDir,
|
||||
},
|
||||
args: []string{"qliksense.acceptEULA", "qliksense.mongoDbUri"},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
tearDown := setup()
|
||||
defer tearDown()
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
//set arguments to be removed
|
||||
_ = tt.args.q.SetConfigs([]string{"qliksense.acceptEULA=\"yes\"", "qliksense.mongoDbUri=\"mongo://mongo:3307\""})
|
||||
if err := tt.args.q.UnsetConfigs(tt.args.args); (err != nil) != tt.wantErr {
|
||||
t.Errorf("SetConfigs() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetImageRegistry(t *testing.T) {
|
||||
getQlikSense := func(tmpQlikSenseHome string) (*Qliksense, error) {
|
||||
if err := ioutil.WriteFile(path.Join(tmpQlikSenseHome, "config.yaml"), []byte(fmt.Sprintf(`
|
||||
|
||||
Reference in New Issue
Block a user