Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use google uuid package for generating uuids in the codebase #7455

Merged
merged 1 commit into from
Jul 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ linters-settings:
list-type: blacklist
packages:
- github.com/jenkins-x/jx/v2/pkg/log/
- github.com/satori/go.uuid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this!

- github.com/pborman/uuid
packages-with-error-message:
- github.com/jenkins-x/jx/v2/pkg/log/: "use jenkins-x/jx-logging instead"
- github.com/satori/go.uuid: "use github.com/google/uuid instead"
- github.com/pborman/uuid: "use github.com/google/uuid instead"
dupl:
threshold: 100
exhaustive:
Expand Down
4 changes: 2 additions & 2 deletions cmd/codegen/util/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"path/filepath"
"strings"

uuid "github.com/satori/go.uuid"
"github.com/google/uuid"

"github.com/pkg/errors"
)
Expand Down Expand Up @@ -110,7 +110,7 @@ func GoGet(path string, version string, gopath string, goModules bool, sourceOnl
dir := filepath.Join(parts...)
if !goModules && version != "" {

branchNameUUID, err := uuid.NewV4()
branchNameUUID, err := uuid.NewUUID()
if err != nil {
return errors.WithStack(err)
}
Expand Down
18 changes: 1 addition & 17 deletions cmd/jx/jx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ package main

import (
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"strings"
"testing"

"github.com/jenkins-x/jx-logging/pkg/log"

"github.com/pborman/uuid"
"github.com/google/uuid"

"github.com/jenkins-x/jx/v2/pkg/util"

Expand Down Expand Up @@ -100,17 +98,3 @@ func TestSystem(t *testing.T) {
main()
}
}

func downloadFile(out *os.File, url string) error {

// Get the data
resp, err := http.Get(url)
if err != nil {
return err
}
defer resp.Body.Close()

// Write the body to file
_, err = io.Copy(out, resp.Body)
return err
}
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,13 @@ require (
github.com/nwaples/rardecode v1.0.0 // indirect
github.com/onsi/ginkgo v1.10.1
github.com/onsi/gomega v1.7.0
github.com/pborman/uuid v1.2.0
github.com/pelletier/go-toml v1.4.0 // indirect
github.com/petergtz/pegomock v2.7.0+incompatible
github.com/pkg/browser v0.0.0-20170505125900-c90ca0c84f15
github.com/pkg/errors v0.9.1
github.com/rodaine/hclencoder v0.0.0-20180926060551-0680c4321930
github.com/rollout/rox-go v0.0.0-20181220111955-29ddae74a8c4
github.com/russross/blackfriday v1.5.2
github.com/satori/go.uuid v1.2.1-0.20180103174451-36e9d2ebbde5
github.com/sethvargo/go-password v0.1.2
github.com/shirou/gopsutil v0.0.0-20180901134234-eb1f1ab16f2e
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
Expand Down
5 changes: 3 additions & 2 deletions pkg/apps/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (

"github.com/jenkins-x/jx/v2/pkg/kube"

"github.com/pborman/uuid"
"github.com/google/uuid"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand Down Expand Up @@ -374,7 +374,8 @@ func (o *InstallOptions) createInterrogateChartFn(version string, chartName stri
return &chartDetails, errors.Wrapf(err, "locating app resource in %s", chartDir)
}
if appResource.Spec.SchemaPreprocessor != nil {
id := uuid.New()
// Generate a new UUID and get it's string form for use later
id := uuid.New().String()
cmName := toValidName(chartDetails.Name, "schema", id)
cm := corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloud/amazon/storage/bucket_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import (
"github.com/aws/aws-sdk-go/service/s3/s3iface"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/aws/aws-sdk-go/service/s3/s3manager/s3manageriface"
"github.com/google/uuid"
"github.com/jenkins-x/jx-logging/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/cloud/buckets"
"github.com/jenkins-x/jx/v2/pkg/config"
"github.com/jenkins-x/jx/v2/pkg/util"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
)

// AmazonBucketProvider the bucket provider for AWS
Expand Down Expand Up @@ -83,7 +83,7 @@ func (b *AmazonBucketProvider) s3ManagerUploader() (s3manageriface.UploaderAPI,

// CreateNewBucketForCluster creates a new dynamic bucket
func (b *AmazonBucketProvider) CreateNewBucketForCluster(clusterName string, bucketKind string) (string, error) {
uuid4, _ := uuid.NewV4()
uuid4 := uuid.New()
bucketName := fmt.Sprintf("%s-%s-%s", clusterName, bucketKind, uuid4.String())

// Max length is 63, https://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloud/amazon/vault/vault_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"github.com/aws/aws-sdk-go/service/iam"

uuid "github.com/satori/go.uuid"
"github.com/google/uuid"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
Expand Down Expand Up @@ -71,7 +71,7 @@ func CreateVaultResources(vaultParams ResourceCreationOpts) (*string, *string, *
util.ColorInfo(vaultParams.Username),
util.ColorInfo(vaultParams.TableName))

valueUUID, err := uuid.NewV4()
valueUUID, err := uuid.NewUUID()
if err != nil {
return nil, nil, nil, nil, nil, errors.Wrapf(err, "generating UUID failed")
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/cloud/gke/storage/bucket_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"strings"
"time"

uuid2 "github.com/google/uuid"
"github.com/jenkins-x/jx-logging/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/cloud/buckets"
"github.com/jenkins-x/jx/v2/pkg/cloud/gke"
"github.com/jenkins-x/jx/v2/pkg/config"
"github.com/jenkins-x/jx/v2/pkg/util"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
)

var (
Expand All @@ -28,8 +28,8 @@ type GKEBucketProvider struct {

// CreateNewBucketForCluster creates a new dynamic bucket
func (b *GKEBucketProvider) CreateNewBucketForCluster(clusterName string, bucketKind string) (string, error) {
uuid4, _ := uuid.NewV4()
bucketURL := fmt.Sprintf("gs://%s-%s-%s", clusterName, bucketKind, uuid4.String())
uuid := uuid2.New()
bucketURL := fmt.Sprintf("gs://%s-%s-%s", clusterName, bucketKind, uuid.String())
if len(bucketURL) > 60 {
bucketURL = bucketURL[:60]
}
Expand All @@ -48,7 +48,7 @@ func (b *GKEBucketProvider) CreateNewBucketForCluster(clusterName string, bucket
func (b *GKEBucketProvider) EnsureBucketIsCreated(bucketURL string) error {
project := b.Requirements.Cluster.ProjectID
if project == "" {
return fmt.Errorf("Requirements do not specify a project")
return fmt.Errorf("requirements do not specify a project")
}
u, err := url.Parse(bucketURL)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloud/gke/storage/long_term_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"fmt"
"strings"

"github.com/google/uuid"
"github.com/jenkins-x/jx-logging/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/cloud/gke"
"github.com/jenkins-x/jx/v2/pkg/kube"
"github.com/jenkins-x/jx/v2/pkg/util"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
)

// EnableLongTermStorage will take the cluster install values and a provided bucket name and use it / create a new one for gs
Expand Down Expand Up @@ -51,7 +51,7 @@ func createUniqueBucketName(installValues map[string]string) (string, map[string
}

func createUniqueBucketNameForCluster(clusterName string) string {
uuid4, _ := uuid.NewV4()
uuid4 := uuid.New()
bucketName := fmt.Sprintf("%s-lts-%s", clusterName, uuid4.String())
if len(bucketName) > 60 {
bucketName = bucketName[:60]
Expand Down
4 changes: 2 additions & 2 deletions pkg/cloud/openshift/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"path/filepath"
"runtime"

"github.com/google/uuid"
"github.com/jenkins-x/jx/v2/pkg/packages"
"github.com/jenkins-x/jx/v2/pkg/util"
"github.com/pborman/uuid"
)

// InstallOc installs oc cli
Expand Down Expand Up @@ -58,7 +58,7 @@ func InstallOc() error {
}

if extension == ".zip" {
zipDir := filepath.Join(binDir, "oc-tmp-"+uuid.NewUUID().String())
zipDir := filepath.Join(binDir, "oc-tmp-"+uuid.New().String())
err = os.MkdirAll(zipDir, util.DefaultWritePermissions)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/helpers.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package cluster

import (
"github.com/google/uuid"
"github.com/jenkins-x/jx-logging/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/kube/naming"
"github.com/jenkins-x/jx/v2/pkg/util"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
)

// NewLabelValue returns a cluster safe unique label we can use for locking
func NewLabelValue() (string, error) {
id, err := uuid.NewV4()
id, err := uuid.NewUUID()
if err != nil {
return "", err
}
Expand Down
Loading