|
| 1 | +// Copyright 2022 The Codefresh Authors. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package commands |
| 16 | + |
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | + "github.com/spf13/cobra" |
| 20 | +) |
| 21 | + |
| 22 | +func NewSettingCommand() *cobra.Command { |
| 23 | + cmd := &cobra.Command{ |
| 24 | + Use: "settings", |
| 25 | + Short: "Settings commands", |
| 26 | + Args: cobra.NoArgs, |
| 27 | + Run: func(cmd *cobra.Command, args []string) { |
| 28 | + cmd.HelpFunc()(cmd, args) |
| 29 | + exit(1) |
| 30 | + }, |
| 31 | + } |
| 32 | + cmd.AddCommand(NewResetIscRepoUrlCommand()) |
| 33 | + |
| 34 | + return cmd |
| 35 | +} |
| 36 | + |
| 37 | +func NewResetIscRepoUrlCommand() *cobra.Command { |
| 38 | + cmd := &cobra.Command{ |
| 39 | + Use: "reset-isc-url", |
| 40 | + Short: "Reset the URL of the shared configurations repo. ", |
| 41 | + Args: cobra.NoArgs, |
| 42 | + PersistentPreRunE: cfConfig.RequireAuthentication, |
| 43 | + PreRunE: func(cmd *cobra.Command, args []string) error { |
| 44 | + var err error |
| 45 | + var runtimesExist bool |
| 46 | + |
| 47 | + ctx := cmd.Context() |
| 48 | + |
| 49 | + runtimesExist, err = isRuntimesExist(ctx) |
| 50 | + if err != nil { |
| 51 | + return err |
| 52 | + } |
| 53 | + if runtimesExist { |
| 54 | + return fmt.Errorf("reset account Internal Shared Repository url is not allowed. Please uninstall all runtimes from your account and try again") |
| 55 | + } |
| 56 | + |
| 57 | + return nil |
| 58 | + }, |
| 59 | + RunE: func(cmd *cobra.Command, _ []string) error { |
| 60 | + ctx := cmd.Context() |
| 61 | + err := resetIscRepoUrl(ctx) |
| 62 | + if err != nil { |
| 63 | + return fmt.Errorf("failed to reset account Internal Shared Repository url: %w", err) |
| 64 | + } |
| 65 | + fmt.Printf("account Internal Shared Repository url was reset successfully \n") |
| 66 | + return nil |
| 67 | + }, |
| 68 | + } |
| 69 | + |
| 70 | + return cmd |
| 71 | +} |
0 commit comments