Skip to content

Commit ce93e93

Browse files
authored
Merge pull request #221 from koding/adapt-uuid
kite: adapt code to latest go.uuid version
2 parents 4bed82c + b611793 commit ce93e93

File tree

9 files changed

+65
-71
lines changed

9 files changed

+65
-71
lines changed

Gopkg.lock

Lines changed: 33 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@
8585
name = "github.com/mitchellh/cli"
8686

8787
[[constraint]]
88+
branch = "master"
8889
name = "github.com/satori/go.uuid"
89-
version = "1.1.0"
9090

9191
[[constraint]]
9292
branch = "master"

kite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ func NewWithConfig(name, version string, cfg *config.Config) *Kite {
171171
panic("kite: version must be 3-digits semantic version")
172172
}
173173

174-
kiteID := uuid.NewV4()
174+
kiteID := uuid.Must(uuid.NewV4())
175175

176176
l, setlevel := newLogger(name)
177177

kite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func TestContext(t *testing.T) {
9696
}
9797

9898
if !reflect.DeepEqual(got, want) {
99-
t.Fatalf("got %v, want %v")
99+
t.Fatalf("got %v, want %v", got, want)
100100
}
101101
}
102102

kitetest/kitetest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (k *KiteKey) id() string {
3636
if k.ID != "" {
3737
return k.ID
3838
}
39-
return uuid.NewV4().String()
39+
return uuid.Must(uuid.NewV4()).String()
4040
}
4141

4242
func (k *KiteKey) issuer() string {

kontrol/bench_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func BenchmarkPostgres(b *testing.B) {
1212
kon.SetStorage(NewPostgres(nil, kon.Kite.Log))
1313

1414
newKite := func() *protocol.Kite {
15-
id := uuid.NewV4()
15+
id := uuid.Must(uuid.NewV4())
1616
return &protocol.Kite{
1717
Username: "bench-user",
1818
Environment: "bench-env",
@@ -53,7 +53,7 @@ func BenchmarkEtcdAdd(b *testing.B) {
5353
kon.SetStorage(NewEtcd(nil, kon.Kite.Log))
5454

5555
newKite := func() *protocol.Kite {
56-
id := uuid.NewV4()
56+
id := uuid.Must(uuid.NewV4())
5757
return &protocol.Kite{
5858
Username: "bench-user",
5959
Environment: "bench-env",

kontrol/kontrol.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,10 @@ func (k *Kontrol) AddKeyPair(id, public, private string) error {
283283
}
284284

285285
if id == "" {
286-
i := uuid.NewV4()
286+
i, err := uuid.NewV4()
287+
if err != nil {
288+
return err
289+
}
287290
id = i.String()
288291
}
289292

@@ -358,12 +361,16 @@ func (k *Kontrol) InitializeSelf() error {
358361
}
359362

360363
func (k *Kontrol) registerUser(username, publicKey, privateKey string) (kiteKey string, err error) {
364+
id, err := uuid.NewV4()
365+
if err != nil {
366+
return "", err
367+
}
361368
claims := &kitekey.KiteClaims{
362369
StandardClaims: jwt.StandardClaims{
363370
Issuer: k.Kite.Kite().Username,
364371
Subject: username,
365372
IssuedAt: time.Now().Add(-k.tokenLeeway()).UTC().Unix(),
366-
Id: uuid.NewV4().String(),
373+
Id: id.String(),
367374
},
368375
KontrolURL: k.Kite.Config.KontrolURL,
369376
KontrolKey: strings.TrimSpace(publicKey),
@@ -400,12 +407,17 @@ func (k *Kontrol) registerSelf() {
400407
// to generate its kitekey or no kitekey is defined,
401408
// use a dummy entry in order to register the kontrol.
402409
keyPair = &KeyPair{
403-
ID: uuid.NewV4().String(),
404410
Public: "kontrol-self",
405411
Private: "kontrol-self",
406412
}
407413

408-
if err := k.keyPair.AddKey(keyPair); err != nil {
414+
if id, err := uuid.NewV4(); err == nil {
415+
keyPair.ID = id.String()
416+
417+
if err := k.keyPair.AddKey(keyPair); err != nil {
418+
k.log.Error("%s", err)
419+
}
420+
} else {
409421
k.log.Error("%s", err)
410422
}
411423
}
@@ -562,6 +574,11 @@ func (k *Kontrol) generateToken(tok *token) (string, error) {
562574
return "", err
563575
}
564576

577+
id, err := uuid.NewV4()
578+
if err != nil {
579+
return "", err
580+
}
581+
565582
now := time.Now().UTC()
566583

567584
claims := &kitekey.KiteClaims{
@@ -571,7 +588,7 @@ func (k *Kontrol) generateToken(tok *token) (string, error) {
571588
Audience: tok.audience,
572589
ExpiresAt: now.Add(k.tokenTTL()).Add(k.tokenLeeway()).UTC().Unix(),
573590
IssuedAt: now.Add(-k.tokenLeeway()).UTC().Unix(),
574-
Id: uuid.NewV4().String(),
591+
Id: id.String(),
575592
},
576593
}
577594

kontrol/kontrol_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func init() {
3636

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

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

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

667-
i := uuid.NewV4()
667+
i := uuid.Must(uuid.NewV4())
668668
secondID := i.String()
669669

670670
// add so we can use it as key

testutil/testutil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewKiteKeyWithKeyPair(private, public string) *jwt.Token {
3434
// NewToken creates new JWT token for the gien username. It embedds the given
3535
// public key as kontrolKey and signs the token with the private one.
3636
func NewToken(username, private, public string) *jwt.Token {
37-
tknID := uuid.NewV4()
37+
tknID := uuid.Must(uuid.NewV4())
3838

3939
hostname, err := os.Hostname()
4040
if err != nil {

0 commit comments

Comments
 (0)