Skip to content

Commit

Permalink
deprecate use of github.com/satori/go.uuid for github.com/gofrs/uuid
Browse files Browse the repository at this point in the history
Gopkg.toml version of [email protected] did not include non-random uuid fix:
satori/go.uuid#73

also, deprecation notice for satori/go.uuid posted via issue:
satori/go.uuid#84

community recommended replacement is available at github.com/gofrs/uuid

* updated Gopkg.toml to use github.com/gofrs/uuid @ 3.1.2
* rebuilt Gopkg.lock
* incorporate symmantics of uuid.NewV4() can return error

Signed-off-by: David Gervais <[email protected]>
  • Loading branch information
dgervais committed Dec 26, 2018
1 parent 6402c88 commit 7be8c67
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 31 deletions.
20 changes: 11 additions & 9 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# unused-packages = true

required = ["github.com/hashicorp/go-plugin",
"github.com/satori/go.uuid",
"github.com/gofrs/uuid",
"github.com/golang/protobuf/protoc-gen-go",
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway",
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger",
Expand Down Expand Up @@ -88,8 +88,8 @@ required = ["github.com/hashicorp/go-plugin",
version = "1.0.0"

[[constraint]]
name = "github.com/satori/go.uuid"
version = "1.2.0"
name = "github.com/gofrs/uuid"
version = "3.1.2"

[[constraint]]
name = "github.com/shirou/gopsutil"
Expand Down
8 changes: 6 additions & 2 deletions pkg/agent/manager/cache/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cache
import (
"sync"

"github.com/satori/go.uuid"
"github.com/gofrs/uuid"
"github.com/spiffe/spire/pkg/common/selector"
)

Expand Down Expand Up @@ -33,10 +33,14 @@ type subscribers struct {
}

func NewSubscriber(selectors Selectors) (*subscriber, error) {
u, err := uuid.NewV4()
if err != nil {
return nil, err
}
return &subscriber{
c: make(chan *WorkloadUpdate, 1),
sel: selectors,
sid: uuid.NewV4(),
sid: u,
active: true,
}, nil
}
Expand Down
17 changes: 12 additions & 5 deletions pkg/agent/plugin/nodeattestor/k8s/sat.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"io/ioutil"
"sync"

"github.com/gofrs/uuid"
"github.com/hashicorp/hcl"
uuid "github.com/satori/go.uuid"
"github.com/spiffe/spire/pkg/common/plugin/k8s"
"github.com/spiffe/spire/proto/agent/nodeattestor"
"github.com/spiffe/spire/proto/common"
Expand Down Expand Up @@ -41,16 +41,20 @@ type SATAttestorPlugin struct {
config *satAttestorConfig

hooks struct {
newUUID func() string
newUUID func() (string, error)
}
}

var _ nodeattestor.Plugin = (*SATAttestorPlugin)(nil)

func NewSATAttestorPlugin() *SATAttestorPlugin {
p := &SATAttestorPlugin{}
p.hooks.newUUID = func() string {
return uuid.NewV4().String()
p.hooks.newUUID = func() (string, error) {
u, err := uuid.NewV4()
if err != nil {
return "", err
}
return u.String(), nil
}
return p
}
Expand All @@ -61,7 +65,10 @@ func (p *SATAttestorPlugin) FetchAttestationData(stream nodeattestor.FetchAttest
return err
}

uuid := p.hooks.newUUID()
uuid, err := p.hooks.newUUID()
if err != nil {
return err
}

token, err := loadTokenFromFile(config.tokenPath)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/plugin/nodeattestor/k8s/sat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func (s *SATAttestorSuite) TestGetPluginInfo() {

func (s *SATAttestorSuite) newAttestor() {
attestor := NewSATAttestorPlugin()
attestor.hooks.newUUID = func() string {
return "UUID"
attestor.hooks.newUUID = func() (string, error) {
return "UUID", nil
}
s.attestor = nodeattestor.NewBuiltIn(attestor)
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/server/endpoints/registration/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"net/url"
"time"

"github.com/gofrs/uuid"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes/wrappers"
"github.com/satori/go.uuid"
"github.com/sirupsen/logrus"
"github.com/spiffe/spire/pkg/common/bundleutil"
"github.com/spiffe/spire/pkg/common/idutil"
Expand Down Expand Up @@ -425,7 +425,11 @@ func (h *Handler) CreateJoinToken(

// Generate a token if one wasn't specified
if request.Token == "" {
request.Token = uuid.NewV4().String()
u, err := uuid.NewV4()
if err != nil {
return nil, errors.New("Error generating uuid token: %v")
}
request.Token = u.String()
}

ds := h.getDataStore()
Expand Down
15 changes: 11 additions & 4 deletions pkg/server/plugin/datastore/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"sync"
"time"

"github.com/gofrs/uuid"
"github.com/golang/protobuf/proto"
"github.com/hashicorp/hcl"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
uuid "github.com/satori/go.uuid"
"github.com/spiffe/spire/pkg/common/bundleutil"
"github.com/spiffe/spire/pkg/common/idutil"
"github.com/spiffe/spire/pkg/common/selector"
Expand Down Expand Up @@ -772,7 +772,10 @@ func createRegistrationEntry(tx *gorm.DB,
return nil, err
}

entryID := newRegistrationEntryID()
entryID, err := newRegistrationEntryID()
if err != nil {
return nil, err
}

newRegisteredEntry := RegisteredEntry{
EntryID: entryID,
Expand Down Expand Up @@ -1235,8 +1238,12 @@ func modelToEntry(tx *gorm.DB, model RegisteredEntry) (*common.RegistrationEntry
}, nil
}

func newRegistrationEntryID() string {
return uuid.NewV4().String()
func newRegistrationEntryID() (string, error) {
u, err := uuid.NewV4()
if err != nil {
return "", err
}
return u.String(), nil
}

func modelToAttestedNode(model AttestedNode) *datastore.AttestedNode {
Expand Down
15 changes: 11 additions & 4 deletions test/fakes/fakedatastore/fakedatastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"sort"
"sync"

"github.com/gofrs/uuid"
"github.com/golang/protobuf/proto"
_ "github.com/jinzhu/gorm/dialects/sqlite"
uuid "github.com/satori/go.uuid"
"github.com/spiffe/spire/pkg/common/bundleutil"
"github.com/spiffe/spire/pkg/common/selector"
"github.com/spiffe/spire/pkg/common/util"
Expand Down Expand Up @@ -310,7 +310,10 @@ func (s *DataStore) CreateRegistrationEntry(ctx context.Context,
s.mu.Lock()
defer s.mu.Unlock()

entryID := newRegistrationEntryID()
entryID, err := newRegistrationEntryID()
if err != nil {
return nil, err
}

entry := cloneRegistrationEntry(req.Entry)
entry.EntryId = entryID
Expand Down Expand Up @@ -603,8 +606,12 @@ func cloneJoinToken(token *datastore.JoinToken) *datastore.JoinToken {
return proto.Clone(token).(*datastore.JoinToken)
}

func newRegistrationEntryID() string {
return uuid.NewV4().String()
func newRegistrationEntryID() (string, error) {
u, err := uuid.NewV4()
if err != nil {
return "", err
}
return u.String(), nil
}

func containsSelectors(selectors, subset []*common.Selector) bool {
Expand Down

0 comments on commit 7be8c67

Please sign in to comment.