Skip to content

Commit

Permalink
feat: add version prefix
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Gateru <[email protected]>
  • Loading branch information
felixgateru committed Jan 28, 2025
1 parent e69730d commit 4bf37db
Show file tree
Hide file tree
Showing 46 changed files with 623 additions and 573 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/api-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ on:

env:
TOKENS_URL: http://localhost:9002/users/tokens/issue
CREATE_DOMAINS_URL: http://localhost:9003/domains
CREATE_DOMAINS_URL: http://localhost:9003/v1/domains
USER_IDENTITY: [email protected]
USER_SECRET: 12345678
DOMAIN_NAME: demo-test
USERS_URL: http://localhost:9002
DOMAIN_URL: http://localhost:9003
CLIENTS_URL: http://localhost:9006
CHANNELS_URL: http://localhost:9005
GROUPS_URL: http://localhost:9004
USERS_URL: http://localhost:9002/v1
DOMAIN_URL: http://localhost:9003/v1
CLIENTS_URL: http://localhost:9006/v1
CHANNELS_URL: http://localhost:9005/v1
GROUPS_URL: http://localhost:9004/v1
HTTP_ADAPTER_URL: http://localhost:8008
INVITATIONS_URL: http://localhost:9020
AUTH_URL: http://localhost:9001
CERTS_URL: http://localhost:9019
JOURNAL_URL: http://localhost:9021
INVITATIONS_URL: http://localhost:9020/v1
AUTH_URL: http://localhost:9001/v1
CERTS_URL: http://localhost:9019/v1
JOURNAL_URL: http://localhost:9021/v1

jobs:
api-test:
Expand Down
2 changes: 1 addition & 1 deletion apidocs/openapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

This folder contains an OpenAPI specifications for SuperMQ API.

