Skip to content

Commit

Permalink
Remove action request field
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Nola <[email protected]>
  • Loading branch information
dereknola committed Oct 5, 2023
1 parent c736a69 commit 010af11
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
3 changes: 1 addition & 2 deletions pkg/cli/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@ func Rotate(app *cli.Context) error {
if err != nil {
return err
}
b, err := json.Marshal(server.ServerTokenRequest{
Action: pointer.String("rotate"),
b, err := json.Marshal(server.TokenRotateRequest{
NewToken: pointer.String(cmds.TokenConfig.NewToken),
})
if err != nil {
Expand Down
17 changes: 5 additions & 12 deletions pkg/server/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@ import (
"github.com/sirupsen/logrus"
)

type ServerTokenRequest struct {
Action *string `json:"stage,omitempty"`
type TokenRotateRequest struct {
NewToken *string `json:"newToken,omitempty"`
}

func getServerTokenRequest(req *http.Request) (ServerTokenRequest, error) {
func getServerTokenRequest(req *http.Request) (TokenRotateRequest, error) {
b, err := io.ReadAll(req.Body)
if err != nil {
return ServerTokenRequest{}, err
return TokenRotateRequest{}, err
}
result := ServerTokenRequest{}
result := TokenRotateRequest{}
err = json.Unmarshal(b, &result)
return result, err
}
Expand All @@ -45,13 +44,7 @@ func tokenRequestHandler(ctx context.Context, server *config.Control) http.Handl
resp.Write([]byte(err.Error()))
return
}
if *sTokenReq.Action == "rotate" {
err = tokenRotate(ctx, server, *sTokenReq.NewToken)
} else {
err = fmt.Errorf("unknown action %s requested", *sTokenReq.Action)
}

if err != nil {
if err = tokenRotate(ctx, server, *sTokenReq.NewToken); err != nil {
genErrorMessage(resp, http.StatusInternalServerError, err, "token")
return
}
Expand Down

0 comments on commit 010af11

Please sign in to comment.