aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/core/token.go
diff options
context:
space:
mode:
authoramine <hilalyamine@gmail.com>2019-10-24 20:39:13 +0200
committeramine <hilalyamine@gmail.com>2019-11-09 13:26:52 +0100
commit4dc7b8b06ed5d48eca077b81a0b8c90777b8fe82 (patch)
tree7689235363d4aa9722ca4ca8cc37f66f6250c3d9 /bridge/core/token.go
parentbaefa687b582632cd9cc21b945bc074c833f5389 (diff)
downloadgit-bug-4dc7b8b06ed5d48eca077b81a0b8c90777b8fe82.tar.gz
tokens: use entity.Id as id type
Diffstat (limited to 'bridge/core/token.go')
-rw-r--r--bridge/core/token.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/bridge/core/token.go b/bridge/core/token.go
index bd97cd18..cd5303d5 100644
--- a/bridge/core/token.go
+++ b/bridge/core/token.go
@@ -4,6 +4,7 @@ import (
"crypto/sha256"
"encoding/json"
"fmt"
+ "github.com/MichaelMure/git-bug/entity"
"regexp"
"strings"
@@ -19,7 +20,7 @@ const (
// Token holds an API access token data
type Token struct {
- ID string
+ id entity.Id
Value string
Target string
Global bool
@@ -35,22 +36,22 @@ func NewToken(value, target string, global bool, scopes []string) *Token {
Scopes: scopes,
}
- token.ID = hashToken(token)
+ token.id = entity.Id(hashToken(token))
return token
}
// Id return full token identifier. It will compute the Id if it's empty
func (t *Token) Id() string {
- if t.ID == "" {
- t.ID = hashToken(t)
+ if t.id == "" {
+ t.id = entity.Id(hashToken(t))
}
- return t.ID
+ return t.id.String()
}
// HumanId return the truncated token id
func (t *Token) HumanId() string {
- return t.Id()[:6]
+ return t.id.Human()
}
func hashToken(token *Token) string {
@@ -65,7 +66,7 @@ func hashToken(token *Token) string {
// Validate ensure token important fields are valid
func (t *Token) Validate() error {
- if t.ID == "" {
+ if t.id == "" {
return fmt.Errorf("missing id")
}
if t.Value == "" {
@@ -111,7 +112,7 @@ func loadToken(repo repository.RepoConfig, id string, global bool) (*Token, erro
}
var ok bool
- token := &Token{ID: id, Global: global}
+ token := &Token{id: entity.Id(id), Global: global}
token.Value, ok = configs[tokenValueKey]
if !ok {