aboutsummaryrefslogtreecommitdiffstats
path: root/bridge/core/auth/token.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-02-09 01:31:00 +0100
committerGitHub <noreply@github.com>2020-02-09 01:31:00 +0100
commit9e1a987b4d94dc5c2115423ede5954d4faf1d342 (patch)
treee30bb28d55444a7d1e66c8fa8b8ba7d413805473 /bridge/core/auth/token.go
parent97bc5ccd229b7b438262a84e3c42783b4d4a82af (diff)
parent9b1aaa032d36e1ac05504916e359f767d1622d9d (diff)
downloadgit-bug-9e1a987b4d94dc5c2115423ede5954d4faf1d342.tar.gz
Merge pull request #294 from MichaelMure/cred-metadata
Cred metadata
Diffstat (limited to 'bridge/core/auth/token.go')
-rw-r--r--bridge/core/auth/token.go31
1 files changed, 19 insertions, 12 deletions
diff --git a/bridge/core/auth/token.go b/bridge/core/auth/token.go
index 8333ef12..42f960bf 100644
--- a/bridge/core/auth/token.go
+++ b/bridge/core/auth/token.go
@@ -18,16 +18,15 @@ var _ Credential = &Token{}
// Token holds an API access token data
type Token struct {
- userId entity.Id
target string
createTime time.Time
Value string
+ meta map[string]string
}
// NewToken instantiate a new token
-func NewToken(userId entity.Id, value, target string) *Token {
+func NewToken(value, target string) *Token {
return &Token{
- userId: userId,
target: target,
createTime: time.Now(),
Value: value,
@@ -37,7 +36,6 @@ func NewToken(userId entity.Id, value, target string) *Token {
func NewTokenFromConfig(conf map[string]string) *Token {
token := &Token{}
- token.userId = entity.Id(conf[configKeyUserId])
token.target = conf[configKeyTarget]
if createTime, ok := conf[configKeyCreateTime]; ok {
if t, err := repository.ParseTimestamp(createTime); err == nil {
@@ -46,6 +44,7 @@ func NewTokenFromConfig(conf map[string]string) *Token {
}
token.Value = conf[tokenValueKey]
+ token.meta = metaFromConfig(conf)
return token
}
@@ -55,14 +54,6 @@ func (t *Token) ID() entity.Id {
return entity.Id(fmt.Sprintf("%x", sum))
}
-func (t *Token) UserId() entity.Id {
- return t.userId
-}
-
-func (t *Token) updateUserId(id entity.Id) {
- t.userId = id
-}
-
func (t *Token) Target() string {
return t.target
}
@@ -92,6 +83,22 @@ func (t *Token) Validate() error {
return nil
}
+func (t *Token) Metadata() map[string]string {
+ return t.meta
+}
+
+func (t *Token) GetMetadata(key string) (string, bool) {
+ val, ok := t.meta[key]
+ return val, ok
+}
+
+func (t *Token) SetMetadata(key string, value string) {
+ if t.meta == nil {
+ t.meta = make(map[string]string)
+ }
+ t.meta[key] = value
+}
+
func (t *Token) toConfig() map[string]string {
return map[string]string{
tokenValueKey: t.Value,