From 66db7812c416edd8959e763a431808d70d4c4709 Mon Sep 17 00:00:00 2001 From: Juan Antonio Osorio Date: Mon, 6 Nov 2023 10:00:50 +0200 Subject: [PATCH] Remove `apply` subcommand from CLI (#1499) We're not currently using it. I'd like us to, but we can do it later. --- cmd/cli/app/apply/apply.go | 115 ------------------------------------- cmd/cli/main.go | 1 - 2 files changed, 116 deletions(-) delete mode 100644 cmd/cli/app/apply/apply.go diff --git a/cmd/cli/app/apply/apply.go b/cmd/cli/app/apply/apply.go deleted file mode 100644 index 01fc576c0c..0000000000 --- a/cmd/cli/app/apply/apply.go +++ /dev/null @@ -1,115 +0,0 @@ -// -// Copyright 2023 Stacklok, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package apply provides the apply command for the minder CLI -package apply - -import ( - "encoding/json" - "fmt" - "io" - "os" - "path/filepath" - "reflect" - - "github.com/spf13/cobra" - "github.com/spf13/viper" - "google.golang.org/grpc/codes" - "google.golang.org/grpc/status" - "gopkg.in/yaml.v3" - - "github.com/stacklok/minder/cmd/cli/app" - "github.com/stacklok/minder/internal/util" -) - -type objectParameters struct { - Object string - Parameters map[string]interface{} -} - -func parseContent(data []byte) ([]objectParameters, error) { - var objects []map[string]interface{} - err := json.Unmarshal(data, &objects) - if err != nil { - // try with yaml - err = yaml.Unmarshal(data, &objects) - if err != nil { - return nil, status.Errorf(codes.Unknown, "failed to parse content: %s", err) - } - } - - var ret []objectParameters - for _, object := range objects { - for objectName, objectData := range object { - ret = append(ret, objectParameters{ - Object: objectName, - Parameters: objectData.(map[string]interface{}), - }) - } - } - return ret, nil -} - -// ApplyCmd is the root command for the apply subcommands -var ApplyCmd = &cobra.Command{ - Use: "apply (-f FILENAME)", - Short: "Appy a configuration to a minder control plane", - Long: `The minder apply command applies a configuration to a minder control plane.`, - PreRun: func(cmd *cobra.Command, args []string) { - err := viper.BindPFlags(cmd.Flags()) - util.ExitNicelyOnError(err, "Error binding flags") - }, - Run: func(cmd *cobra.Command, args []string) { - f := util.GetConfigValue(viper.GetViper(), "file", "file", cmd, "").(string) - - var data []byte - var err error - - if f == "-" { - data, err = io.ReadAll(os.Stdin) - util.ExitNicelyOnError(err, "Error reading from stdin") - } else { - f = filepath.Clean(f) - data, err = os.ReadFile(f) - util.ExitNicelyOnError(err, "Error reading file") - } - - // try to unmarshal with json or yaml - objects, err := parseContent(data) - util.ExitNicelyOnError(err, "Error parsing content") - - for _, object := range objects { - // iterate over params and set viper values - params := object.Parameters - for k, v := range params { - valueType := reflect.TypeOf(v) - if valueType.Kind() == reflect.Int { - v1 := v.(int) - viper.Set(k, int32(v1)) - } else { - viper.Set(k, v) - } - } - } - }, -} - -func init() { - app.RootCmd.AddCommand(ApplyCmd) - ApplyCmd.Flags().StringP("file", "f", "", "Path to the configuration file to apply or - for stdin") - if err := ApplyCmd.MarkFlagRequired("file"); err != nil { - fmt.Fprintf(os.Stderr, "Error binding flags: %s\n", err) - } -} diff --git a/cmd/cli/main.go b/cmd/cli/main.go index d9abad2779..f54e52774d 100644 --- a/cmd/cli/main.go +++ b/cmd/cli/main.go @@ -18,7 +18,6 @@ package main import ( "github.com/stacklok/minder/cmd/cli/app" - _ "github.com/stacklok/minder/cmd/cli/app/apply" _ "github.com/stacklok/minder/cmd/cli/app/artifact" _ "github.com/stacklok/minder/cmd/cli/app/auth" _ "github.com/stacklok/minder/cmd/cli/app/docs"