Skip to content

Commit

Permalink
multi-tenancy: Implements multi-tenancy
Browse files Browse the repository at this point in the history
This commit implements multi-tenancy.
DB resources _agent_ and _source_ have two additional columns: username
and org_id.
The _user_ struct is passed though the context to service layer by the
auth middleware. Each service check if username is available in the
context and use it to filter resources or to verify that the resource
belongs to the user. Otherwise, it responds with 403.

The buissness logic remains unchanged.

There is no RBAC implemented in this commit (e.g. admin **sees**
everything or only the user with _admin_ role has the right to access
mutating endpoints).

Adds:
- filter by username to agent and source store.
- mappers between api and models in the service layer.

Modifies:

Agent and source store interface are changed to accept models from the
store instead of api's models.
For example:

```
type Agent interface {
    ...
    Update(ctx context.Context, agentUpdate apiAgent.AgentStatusUpdate) (*api.Agent, error)
    ...
}
```
is changed to
```
type Agent interface {
    ...
    Update(ctx context.Context, agent model.Agent) (*model.Agent, error)
    ...
}```

A consequence of this is that mapping between API and DB models is made
in the service layer with the help of `mappers`.

Signed-off-by: Cosmin Tupangiu <[email protected]>
  • Loading branch information
tupyy committed Jan 8, 2025
1 parent 7953ba0 commit cb07e7a
Show file tree
Hide file tree
Showing 25 changed files with 964 additions and 331 deletions.
12 changes: 12 additions & 0 deletions api/v1alpha1/agent/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ paths:
application/json:
schema:
$ref: '../openapi.yaml#/components/schemas/Error'
"403":
description: Forbidden
content:
application/json:
schema:
$ref: '../openapi.yaml#/components/schemas/Error'
"404":
description: NotFound
content:
Expand Down Expand Up @@ -95,6 +101,12 @@ paths:
application/json:
schema:
$ref: '../openapi.yaml#/components/schemas/Error'
"403":
description: Forbidden
content:
application/json:
schema:
$ref: '../openapi.yaml#/components/schemas/Error'
"410":
description: Gone
content:
Expand Down
44 changes: 22 additions & 22 deletions api/v1alpha1/agent/spec.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions api/v1alpha1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
"403":
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
"404":
description: NotFound
content:
Expand Down Expand Up @@ -116,6 +122,12 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
"403":
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
"404":
description: NotFound
content:
Expand Down Expand Up @@ -209,6 +221,12 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
"403":
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
"500":
description: Internal Server Error
content:
Expand Down Expand Up @@ -248,6 +266,12 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
"403":
description: Forbidden
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
"404":
description: NotFound
content:
Expand Down
62 changes: 31 additions & 31 deletions api/v1alpha1/spec.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions internal/api/client/agent/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions internal/api/client/client.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions internal/api/server/agent/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cb07e7a

Please sign in to comment.