View specification in Swagger UI at [docs.api.magistrala.abstractmachines.fr](https://docs.api.supermq.abstractmachines.fr)
View specification in Swagger UI at [docs.api.supermq.abstractmachines.fr](https://docs.api.supermq.abstractmachines.fr)
4 changes: 2 additions & 2 deletions apidocs/openapi/auth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ info:
version: 0.15.1

servers:
- url: http://localhost:9001
- url: https://localhost:9001
- url: http://localhost:9001/v1
- url: https://localhost:9001/v1

tags:
- name: Keys
Expand Down
4 changes: 2 additions & 2 deletions apidocs/openapi/certs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ info:
version: 0.15.1

servers:
- url: http://localhost:9019
- url: https://localhost:9019
- url: http://localhost:9019/v1
- url: https://localhost:9019/v1

tags:
- name: certs
Expand Down
22 changes: 11 additions & 11 deletions apidocs/openapi/channels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ info:
version: 0.15.1

servers:
- url: http://localhost:9005
- url: https://localhost:9005
- url: http://localhost:9005/v1
- url: https://localhost:9005/v1

tags:
- name: Channels
Expand Down Expand Up @@ -454,7 +454,7 @@ paths:
description: Database can't process request.
"500":
$ref: "#/components/responses/ServiceError"

/{domainID}/channels/{chanID}/connect:
post:
operationId: connectClientsToChannel
Expand Down Expand Up @@ -557,7 +557,7 @@ components:
ParentGroupReqObj:
type: object
properties:
parent_group_id:
parent_group_id:
type: string
format: uuid
example: bb7edb32-2eac-4aad-aebe-ed96fe073879
Expand Down Expand Up @@ -667,7 +667,7 @@ components:
- name
- metadata
- description

ChannelUpdateTags:
type: object
properties:
Expand Down Expand Up @@ -817,7 +817,7 @@ components:
format: uuid
required: false
example: bb7edb32-2eac-4aad-aebe-ed96fe073879

Metadata:
name: metadata
description: Metadata filter. Filtering is performed matching the parameter with metadata on top level. Parameter is json.
Expand Down Expand Up @@ -867,7 +867,7 @@ components:
application/json:
schema:
$ref: "#/components/schemas/ChannelReqObj"

ChannelsCreateReq:
description: JSON-formatted document describing the new channels to be registered
required: true
Expand All @@ -885,15 +885,15 @@ components:
application/json:
schema:
$ref: "#/components/schemas/ChannelUpdate"

ChannelUpdateTagsReq:
description: JSON-formated document describing the tags of channel to be updated.
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/ChannelUpdate"

ChannelParentGroupReq:
description: JSON-formated document describing the parent group to be set to or removed from a channel.
required: true
Expand All @@ -909,7 +909,7 @@ components:
application/json:
schema:
$ref: "#/components/schemas/ConnectionReqSchema"

ChannelConnReq:
description: JSON-formatted document describing the new connection.
required: true
Expand Down Expand Up @@ -976,7 +976,7 @@ components:
operationId: unassignGroupsFromChannel
parameters:
chanID: $response.body#/id

ChannelsCreateRes:
description: Registered new channels.
headers:
Expand Down
12 changes: 6 additions & 6 deletions apidocs/openapi/clients.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ info:
version: 0.15.1

servers:
- url: http://localhost:9006
- url: https://localhost:9006
- url: http://localhost:9006/v1
- url: https://localhost:9006/v1

tags:
- name: Clients
Expand All @@ -28,8 +28,8 @@ tags:
- name: Roles
description: All operations involving roles for clients
externalDocs:
description: Find out more about roles
url: https://docs.supermq.abstractmachines.fr/
description: Find out more about roles
url: https://docs.supermq.abstractmachines.fr/
- name: Health
description: Health check operations
externalDocs:
Expand Down Expand Up @@ -472,7 +472,7 @@ paths:
- bearerAuth: []
responses:
"201":
$ref: "./schemas/roles.yml#/components/responses/CreateRoleRes"
$ref: "./schemas/roles.yml#/components/responses/CreateRoleRes"
"400":
description: Failed due to malformed client's ID.
"401":
Expand Down Expand Up @@ -952,7 +952,7 @@ components:
ParentGroupReqObj:
type: object
properties:
parent_group_id:
parent_group_id:
type: string
format: uuid
example: bb7edb32-2eac-4aad-aebe-ed96fe073879
Expand Down
10 changes: 5 additions & 5 deletions apidocs/openapi/domains.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ info:
version: 0.15.1

servers:
- url: http://localhost:9003
- url: https://localhost:9003
- url: http://localhost:9003/v1
- url: https://localhost:9003/v1

tags:
- name: Domains
Expand All @@ -28,8 +28,8 @@ tags:
- name: Roles
description: All operations involving roles for clients
externalDocs:
description: Find out more about roles
url: https://docs.supermq.abstractmachines.fr/
description: Find out more about roles
url: https://docs.supermq.abstractmachines.fr/
- name: Health
description: Service health check endpoint.
externalDocs:
Expand Down Expand Up @@ -242,7 +242,7 @@ paths:
- bearerAuth: []
responses:
"201":
$ref: "./schemas/roles.yml#/components/responses/CreateRoleRes"
$ref: "./schemas/roles.yml#/components/responses/CreateRoleRes"
"400":
description: Failed due to malformed domain's ID.
"401":
Expand Down
12 changes: 6 additions & 6 deletions apidocs/openapi/groups.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ info:
version: 0.15.1

servers:
- url: http://localhost:9004
- url: https://localhost:9004
- url: http://localhost:9004/v1
- url: https://localhost:9004/v1

tags:
- name: Groups
Expand All @@ -28,8 +28,8 @@ tags:
- name: Roles
description: All operations involving roles for groups
externalDocs:
description: Find out more about roles
url: https://docs.supermq.abstractmachines.fr/
description: Find out more about roles
url: https://docs.supermq.abstractmachines.fr/
- name: Health
description: Health check operations
externalDocs:
Expand Down Expand Up @@ -516,7 +516,7 @@ paths:
- bearerAuth: []
responses:
"201":
$ref: "./schemas/roles.yml#/components/responses/CreateRoleRes"
$ref: "./schemas/roles.yml#/components/responses/CreateRoleRes"
"400":
description: Failed due to malformed group's ID.
"401":
Expand Down Expand Up @@ -1192,7 +1192,7 @@ components:
ParentGroupReqObj:
type: object
properties:
group_id:
group_id:
type: string
format: uuid
example: bb7edb32-2eac-4aad-aebe-ed96fe073879
Expand Down
5 changes: 2 additions & 3 deletions apidocs/openapi/invitations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ info:
version: 0.15.1

servers:
- url: http://localhost:9020
- url: https://localhost:9020
- url: http://localhost:9020/v1
- url: https://localhost:9020/v1

tags:
- name: Invitations
Expand Down Expand Up @@ -201,7 +201,6 @@ paths:
/health:
get:
summary: Retrieves service health check info.
tags:
- health
security: []
responses:
Expand Down
4 changes: 2 additions & 2 deletions apidocs/openapi/journal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ info:
version: 0.15.1

servers:
- url: http://localhost:9021
- url: https://localhost:9021
- url: http://localhost:9021/v1
- url: https://localhost:9021/v1

tags:
- name: journal-log
Expand Down
8 changes: 4 additions & 4 deletions apidocs/openapi/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ info:
version: 0.15.1

servers:
- url: http://localhost:9002
- url: https://localhost:9002
- url: http://localhost:9002/v1
- url: https://localhost:9002/v1

tags:
- name: Users
Expand Down Expand Up @@ -666,7 +666,7 @@ paths:
description: Database can't process request.
"500":
$ref: "#/components/responses/ServiceError"

/{domainID}/users:
get:
summary: List users assigned to domain
Expand Down Expand Up @@ -1310,7 +1310,7 @@ components:
pattern: "^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$"
required: true
example: bb7edb32-2eac-4aad-aebe-ed96fe073879

ClientID:
name: clientID
description: Unique client identifier.
Expand Down
6 changes: 3 additions & 3 deletions auth/api/http/keys/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestIssue(t *testing.T) {
req := testRequest{
client: client,
method: http.MethodPost,
url: fmt.Sprintf("%s/keys", ts.URL),
url: fmt.Sprintf("%s/v1/keys", ts.URL),
contentType: tc.ct,
token: tc.token,
body: strings.NewReader(tc.req),
Expand Down Expand Up @@ -264,7 +264,7 @@ func TestRetrieve(t *testing.T) {
req := testRequest{
client: client,
method: http.MethodGet,
url: fmt.Sprintf("%s/keys/%s", ts.URL, tc.id),
url: fmt.Sprintf("%s/v1/keys/%s", ts.URL, tc.id),
token: tc.token,
}
repocall := krepo.On("Retrieve", mock.Anything, mock.Anything, mock.Anything).Return(tc.key, tc.err)
Expand Down Expand Up @@ -326,7 +326,7 @@ func TestRevoke(t *testing.T) {
req := testRequest{
client: client,
method: http.MethodDelete,
url: fmt.Sprintf("%s/keys/%s", ts.URL, tc.id),
url: fmt.Sprintf("%s/v1/keys/%s", ts.URL, tc.id),
token: tc.token,
}
repocall := krepo.On("Remove", mock.Anything, mock.Anything, mock.Anything).Return(nil)
Expand Down
7 changes: 5 additions & 2 deletions auth/api/http/keys/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ import (
kithttp "github.com/go-kit/kit/transport/http"
)

const contentType = "application/json"
const (
contentType = "application/json"
versionPrefix = "/v1"
)

// MakeHandler returns a HTTP handler for API endpoints.
func MakeHandler(svc auth.Service, mux *chi.Mux, logger *slog.Logger) *chi.Mux {
opts := []kithttp.ServerOption{
kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, api.EncodeError)),
}
mux.Route("/keys", func(r chi.Router) {
mux.Route(versionPrefix+"/keys", func(r chi.Router) {
r.Post("/", kithttp.NewServer(
issueEndpoint(svc),
decodeIssue,
Expand Down
9 changes: 5 additions & 4 deletions auth/api/http/pats/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ import (
)

const (
contentType = "application/json"
defInterval = "30d"
patPrefix = "pat_"
contentType = "application/json"
defInterval = "30d"
patPrefix = "pat_"
versionPrefix = "/v1"
)

// MakeHandler returns a HTTP handler for API endpoints.
func MakeHandler(svc auth.Service, mux *chi.Mux, logger *slog.Logger) *chi.Mux {
opts := []kithttp.ServerOption{
kithttp.ServerErrorEncoder(apiutil.LoggingErrorEncoder(logger, api.EncodeError)),
}
mux.Route("/pats", func(r chi.Router) {
mux.Route(versionPrefix+"/pats", func(r chi.Router) {
r.Post("/", kithttp.NewServer(
createPATEndpoint(svc),
decodeCreatePATRequest,
Expand Down
Loading

0 comments on commit 4bf37db

Please sign in to comment.