mirror of
https://github.com/Luzifer/vault-otp-ui.git
synced 2024-11-09 16:50:05 +00:00
Add support for icons, cleanup code
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
9747d23de4
commit
7e91879502
6 changed files with 37 additions and 18 deletions
|
@ -8,6 +8,8 @@ Two different methods are supported to store the secrets in Vault:
|
|||
|
||||
- Vault 0.7.x included [TOTP backend](https://www.vaultproject.io/docs/secrets/totp/index.html)
|
||||
- Custom (generic) secrets containing `secret`, `name`, and `icon` keys
|
||||
- Icons supported are to be chosen from [FontAwesome](http://fontawesome.io/) icon set
|
||||
- When no `name` is set the Vault key will be used as a name
|
||||
|
||||
(When using the Vault builtin TOTP backend switching the icons for the tokens is not supported.)
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ createOTPItem = (item) ->
|
|||
otpItem = $(tpl)
|
||||
otpItem.find('.badge').text item.code.replace(/^(.{3})(.{3})$/, '$1 $2')
|
||||
otpItem.find('.title').text item.name
|
||||
otpItem.find('i.fa').addClass "fa-#{item.icon}"
|
||||
|
||||
otpItem.appendTo $('#keylist')
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
otpItem = $(tpl);
|
||||
otpItem.find('.badge').text(item.code.replace(/^(.{3})(.{3})$/, '$1 $2'));
|
||||
otpItem.find('.title').text(item.name);
|
||||
otpItem.find('i.fa').addClass("fa-" + item.icon);
|
||||
return otpItem.appendTo($('#keylist'));
|
||||
};
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -110,7 +110,7 @@
|
|||
<div id="otp-item">
|
||||
<a href="#" class="list-group-item otp-item">
|
||||
<span class="badge">145 369</span>
|
||||
<i class="fa fa-key"></i>
|
||||
<i class="fa"></i>
|
||||
<span class="title">Some Site</span>
|
||||
</a>
|
||||
</div>
|
||||
|
|
41
token.go
41
token.go
|
@ -14,9 +14,10 @@ import (
|
|||
)
|
||||
|
||||
type token struct {
|
||||
Code string `json:"code"`
|
||||
Icon string `json:"icon"`
|
||||
Name string `json:"name"`
|
||||
Secret string `json:"-"`
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
func (t *token) GenerateCode(in time.Time) error {
|
||||
|
@ -142,21 +143,35 @@ func fetchTokenFromKey(client *api.Client, k string, respChan chan *token, wg *s
|
|||
return
|
||||
}
|
||||
|
||||
tok := &token{}
|
||||
|
||||
if data.Data[cfg.Vault.SecretField] != nil {
|
||||
tok.Secret = data.Data[cfg.Vault.SecretField].(string)
|
||||
tok.GenerateCode(time.Now())
|
||||
} else if data.Data["code"] != nil {
|
||||
tok.Code = data.Data["code"].(string)
|
||||
} else {
|
||||
// Secret did not have our field or a code, looks bad
|
||||
if data.Data == nil {
|
||||
// Key without any data? Weird.
|
||||
return
|
||||
}
|
||||
|
||||
tok.Name = k
|
||||
if data.Data["name"] != nil {
|
||||
tok.Name = data.Data["name"].(string)
|
||||
tok := &token{
|
||||
Icon: "key",
|
||||
Name: k,
|
||||
}
|
||||
|
||||
for k, v := range data.Data {
|
||||
switch k {
|
||||
case cfg.Vault.SecretField:
|
||||
tok.Secret = v.(string)
|
||||
tok.GenerateCode(time.Now())
|
||||
case "code":
|
||||
tok.Code = v.(string)
|
||||
case "name":
|
||||
tok.Name = v.(string)
|
||||
case "account_name":
|
||||
tok.Name = v.(string)
|
||||
case "icon":
|
||||
tok.Icon = v.(string)
|
||||
}
|
||||
}
|
||||
|
||||
if tok.Code == "" {
|
||||
// Nothing ended in us having a code, does not seem to be something for us
|
||||
return
|
||||
}
|
||||
|
||||
respChan <- tok
|
||||
|
|
Loading…
Reference in a new issue