From e967bd4e308d9c5f989f7ca41a1d57f9a880450e Mon Sep 17 00:00:00 2001 From: elad-codefresh <82316166+elad-codefresh@users.noreply.github.com> Date: Sun, 22 Aug 2021 14:26:10 +0300 Subject: [PATCH] CR-6063-gs-validation (#70) * 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 --- Makefile | 2 +- cmd/commands/common.go | 5 +++++ cmd/commands/git-source.go | 9 +++++++++ cmd/commands/runtime.go | 9 +++++++++ docs/releases/release_notes.md | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- manifests/runtime.yaml | 2 +- 8 files changed, 30 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index dec525a1d..19e380bb2 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION=v0.0.72 +VERSION=v0.0.73 OUT_DIR=dist YEAR?=$(shell date +"%Y") diff --git a/cmd/commands/common.go b/cmd/commands/common.go index a5bf58d0a..c0ad43d4a 100644 --- a/cmd/commands/common.go +++ b/cmd/commands/common.go @@ -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" @@ -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) +} diff --git a/cmd/commands/git-source.go b/cmd/commands/git-source.go index 55af12d8f..7cec66007 100644 --- a/cmd/commands/git-source.go +++ b/cmd/commands/git-source.go @@ -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 } diff --git a/cmd/commands/runtime.go b/cmd/commands/runtime.go index 0e809e944..c3efda73c 100644 --- a/cmd/commands/runtime.go +++ b/cmd/commands/runtime.go @@ -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 { diff --git a/docs/releases/release_notes.md b/docs/releases/release_notes.md index ebef7ea2f..ae2071589 100644 --- a/docs/releases/release_notes.md +++ b/docs/releases/release_notes.md @@ -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 @@ -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 diff --git a/go.mod b/go.mod index 345be42f7..e12cf2609 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 0559a9548..509e17387 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/manifests/runtime.yaml b/manifests/runtime.yaml index af390fad1..8a39d4b04 100644 --- a/manifests/runtime.yaml +++ b/manifests/runtime.yaml @@ -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