Skip to content

Commit

Permalink
CR-6063-gs-validation (#70)
Browse files Browse the repository at this point in the history
* bump

* lowercase validation

* for runtime also, and moved isLower to common

* isValid

* removed redundant

* bump

* isValid s

* isValid with err

* removed replace

* bump sdk

* tidy
  • Loading branch information
elad-codefresh authored Aug 22, 2021
1 parent 0417655 commit e967bd4
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=v0.0.72
VERSION=v0.0.73
OUT_DIR=dist
YEAR?=$(shell date +"%Y")

Expand Down
5 changes: 5 additions & 0 deletions cmd/commands/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package commands

import (
"os"
"regexp"

"github.com/codefresh-io/cli-v2/pkg/config"
"github.com/codefresh-io/cli-v2/pkg/util"
Expand Down Expand Up @@ -49,3 +50,7 @@ func presetRequiredFlags(cmd *cobra.Command) {
})
cmd.Flags().SortFlags = false
}

func IsValid(s string) (bool, error) {
return regexp.MatchString(`^[a-z]([-a-z0-9]{0,61}[a-z0-9])?$`, s)
}
9 changes: 9 additions & 0 deletions cmd/commands/git-source.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ func NewGitSourceCreateCommand() *cobra.Command {
log.G(ctx).Fatal("must enter a valid value to --git-src-repo. Example: https://github.com/owner/repo-name/path/to/workflow")
}

isValid, err := IsValid(args[1])
if err != nil {
log.G(ctx).Fatal("failed to check the validity of the git-source name")
}

if !isValid {
log.G(ctx).Fatal("git-source name cannot have any uppercase letters, must start with a character, end with character or number, and be shorter than 63 chars")
}

if gsCloneOpts.Auth.Password == "" {
gsCloneOpts.Auth.Password = insCloneOpts.Auth.Password
}
Expand Down
9 changes: 9 additions & 0 deletions cmd/commands/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ func NewRuntimeInstallCommand() *cobra.Command {
log.G(ctx).Fatal("must enter runtime name")
}

isValid, err := IsValid(args[1])
if err != nil {
log.G(ctx).Fatal("failed to check the validity of the runtime name")
}

if !isValid {
log.G(ctx).Fatal("runtime name cannot have any uppercase letters, must start with a character, end with character or number, and be shorter than 63 chars")
}

if versionStr != "" {
version, err = semver.NewVersion(versionStr)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions docs/releases/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cf version
### Linux
```bash
# download and extract the binary
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.72/cf-linux-amd64.tar.gz | tar zx
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.73/cf-linux-amd64.tar.gz | tar zx

# move the binary to your $PATH
mv ./cf-linux-amd64 /usr/local/bin/cf
Expand All @@ -32,7 +32,7 @@ cf version
### Mac
```bash
# download and extract the binary
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.72/cf-darwin-amd64.tar.gz | tar zx
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.73/cf-darwin-amd64.tar.gz | tar zx

# move the binary to your $PATH
mv ./cf-darwin-amd64 /usr/local/bin/cf
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/argoproj/argo-events v1.4.0
github.com/argoproj/argo-workflows/v3 v3.1.6
github.com/briandowns/spinner v1.16.0
github.com/codefresh-io/go-sdk v0.32.1
github.com/codefresh-io/go-sdk v0.32.2
github.com/fatih/color v1.12.0
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
github.com/go-git/go-billy/v5 v5.3.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGX
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:zn76sxSg3SzpJ0PPJaLDCu+Bu0Lg3sKTORVIj19EIF8=
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/codefresh-io/go-sdk v0.32.1 h1:1ZkuAjcUjExaTuXGfvldpE9ldOMFowhImaqjF2drmTw=
github.com/codefresh-io/go-sdk v0.32.1/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
github.com/codefresh-io/go-sdk v0.32.2 h1:74RlRp6cpqwU8sf4l1vG2Xiv8ohnaLQjREkW0BAUwcU=
github.com/codefresh-io/go-sdk v0.32.2/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
github.com/colinmarc/hdfs v1.1.4-0.20180802165501-48eb8d6c34a9/go.mod h1:0DumPviB681UcSuJErAbDIOx6SIaJWj463TymfZG02I=
github.com/colinmarc/hdfs v1.1.4-0.20180805212432-9746310a4d31/go.mod h1:vSBumefK4HA5uiRSwNP+3ofgrEoScpCS2MMWcWXEuQ4=
github.com/container-storage-interface/spec v1.3.0/go.mod h1:6URME8mwIBbpVyZV93Ce5St17xBiQJQY67NDsuohiy4=
Expand Down
2 changes: 1 addition & 1 deletion manifests/runtime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
namespace: "{{ namespace }}"
spec:
defVersion: 1.0.0
version: 0.0.72
version: 0.0.73
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
components:
- name: events
Expand Down

0 comments on commit e967bd4

Please sign in to comment.