Skip to content

Commit

Permalink
feat: rename 'subject' in check response to 'sub' for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
jaspeen committed Jun 10, 2024
1 parent 0fdcc05 commit 21d16fb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func TestCreateApiKey(t *testing.T) {

// check api key
var checkResp struct {
Subject string `json:"subject"`
Sub string `json:"sub"`
}
t.Run("check", func(t *testing.T) {
w = httptest.NewRecorder()
Expand All @@ -135,7 +135,7 @@ func TestCreateApiKey(t *testing.T) {
require.Equal(t, 200, w.Code)
err = json.Unmarshal(w.Body.Bytes(), &checkResp)
require.Nil(t, err)
assert.Equal(t, "testsub", checkResp.Subject)
assert.Equal(t, "testsub", checkResp.Sub)
})

// validate api key
Expand All @@ -154,7 +154,7 @@ func TestCreateApiKey(t *testing.T) {

router.ServeHTTP(w, req)
require.Equal(t, 200, w.Code)
assert.Equal(t, "testsub", checkResp.Subject)
assert.Equal(t, "testsub", checkResp.Sub)
})

// get api key
Expand Down
10 changes: 5 additions & 5 deletions api/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ func (a *Api) checkAndGetApiKeyData(c *gin.Context) (*queries.GetApiKeyForVerify
}

type checkResponse struct {
Id string `json:"id"`
Subject string `json:"subject"`
Extra json.RawMessage `json:"extra,omitempty"`
Id string `json:"id"`
Sub string `json:"sub"`
Extra json.RawMessage `json:"extra,omitempty"`
}

func (a *Api) Check(c *gin.Context) {
apiKeyData, err := a.checkAndGetApiKeyData(c)
if err != nil {
respondUnauthorized(c)
} else {
c.JSON(200, checkResponse{Id: strconv.Itoa(int(apiKeyData.ID)), Subject: apiKeyData.Sub.String, Extra: apiKeyData.Extra.RawMessage})
c.JSON(200, checkResponse{Id: strconv.Itoa(int(apiKeyData.ID)), Sub: apiKeyData.Sub.String, Extra: apiKeyData.Extra.RawMessage})
}
}

Expand Down Expand Up @@ -127,5 +127,5 @@ func (a *Api) Verify(c *gin.Context) {
return
}

c.JSON(200, checkResponse{Id: strconv.Itoa(int(apiKeyData.ID)), Subject: apiKeyData.Sub.String, Extra: apiKeyData.Extra.RawMessage})
c.JSON(200, checkResponse{Id: strconv.Itoa(int(apiKeyData.ID)), Sub: apiKeyData.Sub.String, Extra: apiKeyData.Extra.RawMessage})
}
4 changes: 2 additions & 2 deletions deploy/charts/apikeyman/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ keywords:
- security
sources:
- https://github.com/jaspeen/apikeyman
version: 0.1.5
appVersion: "0.1.5"
version: 0.1.6
appVersion: "0.1.6"

0 comments on commit 21d16fb

Please sign in to comment.