diff options
author | amine <hilalyamine@gmail.com> | 2019-10-24 20:39:13 +0200 |
---|---|---|
committer | amine <hilalyamine@gmail.com> | 2019-11-09 13:26:52 +0100 |
commit | 4dc7b8b06ed5d48eca077b81a0b8c90777b8fe82 (patch) | |
tree | 7689235363d4aa9722ca4ca8cc37f66f6250c3d9 | |
parent | baefa687b582632cd9cc21b945bc074c833f5389 (diff) | |
download | git-bug-4dc7b8b06ed5d48eca077b81a0b8c90777b8fe82.tar.gz |
tokens: use entity.Id as id type
-rw-r--r-- | bridge/core/token.go | 17 | ||||
-rw-r--r-- | commands/bridge_token.go | 2 |
2 files changed, 10 insertions, 9 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 { diff --git a/commands/bridge_token.go b/commands/bridge_token.go index f33ee3e3..cdae0664 100644 --- a/commands/bridge_token.go +++ b/commands/bridge_token.go @@ -49,7 +49,7 @@ func runTokenBridge(cmd *cobra.Command, args []string) error { } func printToken(token *core.Token) { - idFmt := text.LeftPadMaxLine(token.HumanId(), 6, 0) + idFmt := text.LeftPadMaxLine(token.HumanId(), 7, 0) valueFmt := text.LeftPadMaxLine(token.Value, 8, 0) targetFmt := text.LeftPadMaxLine(token.Target, 8, 0) scopesFmt := text.LeftPadMaxLine(strings.Join(token.Scopes, ","), 20, 0) |