Skip to content

Commit

Permalink
issueDate should be registrationDate
Browse files Browse the repository at this point in the history
The field name in the return client credentials is misnamed.
  • Loading branch information
rtamalin committed Aug 16, 2024
1 parent 8df1cd2 commit 5f711e8
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion doc/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ a set of client credentials as follows:
| ---- | ---- | ----------- |
| clientId | integer($int64) | ID used to identify the client to the server |
| authToken | string($([JWT](https://jwt.io/)) | A JSON Web Token ([JWT](https://jwt.io/)) authorization token |
| issueDate | string($[rfc3339nano](https://pkg.go.dev/time#pkg-constants)) | The client UTC registration timestamp expressed in<br>[RFC3339nano](https://pkg.go.dev/time#pkg-constants) format |
| registrationDate | string($[rfc3339nano](https://pkg.go.dev/time#pkg-constants)) | The client UTC registration timestamp expressed in<br>[RFC3339nano](https://pkg.go.dev/time#pkg-constants) format |

***NOTE***: The telemetry client is responsible for storing these client
credentials in a persistent fashion so that they can subsequently be
Expand Down
10 changes: 5 additions & 5 deletions doc/api/requests/authenticate.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ Type: **POST**
| ---- | ---- | ----------- | ------- |
| body | object | {<br>&nbsp;&nbsp;clientId integer($int64)<br>&nbsp;&nbsp;instIdHash {<br>&nbsp;&nbsp;&nbsp;&nbsp;method string<br>&nbsp;&nbsp;&nbsp;&nbsp;value string<br>&nbsp;&nbsp;}<br>} | {<br>&nbsp;&nbsp;"clientId": 1234567890<br>&nbsp;&nbsp;"instIdHash": {<br>&nbsp;&nbsp;&nbsp;&nbsp;"method": "sha256"<br>&nbsp;&nbsp;&nbsp;&nbsp;"value": "984271ec70628b47995fdf9271ded6274c2b104ce201164a9b63cfefef7f40d0"<br>&nbsp;&nbsp;}<br>}|

Request body type `ClientAuthenticationRequest` defined in [restapi module](pkg/restapi)
Request body type `ClientAuthenticationRequest` defined in [restapi module](../../../pkg/restapi)

## Responses

| Code | Description | Example |
| ---- | ----------- | ------- |
| 200 | Success<br>`Content-Type: application/json`<br>{<br>&nbsp;&nbsp;clientId integer($int64)<br>&nbsp;&nbsp;authToken string<br>&nbsp;&nbsp;issueDate string<br>} | {<br>&nbsp;&nbsp;"clientId": 1234567890<br>&nbsp;&nbsp;"authToken": "encoded.JWT.token"<br>&nbsp;&nbsp;"issueDate": "2024-08-01T01:02:03.000000Z"<br>} |
| 200 | Success<br>`Content-Type: application/json`<br>{<br>&nbsp;&nbsp;clientId integer($int64)<br>&nbsp;&nbsp;authToken string<br>&nbsp;&nbsp;registrationDate string<br>} | {<br>&nbsp;&nbsp;"clientId": 1234567890<br>&nbsp;&nbsp;"authToken": "encoded.JWT.token"<br>&nbsp;&nbsp;"registrationDate": "2024-08-01T01:02:03.000000Z"<br>} |
| 400 | Bad Request<br>Missing or incompatible body<br>`Content-Type: application/json`<br>{<br>&nbsp;&nbsp;error string<br>} | {<br>&nbsp;&nbsp;"error": "no clientInstanceId value provided"<br>} |
| 401 | Unauthorized<br>Client (re-)registration required due to one of:<br>- specified client is not registered<br>- invalid clientId provided<br>- provided clientInstanceId hash doesn't match<br>[WWW-Authenticate](hdr_www-authenticate.md) response header will specify recovery action<br>`Content-Type: application/json`<br>{<br>&nbsp;&nbsp;error string<br>} | {<br>&nbsp;&nbsp;"error": "Client not registered"<br>} |
| 401 | Unauthorized<br>Client (re-)registration required due to one of:<br>- specified client is not registered<br>- invalid clientId provided<br>- provided clientInstanceId hash doesn't match<br>[WWW-Authenticate](../headers/www-authenticate.md) response header will specify recovery action<br>`Content-Type: application/json`<br>{<br>&nbsp;&nbsp;error string<br>} | {<br>&nbsp;&nbsp;"error": "Client not registered"<br>} |

Response success body type `ClientAuthenticationResponse` defined in [restapi module](pkg/restapi)
Response success body type `ClientAuthenticationResponse` defined in [restapi module](../../../pkg/restapi)

If the response is a 401 Unauthorized then the `WWW-Authenticate` reponse header will be set.
See [www-authenticate.md](hdr_www-authenticate.md) for more details.
See [www-authenticate.md](../headers/www-authenticate.md) for more details.
6 changes: 3 additions & 3 deletions doc/api/requests/register.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ Type: **POST**
| ---- | ---- | ----------- | ------- |
| body | object | {<br>&nbsp;&nbsp;clientInstanceId: string<br>} | {<br>&nbsp;&nbsp;"clientInstanceId": "ba2cb9f4927441602a385b27f502134902b636f395cadb3ea1438084dba29c8c"<br>}|

Request body type `ClientRegistrationRequest` defined in [restapi module](pkg/restapi)
Request body type `ClientRegistrationRequest` defined in [restapi module](../../../pkg/restapi/)

## Responses

| Code | Description | Example |
| ---- | ----------- | ------- |
| 200 | Success<br>`Content-Type: application/json`<br>{<br>&nbsp;&nbsp;clientId integer($int64)<br>&nbsp;&nbsp;authToken string<br>&nbsp;&nbsp;issueDate string<br>} | {<br>&nbsp;&nbsp;"clientId": 1234567890<br>&nbsp;&nbsp;"authToken": "encoded.JWT.token"<br>&nbsp;&nbsp;"issueDate": "2024-08-01T01:02:03.000000Z"<br>} |
| 200 | Success<br>`Content-Type: application/json`<br>{<br>&nbsp;&nbsp;clientId integer($int64)<br>&nbsp;&nbsp;authToken string<br>&nbsp;&nbsp;registrationDate string<br>} | {<br>&nbsp;&nbsp;"clientId": 1234567890<br>&nbsp;&nbsp;"authToken": "encoded.JWT.token"<br>&nbsp;&nbsp;"registrationDate": "2024-08-01T01:02:03.000000Z"<br>} |
| 400 | Bad Request<br>Missing or incompatible body<br>`Content-Type: application/json`<br>{<br>&nbsp;&nbsp;error string<br>} | {<br>&nbsp;&nbsp;"error": "no clientInstanceId value provided"<br>} |
| 409 | Conflict<br>Client Instance Id already registered<br>`Content-Type: application/json`<br>{<br>&nbsp;&nbsp;error string<br>} | {<br>&nbsp;&nbsp;"error": "specified clientInstanceId already exists"<br>} |

Response success body type `ClientRegistrationResponse` defined in [restapi module](pkg/restapi)
Response success body type `ClientRegistrationResponse` defined in [restapi module](../../../pkg/restapi/)
5 changes: 4 additions & 1 deletion doc/api/requests/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ Type: ***POST***
| ---- | ----------- | ------- |
| 200 | Success<br>`Content-Type: application/json`<br>{<br>&nbsp;&nbsp;processingId integer($int64)<br>&nbsp;&nbsp;processedAt string($rfc3339nano)<br>} | {<br>&nbsp;&nbsp;"processingId": 1234567890<br>&nbsp;&nbsp;"processedAt": "2024-08-01T01:02:03.000000Z"<br>} |
| 400 | Bad Request<br>Missing or incompatible body<br>`Content-Type: application/json`<br>{<br>&nbsp;&nbsp;error string<br>} | {<br>&nbsp;&nbsp;"error": "missing header.reportId field"<br>} |
| 401 | Unauthorized<br>Client (re-)registration required due to one of:<br>- specified client is not registered<br>- invalid clientId provided<br>[WWW-Authenticate](hdr_www-authenticate.md) response header will specify recovery action<br>`Content-Type: application/json`<br>{<br>&nbsp;&nbsp;error string<br>} | {<br>&nbsp;&nbsp;"error": "Client not registered"<br>} |
| 401 | Unauthorized<br>Client (re-)registration required due to one of:<br>- specified client is not registered<br>- invalid clientId provided<br>[WWW-Authenticate](../headers/www-authenticate.md) response header will specify recovery action<br>`Content-Type: application/json`<br>{<br>&nbsp;&nbsp;error string<br>} | {<br>&nbsp;&nbsp;"error": "Client not registered"<br>} |

If the response is a 401 Unauthorized then the `WWW-Authenticate` reponse header will be set.
See [www-authenticate.md](../headers/www-authenticate.md) for more details.
6 changes: 3 additions & 3 deletions pkg/client/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ func (tc *TelemetryClient) Authenticate() (err error) {

tc.auth.ClientId = caResp.ClientId
tc.auth.Token = types.TelemetryAuthToken(caResp.AuthToken)
tc.auth.IssueDate, err = types.TimeStampFromString(caResp.IssueDate)
tc.auth.RegistrationDate, err = types.TimeStampFromString(caResp.RegistrationDate)
if err != nil {
slog.Error(
"failed to parse issueDate as a timestamp",
slog.String("issueDate", caResp.IssueDate),
"failed to parse registrationDate as a timestamp",
slog.String("registrationDate", caResp.RegistrationDate),
slog.String("err", err.Error()),
)
return
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const (
)

type TelemetryAuth struct {
ClientId int64 `json:"clientId"`
Token types.TelemetryAuthToken `json:"token"`
IssueDate types.TelemetryTimeStamp `json:"issueDate"`
ClientId int64 `json:"clientId"`
Token types.TelemetryAuthToken `json:"token"`
RegistrationDate types.TelemetryTimeStamp `json:"registrationDate"`
}

type TelemetryClient struct {
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ func (tc *TelemetryClient) Register() (err error) {

tc.auth.ClientId = crResp.ClientId
tc.auth.Token = types.TelemetryAuthToken(crResp.AuthToken)
tc.auth.IssueDate, err = types.TimeStampFromString(crResp.IssueDate)
tc.auth.RegistrationDate, err = types.TimeStampFromString(crResp.RegistrationDate)
if err != nil {
slog.Error(
"failed to parse issueDate as a timestamp",
slog.String("issueDate", crResp.IssueDate),
"failed to parse registrationDate as a timestamp",
slog.String("registrationDate", crResp.RegistrationDate),
slog.String("err", err.Error()),
)
return
Expand Down
6 changes: 3 additions & 3 deletions pkg/restapi/restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ func (c *ClientRegistrationRequest) String() string {

// ClientRegistrationResponse is the response payload body from the server
type ClientRegistrationResponse struct {
ClientId int64 `json:"clientId"`
AuthToken string `json:"authToken"`
IssueDate string `json:"issueDate"`
ClientId int64 `json:"clientId"`
AuthToken string `json:"authToken"`
RegistrationDate string `json:"registrationDate"`
}

func (c *ClientRegistrationResponse) String() string {
Expand Down

0 comments on commit 5f711e8

Please sign in to comment.