Ejemplo n.º 1
0
func getKeyFromBody(b io.Reader) (repository.Key, bool, error) {
	var key repository.Key
	var body keyBody
	err := json.NewDecoder(b).Decode(&body)
	if err != nil {
		return key, false, &errors.HTTP{Code: http.StatusBadRequest, Message: "Invalid JSON"}
	}
	key.Body = body.Key
	key.Name = body.Name
	return key, body.Force, nil
}
Ejemplo n.º 2
0
func getKeyFromBody(b io.Reader) (repository.Key, error) {
	var key repository.Key
	var body map[string]string
	err := json.NewDecoder(b).Decode(&body)
	if err != nil {
		return key, &errors.HTTP{Code: http.StatusBadRequest, Message: "Invalid JSON"}
	}
	key.Body = body["key"]
	key.Name = body["name"]
	return key, nil
}
Ejemplo n.º 3
0
func (m *fakeManager) UpdateKey(username string, key repository.Key) error {
	m.keysLock.Lock()
	defer m.keysLock.Unlock()
	keys, ok := m.keys[username]
	if !ok {
		return repository.ErrUserNotFound
	}
	if key.Name == "" {
		var p [32]byte
		rand.Read(p[:])
		key.Name = string(p[:])
	}
	if _, ok := keys[key.Name]; !ok {
		return repository.ErrKeyNotFound
	}
	keys[key.Name] = key.Body
	m.keys[username] = keys
	return nil
}