diff --git a/bridge/core/token.go b/bridge/core/token.go index bd97cd1823d9b72f41ae2085b7743747c2efd158..cd5303d58c1eebf114c1b35b8c977ebe85a99268 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 f33ee3e38fbfe476870cd708c4eba012961217f9..cdae066489eed60d159b0195504ca3abd3a1c574 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)