Skip to content

kite: adapt code to latest go.uuid version #221

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

Merged
merged 2 commits into from
Jun 24, 2018
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
89 changes: 33 additions & 56 deletions Gopkg.lock

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

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
name = "github.com/mitchellh/cli"

[[constraint]]
branch = "master"
name = "github.com/satori/go.uuid"
version = "1.1.0"

[[constraint]]
branch = "master"
Expand Down
2 changes: 1 addition & 1 deletion kite.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func NewWithConfig(name, version string, cfg *config.Config) *Kite {
panic("kite: version must be 3-digits semantic version")
}

kiteID := uuid.NewV4()
kiteID := uuid.Must(uuid.NewV4())

l, setlevel := newLogger(name)

Expand Down
2 changes: 1 addition & 1 deletion kite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestContext(t *testing.T) {
}

if !reflect.DeepEqual(got, want) {
t.Fatalf("got %v, want %v")
t.Fatalf("got %v, want %v", got, want)
}
}

Expand Down
2 changes: 1 addition & 1 deletion kitetest/kitetest.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (k *KiteKey) id() string {
if k.ID != "" {
return k.ID
}
return uuid.NewV4().String()
return uuid.Must(uuid.NewV4()).String()
}

func (k *KiteKey) issuer() string {
Expand Down
4 changes: 2 additions & 2 deletions kontrol/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func BenchmarkPostgres(b *testing.B) {
kon.SetStorage(NewPostgres(nil, kon.Kite.Log))

newKite := func() *protocol.Kite {
id := uuid.NewV4()
id := uuid.Must(uuid.NewV4())
return &protocol.Kite{
Username: "bench-user",
Environment: "bench-env",
Expand Down Expand Up @@ -53,7 +53,7 @@ func BenchmarkEtcdAdd(b *testing.B) {
kon.SetStorage(NewEtcd(nil, kon.Kite.Log))

newKite := func() *protocol.Kite {
id := uuid.NewV4()
id := uuid.Must(uuid.NewV4())
return &protocol.Kite{
Username: "bench-user",
Environment: "bench-env",
Expand Down
27 changes: 22 additions & 5 deletions kontrol/kontrol.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,10 @@ func (k *Kontrol) AddKeyPair(id, public, private string) error {
}

if id == "" {
i := uuid.NewV4()
i, err := uuid.NewV4()
if err != nil {
return err
}
id = i.String()
}

Expand Down Expand Up @@ -358,12 +361,16 @@ func (k *Kontrol) InitializeSelf() error {
}

func (k *Kontrol) registerUser(username, publicKey, privateKey string) (kiteKey string, err error) {
id, err := uuid.NewV4()
if err != nil {
return "", err
}
claims := &kitekey.KiteClaims{
StandardClaims: jwt.StandardClaims{
Issuer: k.Kite.Kite().Username,
Subject: username,
IssuedAt: time.Now().Add(-k.tokenLeeway()).UTC().Unix(),
Id: uuid.NewV4().String(),
Id: id.String(),
},
KontrolURL: k.Kite.Config.KontrolURL,
KontrolKey: strings.TrimSpace(publicKey),
Expand Down Expand Up @@ -400,12 +407,17 @@ func (k *Kontrol) registerSelf() {
// to generate its kitekey or no kitekey is defined,
// use a dummy entry in order to register the kontrol.
keyPair = &KeyPair{
ID: uuid.NewV4().String(),
Public: "kontrol-self",
Private: "kontrol-self",
}

if err := k.keyPair.AddKey(keyPair); err != nil {
if id, err := uuid.NewV4(); err == nil {
keyPair.ID = id.String()

if err := k.keyPair.AddKey(keyPair); err != nil {
k.log.Error("%s", err)
}
} else {
k.log.Error("%s", err)
}
}
Expand Down Expand Up @@ -562,6 +574,11 @@ func (k *Kontrol) generateToken(tok *token) (string, error) {
return "", err
}

id, err := uuid.NewV4()
if err != nil {
return "", err
}

now := time.Now().UTC()

claims := &kitekey.KiteClaims{
Expand All @@ -571,7 +588,7 @@ func (k *Kontrol) generateToken(tok *token) (string, error) {
Audience: tok.audience,
ExpiresAt: now.Add(k.tokenTTL()).Add(k.tokenLeeway()).UTC().Unix(),
IssuedAt: now.Add(-k.tokenLeeway()).UTC().Unix(),
Id: uuid.NewV4().String(),
Id: id.String(),
},
}

Expand Down
6 changes: 3 additions & 3 deletions kontrol/kontrol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func init() {

func TestUpdateKeys(t *testing.T) {
if storage := os.Getenv("KONTROL_STORAGE"); storage != "postgres" {
t.Skip("skipping TestUpdateKeys for storage %q: not implemented", storage)
t.Skipf("skipping TestUpdateKeys for storage %q: not implemented", storage)
}

kon, conf := startKontrol(testkeys.PrivateThird, testkeys.PublicThird, 5501)
Expand Down Expand Up @@ -661,10 +661,10 @@ func TestGetQueryKey(t *testing.T) {

func TestKontrolMultiKey(t *testing.T) {
if storage := os.Getenv("KONTROL_STORAGE"); storage != "postgres" {
t.Skip("%q storage does not currently implement soft key pair deletes", storage)
t.Skipf("%q storage does not currently implement soft key pair deletes", storage)
}

i := uuid.NewV4()
i := uuid.Must(uuid.NewV4())
secondID := i.String()

// add so we can use it as key
Expand Down
2 changes: 1 addition & 1 deletion testutil/testutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewKiteKeyWithKeyPair(private, public string) *jwt.Token {
// NewToken creates new JWT token for the gien username. It embedds the given
// public key as kontrolKey and signs the token with the private one.
func NewToken(username, private, public string) *jwt.Token {
tknID := uuid.NewV4()
tknID := uuid.Must(uuid.NewV4())

hostname, err := os.Hostname()
if err != nil {
Expand Down