Skip to content

Commit 0356cd3

Browse files
Cr 15158 cli (#652)
* cr-15158 * bump * bump go-sdk * change error msg * bump * v0.51.0 * go mod tidy * lint * lint
1 parent 4b4cff7 commit 0356cd3

File tree

10 files changed

+153
-7
lines changed

10 files changed

+153
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.1.14
1+
VERSION=v0.1.15
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/common.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ func ensureRuntimeName(ctx context.Context, args []string, allowManaged bool) (s
199199
return runtimeName, nil
200200
}
201201

202+
func isRuntimesExist(ctx context.Context) (bool, error) {
203+
runtimes, err := cfConfig.NewClient().V2().Runtime().List(ctx)
204+
if err != nil {
205+
return true, fmt.Errorf("failed to get runtime list: %w", err)
206+
}
207+
return len(runtimes) > 0, nil
208+
}
209+
202210
func getRuntimeNameFromUserSelect(ctx context.Context, allowManaged bool) (string, error) {
203211
runtimes, err := cfConfig.NewClient().V2().Runtime().List(ctx)
204212
if err != nil {
@@ -504,7 +512,7 @@ func getKubeContextNameFromUserSelect(kubeconfig string) (string, error) {
504512
return contexts[index].Name, nil
505513
}
506514

507-
func getAccessModeFromUserSelect(accessMode *platmodel.AccessMode) (error) {
515+
func getAccessModeFromUserSelect(accessMode *platmodel.AccessMode) error {
508516
templates := &promptui.SelectTemplates{
509517
Selected: "{{ .Name | yellow }}",
510518
}
@@ -729,6 +737,14 @@ func suggestIscRepo(ctx context.Context, suggestedSharedConfigRepo string) (stri
729737
return setIscRepoResponse, nil
730738
}
731739

740+
func resetIscRepoUrl(ctx context.Context) error {
741+
err := cfConfig.NewClient().V2().Runtime().ResetSharedConfigRepo(ctx)
742+
if err != nil {
743+
return fmt.Errorf("failed to reset shared config repo. Error: %w", err)
744+
}
745+
return nil
746+
}
747+
732748
func isRuntimeManaged(ctx context.Context, runtimeName string) (bool, error) {
733749
rt, err := getRuntime(ctx, runtimeName)
734750
if err != nil {

cmd/commands/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ variables in advanced to simplify the use of those commands.
5959
cmd.AddCommand(NewPipelineCommand())
6060
cmd.AddCommand(NewIntegrationCommand())
6161
cmd.AddCommand(NewCompletionCommand())
62+
cmd.AddCommand(NewSettingCommand())
6263

6364
cobra.OnInitialize(func() { postInitCommands(cmd.Commands()) })
6465

cmd/commands/settings.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
}

docs/commands/cli-v2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ cli-v2 [flags]
4040
* [cli-v2 integration](cli-v2_integration.md) - Manage integrations with git providers, container registries and more
4141
* [cli-v2 pipeline](cli-v2_pipeline.md) - Manage pipelines of Codefresh runtimes
4242
* [cli-v2 runtime](cli-v2_runtime.md) - Manage Codefresh runtimes
43+
* [cli-v2 settings](cli-v2_settings.md) - Settings commands
4344
* [cli-v2 upgrade](cli-v2_upgrade.md) - Upgrades the cli
4445
* [cli-v2 version](cli-v2_version.md) - Show cli version
4546
* [cli-v2 workflow](cli-v2_workflow.md) - Manage workflows of Codefresh runtimes

docs/commands/cli-v2_settings.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## cli-v2 settings
2+
3+
Settings commands
4+
5+
```
6+
cli-v2 settings [flags]
7+
```
8+
9+
### Options
10+
11+
```
12+
-h, --help help for settings
13+
```
14+
15+
### Options inherited from parent commands
16+
17+
```
18+
--auth-context string Run the next command using a specific authentication context
19+
--cfconfig string Custom path for authentication contexts config file (default "/home/user")
20+
--insecure Disable certificate validation for TLS connections (e.g. to g.codefresh.io)
21+
--insecure-ingress-host Disable certificate validation of ingress host (default: false)
22+
--request-timeout duration Request timeout (default 30s)
23+
```
24+
25+
### SEE ALSO
26+
27+
* [cli-v2](cli-v2.md) - cli-v2 is used for installing and managing codefresh installations using gitops
28+
* [cli-v2 settings reset-isc-url](cli-v2_settings_reset-isc-url.md) - Reset the URL of the shared configurations repo.
29+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## cli-v2 settings reset-isc-url
2+
3+
Reset the URL of the shared configurations repo.
4+
5+
```
6+
cli-v2 settings reset-isc-url [flags]
7+
```
8+
9+
### Options
10+
11+
```
12+
-h, --help help for reset-isc-url
13+
```
14+
15+
### Options inherited from parent commands
16+
17+
```
18+
--auth-context string Run the next command using a specific authentication context
19+
--cfconfig string Custom path for authentication contexts config file (default "/home/user")
20+
--insecure Disable certificate validation for TLS connections (e.g. to g.codefresh.io)
21+
--insecure-ingress-host Disable certificate validation of ingress host (default: false)
22+
--request-timeout duration Request timeout (default 30s)
23+
```
24+
25+
### SEE ALSO
26+
27+
* [cli-v2 settings](cli-v2_settings.md) - Settings commands
28+

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cf version
2323

2424
```bash
2525
# download and extract the binary
26-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.14/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.15/cf-linux-amd64.tar.gz | tar zx
2727

2828
# move the binary to your $PATH
2929
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -36,7 +36,7 @@ cf version
3636

3737
```bash
3838
# download and extract the binary
39-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.14/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.1.15/cf-darwin-amd64.tar.gz | tar zx
4040

4141
# move the binary to your $PATH
4242
mv ./cf-darwin-amd64 /usr/local/bin/cf

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/argoproj/argo-events v0.17.1-0.20220327045437-70eaafe9afec
1010
github.com/argoproj/argo-workflows/v3 v3.3.1
1111
github.com/briandowns/spinner v1.18.1
12-
github.com/codefresh-io/go-sdk v0.50.0
12+
github.com/codefresh-io/go-sdk v0.51.0
1313
github.com/fatih/color v1.13.0
1414
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
1515
github.com/go-git/go-billy/v5 v5.3.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h
303303
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
304304
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
305305
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
306-
github.com/codefresh-io/go-sdk v0.50.0 h1:SHIlxewFABxJS8M81Ar/E6YQFoEMGAKa8EIr0VLi1vk=
307-
github.com/codefresh-io/go-sdk v0.50.0/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
306+
github.com/codefresh-io/go-sdk v0.51.0 h1:yYmrLp+iDTx9/K3KEFsxVlOB/+Y1KQHSwChgDP1Fjwc=
307+
github.com/codefresh-io/go-sdk v0.51.0/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
308308
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
309309
github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE=
310310
github.com/container-storage-interface/spec v1.5.0/go.mod h1:8K96oQNkJ7pFcC2R9Z1ynGGBB1I93kcS6PGg3SsOk8s=

0 commit comments

Comments
 (0)