From 5f711e87a52ee858352794b0892f5203fc738b5f Mon Sep 17 00:00:00 2001 From: Fergal Mc Carthy Date: Fri, 16 Aug 2024 11:24:36 -0400 Subject: [PATCH] issueDate should be registrationDate The field name in the return client credentials is misnamed. --- doc/api/README.md | 2 +- doc/api/requests/authenticate.md | 10 +++++----- doc/api/requests/register.md | 6 +++--- doc/api/requests/report.md | 5 ++++- pkg/client/authenticate.go | 6 +++--- pkg/client/client.go | 6 +++--- pkg/client/register.go | 6 +++--- pkg/restapi/restapi.go | 6 +++--- 8 files changed, 25 insertions(+), 22 deletions(-) diff --git a/doc/api/README.md b/doc/api/README.md index 8f0419a..fcdaaf8 100644 --- a/doc/api/README.md +++ b/doc/api/README.md @@ -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
[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
[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 diff --git a/doc/api/requests/authenticate.md b/doc/api/requests/authenticate.md index 713a6c7..dd04af8 100644 --- a/doc/api/requests/authenticate.md +++ b/doc/api/requests/authenticate.md @@ -8,17 +8,17 @@ Type: **POST** | ---- | ---- | ----------- | ------- | | body | object | {
  clientId integer($int64)
  instIdHash {
    method string
    value string
  }
} | {
  "clientId": 1234567890
  "instIdHash": {
    "method": "sha256"
    "value": "984271ec70628b47995fdf9271ded6274c2b104ce201164a9b63cfefef7f40d0"
  }
}| -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
`Content-Type: application/json`
{
  clientId integer($int64)
  authToken string
  issueDate string
} | {
  "clientId": 1234567890
  "authToken": "encoded.JWT.token"
  "issueDate": "2024-08-01T01:02:03.000000Z"
} | +| 200 | Success
`Content-Type: application/json`
{
  clientId integer($int64)
  authToken string
  registrationDate string
} | {
  "clientId": 1234567890
  "authToken": "encoded.JWT.token"
  "registrationDate": "2024-08-01T01:02:03.000000Z"
} | | 400 | Bad Request
Missing or incompatible body
`Content-Type: application/json`
{
  error string
} | {
  "error": "no clientInstanceId value provided"
} | -| 401 | Unauthorized
Client (re-)registration required due to one of:
- specified client is not registered
- invalid clientId provided
- provided clientInstanceId hash doesn't match
[WWW-Authenticate](hdr_www-authenticate.md) response header will specify recovery action
`Content-Type: application/json`
{
  error string
} | {
  "error": "Client not registered"
} | +| 401 | Unauthorized
Client (re-)registration required due to one of:
- specified client is not registered
- invalid clientId provided
- provided clientInstanceId hash doesn't match
[WWW-Authenticate](../headers/www-authenticate.md) response header will specify recovery action
`Content-Type: application/json`
{
  error string
} | {
  "error": "Client not registered"
} | -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. diff --git a/doc/api/requests/register.md b/doc/api/requests/register.md index f70947b..1897707 100644 --- a/doc/api/requests/register.md +++ b/doc/api/requests/register.md @@ -8,14 +8,14 @@ Type: **POST** | ---- | ---- | ----------- | ------- | | body | object | {
  clientInstanceId: string
} | {
  "clientInstanceId": "ba2cb9f4927441602a385b27f502134902b636f395cadb3ea1438084dba29c8c"
}| -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
`Content-Type: application/json`
{
  clientId integer($int64)
  authToken string
  issueDate string
} | {
  "clientId": 1234567890
  "authToken": "encoded.JWT.token"
  "issueDate": "2024-08-01T01:02:03.000000Z"
} | +| 200 | Success
`Content-Type: application/json`
{
  clientId integer($int64)
  authToken string
  registrationDate string
} | {
  "clientId": 1234567890
  "authToken": "encoded.JWT.token"
  "registrationDate": "2024-08-01T01:02:03.000000Z"
} | | 400 | Bad Request
Missing or incompatible body
`Content-Type: application/json`
{
  error string
} | {
  "error": "no clientInstanceId value provided"
} | | 409 | Conflict
Client Instance Id already registered
`Content-Type: application/json`
{
  error string
} | {
  "error": "specified clientInstanceId already exists"
} | -Response success body type `ClientRegistrationResponse` defined in [restapi module](pkg/restapi) \ No newline at end of file +Response success body type `ClientRegistrationResponse` defined in [restapi module](../../../pkg/restapi/) \ No newline at end of file diff --git a/doc/api/requests/report.md b/doc/api/requests/report.md index 21fc8da..c3b53ac 100644 --- a/doc/api/requests/report.md +++ b/doc/api/requests/report.md @@ -16,4 +16,7 @@ Type: ***POST*** | ---- | ----------- | ------- | | 200 | Success
`Content-Type: application/json`
{
  processingId integer($int64)
  processedAt string($rfc3339nano)
} | {
  "processingId": 1234567890
  "processedAt": "2024-08-01T01:02:03.000000Z"
} | | 400 | Bad Request
Missing or incompatible body
`Content-Type: application/json`
{
  error string
} | {
  "error": "missing header.reportId field"
} | -| 401 | Unauthorized
Client (re-)registration required due to one of:
- specified client is not registered
- invalid clientId provided
[WWW-Authenticate](hdr_www-authenticate.md) response header will specify recovery action
`Content-Type: application/json`
{
  error string
} | {
  "error": "Client not registered"
} | \ No newline at end of file +| 401 | Unauthorized
Client (re-)registration required due to one of:
- specified client is not registered
- invalid clientId provided
[WWW-Authenticate](../headers/www-authenticate.md) response header will specify recovery action
`Content-Type: application/json`
{
  error string
} | {
  "error": "Client not registered"
} | + +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. diff --git a/pkg/client/authenticate.go b/pkg/client/authenticate.go index ac5d346..47a2d88 100644 --- a/pkg/client/authenticate.go +++ b/pkg/client/authenticate.go @@ -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 diff --git a/pkg/client/client.go b/pkg/client/client.go index f291373..5f20017 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -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 { diff --git a/pkg/client/register.go b/pkg/client/register.go index 83f867b..2f20087 100644 --- a/pkg/client/register.go +++ b/pkg/client/register.go @@ -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 diff --git a/pkg/restapi/restapi.go b/pkg/restapi/restapi.go index 7dbc1eb..d6eb01f 100644 --- a/pkg/restapi/restapi.go +++ b/pkg/restapi/restapi.go @@ -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 {