// Get retrieves and decodes a secconf value stored at key. func (c configManager) Get(key string) ([]byte, error) { value, err := c.store.Get(key) if err != nil { return nil, err } return secconf.Decode(value, bytes.NewBuffer(c.keystore)) }
func (a *RabbitAddress) String() string { user := a.User pass := a.Password // if keyring is supplied, decrypt username & password if a.KeyRing != nil { u, err := secconf.Decode([]byte(a.User), bytes.NewBuffer(a.KeyRing)) if err != nil { user = "" log.Printf("Username decryption error: %s", err) } p, err := secconf.Decode([]byte(a.Password), bytes.NewBuffer(a.KeyRing)) if err != nil { pass = "" log.Printf("Password decryption error: %s", err) } user = string(u[:]) pass = string(p[:]) } else { log.Println("No keyring supplied, treating rabbitmq credentials as plain text") } connStr := fmt.Sprintf("amqp://%s:%s@%s:%d/%s", user, pass, a.Host, a.Port, a.VHost) return connStr }
// List retrieves and decodes all secconf value stored under key. func (c configManager) List(key string) (KVPairs, error) { list, err := c.store.List(key) retList := make(KVPairs, len(list)) if err != nil { return nil, err } for i, kv := range list { retList[i].Key = kv.Key retList[i].Value, err = secconf.Decode(kv.Value, bytes.NewBuffer(c.keystore)) if err != nil { return nil, err } } return retList, nil }
func getEncrypted(key, keyring string, store backend.Store) ([]byte, error) { var value []byte kr, err := os.Open(secretKeyring) if err != nil { return value, err } defer kr.Close() data, err := store.Get(key) if err != nil { return value, err } value, err = secconf.Decode(data, kr) if err != nil { return value, err } return value, err }
func (c configManager) Watch(key string, stop chan bool) <-chan *Response { resp := make(chan *Response, 0) backendResp := c.store.Watch(key, stop) go func() { for { select { case <-stop: return case r := <-backendResp: if r.Error != nil { resp <- &Response{nil, r.Error} continue } value, err := secconf.Decode(r.Value, bytes.NewBuffer(c.keystore)) resp <- &Response{value, err} } } }() return resp }
func listEncrypted(key, keyring string, store backend.Store) (backend.KVPairs, error) { kr, err := os.Open(secretKeyring) if err != nil { return nil, err } defer kr.Close() data, err := store.List(key) if err != nil { return nil, err } for i, kv := range data { data[i].Value, err = secconf.Decode(kv.Value, kr) kr.Seek(0, 0) if err != nil { return nil, err } } return data, err }