Skip to content

Commit

Permalink
Retire satori UUID and use a community driven fork (#241)
Browse files Browse the repository at this point in the history
* Retire satori UUID and use a community driven fork

* Addressed the bot's concerns
  • Loading branch information
Skarlso committed Apr 24, 2020
1 parent 5b343c4 commit a548246
Show file tree
Hide file tree
Showing 16 changed files with 135 additions and 66 deletions.
4 changes: 3 additions & 1 deletion go.mod
Expand Up @@ -20,6 +20,7 @@ require (
github.com/gaia-pipeline/flag v1.7.4-pre
github.com/gaia-pipeline/protobuf v0.0.0-20180812091451-7be8a901b55a
github.com/gliderlabs/ssh v0.1.1 // indirect
github.com/gofrs/uuid v3.2.0+incompatible
github.com/gogo/protobuf v1.2.1 // indirect
github.com/golang/protobuf v1.3.1
github.com/google/go-cmp v0.2.0 // indirect
Expand All @@ -45,7 +46,6 @@ require (
github.com/pelletier/go-buffruneio v0.2.0 // indirect
github.com/pkg/errors v0.8.1
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967
github.com/satori/go.uuid v1.2.0
github.com/sergi/go-diff v1.0.0 // indirect
github.com/sirupsen/logrus v1.4.2 // indirect
github.com/src-d/gcfg v1.3.0 // indirect
Expand All @@ -62,3 +62,5 @@ require (
gopkg.in/yaml.v2 v2.2.2
gotest.tools v2.2.0+incompatible // indirect
)

go 1.13
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -48,6 +48,8 @@ github.com/gaia-pipeline/protobuf v0.0.0-20180812091451-7be8a901b55a h1:/5XAmdAy
github.com/gaia-pipeline/protobuf v0.0.0-20180812091451-7be8a901b55a/go.mod h1:H0w7MofSuW53Nz7kesnBdVkvr437flf5B7D9Lcsb+lQ=
github.com/gliderlabs/ssh v0.1.1 h1:j3L6gSLQalDETeEg/Jg0mGY0/y/N6zI2xX1978P0Uqw=
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
Expand Down Expand Up @@ -124,8 +126,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967 h1:x7xEyJDP7Hv3LVgvWhzioQqbC/KtuUhTigKlH/8ehhE=
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
Expand Down
19 changes: 11 additions & 8 deletions handlers/pipeline.go
Expand Up @@ -5,16 +5,15 @@ import (
"strconv"
"time"

"github.com/gaia-pipeline/gaia/helper/stringhelper"

"github.com/gaia-pipeline/gaia/security"
"github.com/gofrs/uuid"
"github.com/labstack/echo"
"github.com/robfig/cron"

"github.com/gaia-pipeline/gaia"
"github.com/gaia-pipeline/gaia/helper/stringhelper"
"github.com/gaia-pipeline/gaia/security"
"github.com/gaia-pipeline/gaia/services"
"github.com/gaia-pipeline/gaia/workers/pipeline"
"github.com/labstack/echo"
"github.com/robfig/cron"
uuid "github.com/satori/go.uuid"
)

// PipelineGitLSRemote checks for available git remote branches.
Expand Down Expand Up @@ -52,15 +51,19 @@ func CreatePipeline(c echo.Context) error {
// Set initial value
p.Created = time.Now()
p.StatusType = gaia.CreatePipelineRunning
p.ID = uuid.Must(uuid.NewV4(), nil).String()
v4, err := uuid.NewV4()
if err != nil {
return c.String(http.StatusBadRequest, err.Error())
}
p.ID = uuid.Must(v4, nil).String()

// Add pipeline type tag if not already existent
if !stringhelper.IsContainedInSlice(p.Pipeline.Tags, p.Pipeline.Type.String(), true) {
p.Pipeline.Tags = append(p.Pipeline.Tags, p.Pipeline.Type.String())
}

// Save this pipeline to our store
err := storeService.CreatePipelinePut(p)
err = storeService.CreatePipelinePut(p)
if err != nil {
gaia.Cfg.Logger.Debug("cannot put pipeline into store", "error", err.Error())
return c.String(http.StatusInternalServerError, err.Error())
Expand Down
14 changes: 9 additions & 5 deletions handlers/workers.go
Expand Up @@ -6,13 +6,13 @@ import (
"net/http"
"time"

"github.com/gaia-pipeline/gaia/security"

"github.com/Pallinder/go-randomdata"
"github.com/gofrs/uuid"
"github.com/labstack/echo"

"github.com/gaia-pipeline/gaia"
"github.com/gaia-pipeline/gaia/security"
"github.com/gaia-pipeline/gaia/services"
"github.com/labstack/echo"
uuid "github.com/satori/go.uuid"
)

const (
Expand Down Expand Up @@ -57,8 +57,12 @@ func RegisterWorker(c echo.Context) error {
worker.Name = randomdata.SillyName() + "_" + randomdata.SillyName()
}

v4, err := uuid.NewV4()
if err != nil {
return c.String(http.StatusInternalServerError, "error generating uuid")
}
w := gaia.Worker{
UniqueID: uuid.Must(uuid.NewV4(), nil).String(),
UniqueID: uuid.Must(v4, nil).String(),
Name: worker.Name,
Tags: worker.Tags,
RegisterDate: time.Now(),
Expand Down
4 changes: 2 additions & 2 deletions security/secret_generator.go
Expand Up @@ -3,13 +3,13 @@ package security
import (
"crypto/rand"

uuid "github.com/satori/go.uuid"
"github.com/gofrs/uuid"
)

// GenerateRandomUUIDV5 will return a 32bit random seeded UUID based on
// a randomly generated UUID v4.
func GenerateRandomUUIDV5() string {
nsUUID := uuid.NewV4()
nsUUID, _ := uuid.NewV4()
token := make([]byte, 32)
_, _ = rand.Read(token)
namespace := string(token)
Expand Down
39 changes: 27 additions & 12 deletions store/store_test.go
Expand Up @@ -8,8 +8,9 @@ import (
"testing"
"time"

"github.com/gofrs/uuid"

"github.com/gaia-pipeline/gaia"
uuid "github.com/satori/go.uuid"
)

func TestInit(t *testing.T) {
Expand Down Expand Up @@ -172,8 +173,12 @@ func TestCreatePipelinePut(t *testing.T) {
}
defer store.Close()

v4, err := uuid.NewV4()
if err != nil {
t.Fatal(err)
}
p := &gaia.CreatePipeline{
ID: uuid.Must(uuid.NewV4(), nil).String(),
ID: uuid.Must(v4, nil).String(),
Created: time.Now(),
StatusType: gaia.CreatePipelineRunning,
Pipeline: gaia.Pipeline{
Expand Down Expand Up @@ -206,8 +211,9 @@ func TestCreatePipelineGet(t *testing.T) {
var getIDs []string

for i := 0; i < 3; i++ {
v4, _ := uuid.NewV4()
p := gaia.CreatePipeline{
ID: uuid.Must(uuid.NewV4(), nil).String(),
ID: uuid.Must(v4, nil).String(),
Pipeline: gaia.Pipeline{
Repo: &gaia.GitRepo{},
},
Expand Down Expand Up @@ -388,23 +394,25 @@ func TestPipelineGetRunHighestID(t *testing.T) {
t.Fatal(err)
}

v4, _ := uuid.NewV4()
pipelineRun1 := &gaia.PipelineRun{
ID: 1,
PipelineID: 1,
Status: gaia.RunRunning,
UniqueID: uuid.Must(uuid.NewV4(), nil).String(),
UniqueID: uuid.Must(v4, nil).String(),
StartDate: time.Now(),
}
err = store.PipelinePutRun(pipelineRun1)
if err != nil {
t.Fatal(err)
}

newV4, _ := uuid.NewV4()
pipelineRun2 := &gaia.PipelineRun{
ID: 2,
PipelineID: 1,
Status: gaia.RunRunning,
UniqueID: uuid.Must(uuid.NewV4(), nil).String(),
UniqueID: uuid.Must(newV4, nil).String(),
StartDate: time.Now(),
}
err = store.PipelinePutRun(pipelineRun2)
Expand Down Expand Up @@ -439,8 +447,9 @@ func TestPipelinePutRun(t *testing.T) {
}
defer store.Close()

v4, _ := uuid.NewV4()
run := gaia.PipelineRun{
UniqueID: uuid.Must(uuid.NewV4(), nil).String(),
UniqueID: uuid.Must(v4, nil).String(),
ID: 1,
PipelineID: 1,
ScheduleDate: time.Now(),
Expand Down Expand Up @@ -470,22 +479,24 @@ func TestPipelineGetScheduled(t *testing.T) {
}
defer store.Close()

v4, _ := uuid.NewV4()
pipelineRun1 := &gaia.PipelineRun{
ID: 1,
PipelineID: 1,
Status: gaia.RunNotScheduled,
UniqueID: uuid.Must(uuid.NewV4(), nil).String(),
UniqueID: uuid.Must(v4, nil).String(),
}
err = store.PipelinePutRun(pipelineRun1)
if err != nil {
t.Fatal(err)
}

v4, _ = uuid.NewV4()
pipelineRun2 := &gaia.PipelineRun{
ID: 2,
PipelineID: 1,
Status: gaia.RunNotScheduled,
UniqueID: uuid.Must(uuid.NewV4(), nil).String(),
UniqueID: uuid.Must(v4, nil).String(),
}
err = store.PipelinePutRun(pipelineRun2)
if err != nil {
Expand Down Expand Up @@ -528,8 +539,9 @@ func TestPipelineGetRunByPipelineIDAndID(t *testing.T) {
}
defer store.Close()

v4, _ := uuid.NewV4()
run := gaia.PipelineRun{
UniqueID: uuid.Must(uuid.NewV4(), nil).String(),
UniqueID: uuid.Must(v4, nil).String(),
ID: 1,
PipelineID: 1,
ScheduleDate: time.Now(),
Expand Down Expand Up @@ -582,11 +594,12 @@ func TestPipelineGetAllRuns(t *testing.T) {
}

for i := 0; i < 2; i++ {
v4, _ := uuid.NewV4()
p := &gaia.PipelineRun{
ID: i,
PipelineID: 1,
Status: gaia.RunNotScheduled,
UniqueID: uuid.Must(uuid.NewV4(), nil).String(),
UniqueID: uuid.Must(v4, nil).String(),
}
err = store.PipelinePutRun(p)
if err != nil {
Expand Down Expand Up @@ -646,23 +659,25 @@ func TestPipelineGetLatestRun(t *testing.T) {
t.Fatal(err)
}

v4, _ := uuid.NewV4()
pipelineRun1 := &gaia.PipelineRun{
ID: 1,
PipelineID: 1,
Status: gaia.RunRunning,
UniqueID: uuid.Must(uuid.NewV4(), nil).String(),
UniqueID: uuid.Must(v4, nil).String(),
StartDate: time.Now(),
}
err = store.PipelinePutRun(pipelineRun1)
if err != nil {
t.Fatal(err)
}

v4, _ = uuid.NewV4()
pipelineRun2 := &gaia.PipelineRun{
ID: 2,
PipelineID: 1,
Status: gaia.RunRunning,
UniqueID: uuid.Must(uuid.NewV4(), nil).String(),
UniqueID: uuid.Must(v4, nil).String(),
StartDate: time.Now(),
}
err = store.PipelinePutRun(pipelineRun2)
Expand Down
10 changes: 7 additions & 3 deletions workers/pipeline/build_cpp.go
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/gaia-pipeline/gaia"
"github.com/gaia-pipeline/gaia/services"
uuid "github.com/satori/go.uuid"
"github.com/gofrs/uuid"
)

const (
Expand All @@ -28,11 +28,15 @@ type BuildPipelineCpp struct {
// PrepareEnvironment prepares the environment before we start the build process.
func (b *BuildPipelineCpp) PrepareEnvironment(p *gaia.CreatePipeline) error {
// create uniqueName for destination folder
uniqueName := uuid.Must(uuid.NewV4(), nil)
v4, err := uuid.NewV4()
if err != nil {
return err
}
uniqueName := uuid.Must(v4, nil)

// Create local temp folder for clone
cloneFolder := filepath.Join(gaia.Cfg.HomePath, gaia.TmpFolder, gaia.TmpCppFolder, srcFolder, uniqueName.String())
err := os.MkdirAll(cloneFolder, 0700)
err = os.MkdirAll(cloneFolder, 0700)
if err != nil {
return err
}
Expand Down
10 changes: 7 additions & 3 deletions workers/pipeline/build_golang.go
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/gaia-pipeline/gaia"
"github.com/gaia-pipeline/gaia/services"
uuid "github.com/satori/go.uuid"
"github.com/gofrs/uuid"
)

const (
Expand All @@ -27,12 +27,16 @@ type BuildPipelineGolang struct {
// PrepareEnvironment prepares the environment before we start the build process.
func (b *BuildPipelineGolang) PrepareEnvironment(p *gaia.CreatePipeline) error {
// create uniqueName for destination folder
uniqueName := uuid.Must(uuid.NewV4(), nil)
v4, err := uuid.NewV4()
if err != nil {
return err
}
uniqueName := uuid.Must(v4, nil)

// Create local temp folder for clone
goPath := filepath.Join(gaia.Cfg.HomePath, gaia.TmpFolder, gaia.TmpGoFolder)
cloneFolder := filepath.Join(goPath, srcFolder, uniqueName.String())
err := os.MkdirAll(cloneFolder, 0700)
err = os.MkdirAll(cloneFolder, 0700)
if err != nil {
return err
}
Expand Down
10 changes: 7 additions & 3 deletions workers/pipeline/build_java.go
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/gaia-pipeline/gaia"
"github.com/gaia-pipeline/gaia/services"
uuid "github.com/satori/go.uuid"
"github.com/gofrs/uuid"
)

var (
Expand All @@ -33,12 +33,16 @@ type BuildPipelineJava struct {
// PrepareEnvironment prepares the environment before we start the build process.
func (b *BuildPipelineJava) PrepareEnvironment(p *gaia.CreatePipeline) error {
// create uniqueName for destination folder
uniqueName := uuid.Must(uuid.NewV4(), nil)
v4, err := uuid.NewV4()
if err != nil {
return err
}
uniqueName := uuid.Must(v4, nil)

// Create local temp folder for clone
rootPath := filepath.Join(gaia.Cfg.HomePath, gaia.TmpFolder, javaFolder)
cloneFolder := filepath.Join(rootPath, srcFolder, uniqueName.String())
err := os.MkdirAll(cloneFolder, 0700)
err = os.MkdirAll(cloneFolder, 0700)
if err != nil {
return err
}
Expand Down
11 changes: 8 additions & 3 deletions workers/pipeline/build_nodejs.go
Expand Up @@ -12,7 +12,7 @@ import (

"github.com/gaia-pipeline/gaia"
"github.com/gaia-pipeline/gaia/services"
uuid "github.com/satori/go.uuid"
"github.com/gofrs/uuid"
)

const nodeJSInternalCloneFolder = "jsclone"
Expand All @@ -25,11 +25,16 @@ type BuildPipelineNodeJS struct {
// PrepareEnvironment prepares the environment before we start the build process.
func (b *BuildPipelineNodeJS) PrepareEnvironment(p *gaia.CreatePipeline) error {
// create uniqueName for destination folder
uniqueName := uuid.Must(uuid.NewV4(), nil)
v4, err := uuid.NewV4()
if err != nil {
gaia.Cfg.Logger.Debug("unable to generate uuid", "error", err.Error())
return err
}
uniqueName := uuid.Must(v4, nil)

// Create local temp folder for clone
cloneFolder := filepath.Join(gaia.Cfg.HomePath, gaia.TmpFolder, gaia.TmpNodeJSFolder, srcFolder, uniqueName.String(), nodeJSInternalCloneFolder)
err := os.MkdirAll(cloneFolder, 0700)
err = os.MkdirAll(cloneFolder, 0700)
if err != nil {
return err
}
Expand Down

0 comments on commit a548246

Please sign in to comment.