aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bridge/core/token.go45
-rw-r--r--commands/bridge_token.go7
-rw-r--r--commands/bridge_token_add.go2
-rw-r--r--repository/git.go12
4 files changed, 25 insertions, 41 deletions
diff --git a/bridge/core/token.go b/bridge/core/token.go
index 5e629c51..0147f747 100644
--- a/bridge/core/token.go
+++ b/bridge/core/token.go
@@ -10,14 +10,12 @@ import (
const (
tokenConfigKeyPrefix = "git-bug.token"
- tokenKeyValue = "value"
tokenKeyTarget = "target"
tokenKeyScopes = "scopes"
)
// Token represent token related informations
type Token struct {
- Id string
Value string
Target string
Global bool
@@ -25,9 +23,8 @@ type Token struct {
}
// NewToken instantiate a new token
-func NewToken(id, value, target string, global bool, scopes []string) *Token {
+func NewToken(value, target string, global bool, scopes []string) *Token {
return &Token{
- Id: id,
Value: value,
Target: target,
Global: global,
@@ -37,9 +34,6 @@ func NewToken(id, value, target string, global bool, scopes []string) *Token {
// Validate ensure token important fields are valid
func (t *Token) Validate() error {
- if t.Id == "" {
- return fmt.Errorf("missing token id")
- }
if t.Value == "" {
return fmt.Errorf("missing token value")
}
@@ -49,8 +43,8 @@ func (t *Token) Validate() error {
return nil
}
-func loadToken(repo repository.RepoConfig, id string, global bool) (*Token, error) {
- keyPrefix := fmt.Sprintf("git-bug.token.%s.", id)
+func loadToken(repo repository.RepoConfig, value string, global bool) (*Token, error) {
+ keyPrefix := fmt.Sprintf("git-bug.token.%s.", value)
var pairs map[string]string
var err error
@@ -75,12 +69,7 @@ func loadToken(repo repository.RepoConfig, id string, global bool) (*Token, erro
}
var ok bool
- token := &Token{Id: id, Global: global}
- token.Value, ok = result[tokenKeyValue]
- if !ok {
- return nil, fmt.Errorf("empty token value")
- }
-
+ token := &Token{Value: value, Global: global}
token.Target, ok = result[tokenKeyTarget]
if !ok {
return nil, fmt.Errorf("empty token key")
@@ -96,13 +85,13 @@ func loadToken(repo repository.RepoConfig, id string, global bool) (*Token, erro
}
// GetToken loads a token from repo config
-func GetToken(repo repository.RepoConfig, id string) (*Token, error) {
- return loadToken(repo, id, false)
+func GetToken(repo repository.RepoConfig, value string) (*Token, error) {
+ return loadToken(repo, value, false)
}
// GetGlobalToken loads a token from the global config
-func GetGlobalToken(repo repository.RepoConfig, id string) (*Token, error) {
- return loadToken(repo, id, true)
+func GetGlobalToken(repo repository.RepoConfig, value string) (*Token, error) {
+ return loadToken(repo, value, true)
}
func listTokens(repo repository.RepoConfig, global bool) ([]string, error) {
@@ -166,19 +155,13 @@ func storeToken(repo repository.RepoConfig, token *Token) error {
}
var err error
- storeValueKey := fmt.Sprintf("git-bug.token.%s.%s", token.Id, tokenKeyValue)
- err = store(storeValueKey, token.Value)
- if err != nil {
- return err
- }
-
- storeTargetKey := fmt.Sprintf("git-bug.token.%s.%s", token.Id, tokenKeyTarget)
+ storeTargetKey := fmt.Sprintf("git-bug.token.%s.%s", token.Value, tokenKeyTarget)
err = store(storeTargetKey, token.Target)
if err != nil {
return err
}
- storeScopesKey := fmt.Sprintf("git-bug.token.%s.%s", token.Id, tokenKeyScopes)
+ storeScopesKey := fmt.Sprintf("git-bug.token.%s.%s", token.Value, tokenKeyScopes)
err = store(storeScopesKey, strings.Join(token.Scopes, ","))
if err != nil {
return err
@@ -198,13 +181,13 @@ func StoreGlobalToken(repo repository.RepoConfig, token *Token) error {
}
// RemoveToken removes a token from the repo config
-func RemoveToken(repo repository.RepoConfig, id string) error {
- keyPrefix := fmt.Sprintf("git-bug.token.%s", id)
+func RemoveToken(repo repository.RepoConfig, value string) error {
+ keyPrefix := fmt.Sprintf("git-bug.token.%s", value)
return repo.RmConfigs(keyPrefix)
}
// RemoveGlobalToken removes a token from the repo config
-func RemoveGlobalToken(repo repository.RepoConfig, id string) error {
- keyPrefix := fmt.Sprintf("git-bug.token.%s", id)
+func RemoveGlobalToken(repo repository.RepoConfig, value string) error {
+ keyPrefix := fmt.Sprintf("git-bug.token.%s", value)
return repo.RmGlobalConfigs(keyPrefix)
}
diff --git a/commands/bridge_token.go b/commands/bridge_token.go
index 52dea9a9..cb9754c3 100644
--- a/commands/bridge_token.go
+++ b/commands/bridge_token.go
@@ -59,14 +59,13 @@ func runTokenBridge(cmd *cobra.Command, args []string) error {
for _, token := range tokens {
valueFmt := text.LeftPadMaxLine(token.Value, 20, 0)
- targetFmt := text.LeftPadMaxLine(token.Target, 10, 0)
+ targetFmt := text.LeftPadMaxLine(token.Target, 8, 0)
scopesFmt := text.LeftPadMaxLine(strings.Join(token.Scopes, ","), 20, 0)
- fmt.Printf("%s %s %s %s %s\n",
- colors.Cyan(token.Id),
+ fmt.Printf("%s %s %s %s\n",
+ valueFmt,
colors.Magenta(targetFmt),
colors.Yellow(token.Global),
- valueFmt,
scopesFmt,
)
}
diff --git a/commands/bridge_token_add.go b/commands/bridge_token_add.go
index 8b3fc5ce..1e62a383 100644
--- a/commands/bridge_token_add.go
+++ b/commands/bridge_token_add.go
@@ -34,11 +34,9 @@ var bridgeTokenAddCmd = &cobra.Command{
func init() {
bridgeTokenCmd.AddCommand(bridgeTokenAddCmd)
- bridgeTokenAddCmd.Flags().StringVarP(&bridgeToken.Id, "id", "i", "", "")
bridgeTokenAddCmd.Flags().BoolVarP(&bridgeToken.Global, "global", "g", false, "")
bridgeTokenAddCmd.Flags().StringVarP(&bridgeToken.Value, "value", "v", "", "")
bridgeTokenAddCmd.Flags().StringVarP(&bridgeToken.Target, "target", "t", "", "")
bridgeTokenAddCmd.Flags().StringArrayVarP(&bridgeToken.Scopes, "scopes", "s", []string{}, "")
bridgeTokenAddCmd.Flags().SortFlags = false
-
}
diff --git a/repository/git.go b/repository/git.go
index 2b00d1f2..2c72fccd 100644
--- a/repository/git.go
+++ b/repository/git.go
@@ -15,11 +15,15 @@ import (
"github.com/MichaelMure/git-bug/util/lamport"
)
-const createClockFile = "/git-bug/create-clock"
-const editClockFile = "/git-bug/edit-clock"
+const (
+ createClockFile = "/git-bug/create-clock"
+ editClockFile = "/git-bug/edit-clock"
+)
-// ErrNotARepo is the error returned when the git repo root wan't be found
-var ErrNotARepo = errors.New("not a git repository")
+var (
+ // ErrNotARepo is the error returned when the git repo root wan't be found
+ ErrNotARepo = errors.New("not a git repository")
+)
var _ ClockedRepo = &GitRepo{}