@@ -81,10 +81,10 @@ type DeleteResponse struct {
81
81
}
82
82
83
83
// GetAdmin returns the requested admin, or an error.
84
- func ( h * Handler ) GetAdmin (w http.ResponseWriter , r * http.Request ) {
84
+ func GetAdmin (w http.ResponseWriter , r * http.Request ) {
85
85
id := chi .URLParam (r , "id" )
86
86
87
- adm , ok := h . auth .LoadAdminByID (id )
87
+ adm , ok := mustAuthority ( r . Context ()) .LoadAdminByID (id )
88
88
if ! ok {
89
89
render .Error (w , admin .NewError (admin .ErrorNotFoundType ,
90
90
"admin %s not found" , id ))
@@ -94,15 +94,15 @@ func (h *Handler) GetAdmin(w http.ResponseWriter, r *http.Request) {
94
94
}
95
95
96
96
// GetAdmins returns a segment of admins associated with the authority.
97
- func ( h * Handler ) GetAdmins (w http.ResponseWriter , r * http.Request ) {
97
+ func GetAdmins (w http.ResponseWriter , r * http.Request ) {
98
98
cursor , limit , err := api .ParseCursor (r )
99
99
if err != nil {
100
100
render .Error (w , admin .WrapError (admin .ErrorBadRequestType , err ,
101
101
"error parsing cursor and limit from query params" ))
102
102
return
103
103
}
104
104
105
- admins , nextCursor , err := h . auth .GetAdmins (cursor , limit )
105
+ admins , nextCursor , err := mustAuthority ( r . Context ()) .GetAdmins (cursor , limit )
106
106
if err != nil {
107
107
render .Error (w , admin .WrapErrorISE (err , "error retrieving paginated admins" ))
108
108
return
@@ -114,7 +114,7 @@ func (h *Handler) GetAdmins(w http.ResponseWriter, r *http.Request) {
114
114
}
115
115
116
116
// CreateAdmin creates a new admin.
117
- func ( h * Handler ) CreateAdmin (w http.ResponseWriter , r * http.Request ) {
117
+ func CreateAdmin (w http.ResponseWriter , r * http.Request ) {
118
118
var body CreateAdminRequest
119
119
if err := read .JSON (r .Body , & body ); err != nil {
120
120
render .Error (w , admin .WrapError (admin .ErrorBadRequestType , err , "error reading request body" ))
@@ -126,7 +126,8 @@ func (h *Handler) CreateAdmin(w http.ResponseWriter, r *http.Request) {
126
126
return
127
127
}
128
128
129
- p , err := h .auth .LoadProvisionerByName (body .Provisioner )
129
+ auth := mustAuthority (r .Context ())
130
+ p , err := auth .LoadProvisionerByName (body .Provisioner )
130
131
if err != nil {
131
132
render .Error (w , admin .WrapErrorISE (err , "error loading provisioner %s" , body .Provisioner ))
132
133
return
@@ -137,7 +138,7 @@ func (h *Handler) CreateAdmin(w http.ResponseWriter, r *http.Request) {
137
138
Type : body .Type ,
138
139
}
139
140
// Store to authority collection.
140
- if err := h . auth .StoreAdmin (r .Context (), adm , p ); err != nil {
141
+ if err := auth .StoreAdmin (r .Context (), adm , p ); err != nil {
141
142
render .Error (w , admin .WrapErrorISE (err , "error storing admin" ))
142
143
return
143
144
}
@@ -146,10 +147,10 @@ func (h *Handler) CreateAdmin(w http.ResponseWriter, r *http.Request) {
146
147
}
147
148
148
149
// DeleteAdmin deletes admin.
149
- func ( h * Handler ) DeleteAdmin (w http.ResponseWriter , r * http.Request ) {
150
+ func DeleteAdmin (w http.ResponseWriter , r * http.Request ) {
150
151
id := chi .URLParam (r , "id" )
151
152
152
- if err := h . auth .RemoveAdmin (r .Context (), id ); err != nil {
153
+ if err := mustAuthority ( r . Context ()) .RemoveAdmin (r .Context (), id ); err != nil {
153
154
render .Error (w , admin .WrapErrorISE (err , "error deleting admin %s" , id ))
154
155
return
155
156
}
@@ -158,7 +159,7 @@ func (h *Handler) DeleteAdmin(w http.ResponseWriter, r *http.Request) {
158
159
}
159
160
160
161
// UpdateAdmin updates an existing admin.
161
- func ( h * Handler ) UpdateAdmin (w http.ResponseWriter , r * http.Request ) {
162
+ func UpdateAdmin (w http.ResponseWriter , r * http.Request ) {
162
163
var body UpdateAdminRequest
163
164
if err := read .JSON (r .Body , & body ); err != nil {
164
165
render .Error (w , admin .WrapError (admin .ErrorBadRequestType , err , "error reading request body" ))
@@ -171,8 +172,8 @@ func (h *Handler) UpdateAdmin(w http.ResponseWriter, r *http.Request) {
171
172
}
172
173
173
174
id := chi .URLParam (r , "id" )
174
-
175
- adm , err := h . auth .UpdateAdmin (r .Context (), id , & linkedca.Admin {Type : body .Type })
175
+ auth := mustAuthority ( r . Context ())
176
+ adm , err := auth .UpdateAdmin (r .Context (), id , & linkedca.Admin {Type : body .Type })
176
177
if err != nil {
177
178
render .Error (w , admin .WrapErrorISE (err , "error updating admin %s" , id ))
178
179
return
0 commit comments