authConfig.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package api
  2. import (
  3. "net/http"
  4. "github.com/go-chi/chi"
  5. "github.com/smallstep/certificates/api"
  6. "github.com/smallstep/certificates/authority/config"
  7. "github.com/smallstep/certificates/authority/mgmt"
  8. )
  9. // CreateAuthConfigRequest represents the body for a CreateAuthConfig request.
  10. type CreateAuthConfigRequest struct {
  11. ASN1DN *config.ASN1DN `json:"asn1dn,omitempty"`
  12. Claims *mgmt.Claims `json:"claims,omitempty"`
  13. Backdate string `json:"backdate,omitempty"`
  14. }
  15. // Validate validates a CreateAuthConfig request body.
  16. func (car *CreateAuthConfigRequest) Validate() error {
  17. return nil
  18. }
  19. // UpdateAuthConfigRequest represents the body for a UpdateAuthConfig request.
  20. type UpdateAuthConfigRequest struct {
  21. ASN1DN *config.ASN1DN `json:"asn1dn"`
  22. Claims *mgmt.Claims `json:"claims"`
  23. Backdate string `json:"backdate,omitempty"`
  24. }
  25. // Validate validates a new-admin request body.
  26. func (uar *UpdateAuthConfigRequest) Validate() error {
  27. return nil
  28. }
  29. // GetAuthConfig returns the requested admin, or an error.
  30. func (h *Handler) GetAuthConfig(w http.ResponseWriter, r *http.Request) {
  31. ctx := r.Context()
  32. id := chi.URLParam(r, "id")
  33. ac, err := h.db.GetAuthConfig(ctx, id)
  34. if err != nil {
  35. api.WriteError(w, err)
  36. return
  37. }
  38. api.JSON(w, ac)
  39. }
  40. // UpdateAuthConfig updates an existing AuthConfig.
  41. func (h *Handler) UpdateAuthConfig(w http.ResponseWriter, r *http.Request) {
  42. /*
  43. ctx := r.Context()
  44. id := chi.URLParam(r, "id")
  45. var body UpdateAuthConfigRequest
  46. if err := api.ReadJSON(r.Body, &body); err != nil {
  47. api.WriteError(w, err)
  48. return
  49. }
  50. if err := body.Validate(); err != nil {
  51. api.WriteError(w, err)
  52. return
  53. }
  54. ac, err := h.db.GetAuthConfig(ctx, id)
  55. if err != nil {
  56. api.WriteError(w, err)
  57. return
  58. }
  59. ac.Status = body.Status
  60. if body.ASN1DN != nil {
  61. ac.ASN1DN = body.ASN1DN
  62. }
  63. if body.Claims != nil {
  64. ac.Claims = body.Claims
  65. }
  66. if body.Backdate != "" {
  67. ac.Backdate = body.Backdate
  68. }
  69. if err := h.db.UpdateAuthConfig(ctx, ac); err != nil {
  70. api.WriteError(w, err)
  71. return
  72. }
  73. api.JSON(w, ac)
  74. */
  75. }