1 Star 0 Fork 0

PeterTu_2019/influxdb

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
secret.go 2.07 KB
一键复制 编辑 原始数据 按行查看 历史
package influxdb
import (
"context"
"encoding/json"
"strings"
"github.com/influxdata/influxdb/v2/kit/platform"
)
// ErrSecretNotFound is the error msg for a missing secret.
const ErrSecretNotFound = "secret not found"
// SecretService a service for storing and retrieving secrets.
type SecretService interface {
// LoadSecret retrieves the secret value v found at key k for organization orgID.
LoadSecret(ctx context.Context, orgID platform.ID, k string) (string, error)
// GetSecretKeys retrieves all secret keys that are stored for the organization orgID.
GetSecretKeys(ctx context.Context, orgID platform.ID) ([]string, error)
// PutSecret stores the secret pair (k,v) for the organization orgID.
PutSecret(ctx context.Context, orgID platform.ID, k string, v string) error
// PutSecrets puts all provided secrets and overwrites any previous values.
PutSecrets(ctx context.Context, orgID platform.ID, m map[string]string) error
// PatchSecrets patches all provided secrets and updates any previous values.
PatchSecrets(ctx context.Context, orgID platform.ID, m map[string]string) error
// DeleteSecret removes a single secret from the secret store.
DeleteSecret(ctx context.Context, orgID platform.ID, ks ...string) error
}
// SecretField contains a key string, and value pointer.
type SecretField struct {
Key string `json:"key"`
Value *string `json:"value,omitempty"`
}
// String returns the key of the secret.
func (s SecretField) String() string {
if s.Key == "" {
return ""
}
return "secret: " + s.Key
}
// MarshalJSON implement the json marshaler interface.
func (s SecretField) MarshalJSON() ([]byte, error) {
return json.Marshal(s.String())
}
// UnmarshalJSON implement the json unmarshaler interface.
func (s *SecretField) UnmarshalJSON(b []byte) error {
var ss string
if err := json.Unmarshal(b, &ss); err != nil {
return err
}
if ss == "" {
s.Key = ""
return nil
}
if strings.HasPrefix(ss, "secret: ") {
s.Key = ss[len("secret: "):]
} else {
s.Value = strPtr(ss)
}
return nil
}
func strPtr(s string) *string {
ss := new(string)
*ss = s
return ss
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/petertu_2019/influxdb.git
git@gitee.com:petertu_2019/influxdb.git
petertu_2019
influxdb
influxdb
master

搜索帮助