eak.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package api
  2. import (
  3. "net/http"
  4. "github.com/smallstep/certificates/api"
  5. "github.com/smallstep/certificates/authority/admin"
  6. )
  7. // CreateExternalAccountKeyRequest is the type for GET /admin/eak requests
  8. type CreateExternalAccountKeyRequest struct {
  9. Name string `json:"name"`
  10. }
  11. // CreateExternalAccountKeyResponse is the type for GET /admin/eak responses
  12. type CreateExternalAccountKeyResponse struct {
  13. KeyID string `json:"keyID"`
  14. Name string `json:"name"`
  15. Key []byte `json:"key"`
  16. }
  17. // CreateExternalAccountKey creates a new External Account Binding key
  18. func (h *Handler) CreateExternalAccountKey(w http.ResponseWriter, r *http.Request) {
  19. var eakRequest = new(CreateExternalAccountKeyRequest)
  20. if err := api.ReadJSON(r.Body, eakRequest); err != nil { // TODO: rewrite into protobuf json (likely)
  21. api.WriteError(w, err)
  22. return
  23. }
  24. // TODO: Validate input
  25. eak, err := h.db.CreateExternalAccountKey(r.Context(), eakRequest.Name)
  26. if err != nil {
  27. api.WriteError(w, admin.WrapErrorISE(err, "error creating external account key %s", eakRequest.Name))
  28. return
  29. }
  30. eakResponse := CreateExternalAccountKeyResponse{
  31. KeyID: eak.ID,
  32. Name: eak.Name,
  33. Key: eak.KeyBytes,
  34. }
  35. api.JSONStatus(w, eakResponse, http.StatusCreated) // TODO: rewrite into protobuf json (likely)
  36. }