Skip to content

Commit

Permalink
wip: updating fake auhenticator
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored May 3, 2024
1 parent cd08992 commit 9f05a98
Show file tree
Hide file tree
Showing 11 changed files with 652 additions and 161 deletions.
87 changes: 72 additions & 15 deletions api/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,20 @@ paths:
operationId: version
tags:
- Server
security:
- bearerAuth: [] # no scopes required
- apiKey: [] # no scopes required
responses:
"200":
description: Successful
content:
application/json:
schema:
$ref: "#/components/schemas/Version"

"500":
$ref: "#/components/responses/InternalError"
"501":
$ref: "#/components/responses/Unimplemented"
/operators:
get:
summary: List all operators
Expand Down Expand Up @@ -442,6 +448,7 @@ paths:
- $ref: "#/components/parameters/limitParam"
security:
- bearerAuth: ["read:teams"]
- apiKey: ["read"]
responses:
"200":
description: Successfull response
Expand All @@ -450,12 +457,7 @@ paths:
schema:
allOf:
- $ref: "#/components/schemas/PaginatedResult"
- type: object
properties:
results:
type: array
items:
$ref: "#/components/schemas/Team"
- $ref: "#/components/schemas/Teams"

post:
summary: Creates a new team
Expand All @@ -471,20 +473,58 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/Team"
"404":
$ref: "#/components/responses/NotFound"
"400":
$ref: "#/components/responses/BadRequest"
"409":
$ref: "#/components/responses/Duplicate"
"500":
$ref: "#/components/responses/InternalError"
"501":
$ref: "#/components/responses/Unimplemented"

/teams/{teamId}:
get:
summary: Gets a team by ID
operationId: getTeam
parameters:
- $ref: "#/components/parameters/teamId"
security:
- bearerAuth: ["read"]
- apiKey: ["read"]
responses:
"200":
description: Successful
content:
application/json:
schema:
$ref: "#/components/schemas/Team"
"401":
$ref: "#/components/responses/Unauthorized"
"404":
$ref: "#/components/responses/NotFound"
"500":
$ref: "#/components/responses/InternalError"
"501":
$ref: "#/components/responses/Unimplemented"
delete:
summary: Deletes a team by ID
operationId: deleteTeam
parameters:
- $ref: "#/components/parameters/teamId"
security:
- bearerAuth: ["delete"]
- apiKey: ["delete"]
responses:
"204":
description: Successful
"401":
$ref: "#/components/responses/Unauthorized"
"500":
$ref: "#/components/responses/InternalError"
"501":
$ref: "#/components/responses/Unimplemented"

/teams/{teamId}/accounts:
get:
Expand Down Expand Up @@ -946,6 +986,12 @@ components:
application/json:
schema:
$ref: "#/components/schemas/Error"
Duplicate:
description: The requested resource was a duplicate.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"

requestBodies:
CreateSystem:
Expand Down Expand Up @@ -975,7 +1021,15 @@ components:
content:
application/json:
schema:
$ref: "#/components/schemas/Team"
type: object
required:
- name
properties:
name:
type: string
description:
type: string

CreateOperator:
content:
application/json:
Expand Down Expand Up @@ -1033,18 +1087,14 @@ components:
type: string

securitySchemes:
cookieAuth:
type: apiKey
in: cookie
name: JSESSIONID
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
apiKey:
in: header
name: apiKey
type: apiKey
in: header
name: X-API-Key

schemas:
Error:
Expand Down Expand Up @@ -1427,7 +1477,14 @@ components:
items:
$ref: "#/components/schemas/Operator"

Teams:
type: object
properties:
results:
type: array
items:
$ref: "#/components/schemas/Team"

security:
- cookieAuth: []
- bearerAuth: []
- apiKey: []
7 changes: 1 addition & 6 deletions internal/api/adapters/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ import (
"gorm.io/gorm"
)

var (
_ ports.Users = (*DB)(nil)
_ ports.Accounts = (*DB)(nil)
_ ports.Operators = (*DB)(nil)
_ ports.Systems = (*DB)(nil)
)
var _ ports.Repositories = (*DB)(nil)

// DB ...
type DB struct {
Expand Down
32 changes: 32 additions & 0 deletions internal/api/adapters/db/teams.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package db

import (
"context"

"github.com/google/uuid"
"github.com/zeiss/typhoon/internal/api/models"
)

// CreateTeam creates a new team.
func (db *DB) CreateTeam(ctx context.Context, team models.Team) (models.Team, error) {
if err := db.conn.WithContext(ctx).Create(&team).Error; err != nil {
return models.Team{}, err
}

return team, nil
}

// GetTeam retrieves a team by its ID.
func (db *DB) GetTeam(ctx context.Context, id uuid.UUID) (models.Team, error) {
team := models.Team{}
if err := db.conn.WithContext(ctx).Where("id = ?", id).First(&team).Error; err != nil {
return models.Team{}, err
}

return team, nil
}

// DeleteTeam deletes a team by its ID.
func (db *DB) DeleteTeam(ctx context.Context, id uuid.UUID) error {
return db.conn.WithContext(ctx).Where("id = ?", id).Delete(&models.Team{}).Error
}
33 changes: 31 additions & 2 deletions internal/api/controllers/teams.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
package controllers

import "github.com/zeiss/typhoon/internal/api/ports"
import (
"context"

"github.com/google/uuid"
authz "github.com/zeiss/fiber-authz"
"github.com/zeiss/typhoon/internal/api/models"
"github.com/zeiss/typhoon/internal/api/ports"
)

// TeamsController ...
type TeamsController interface{}
type TeamsController interface {
// CreateTeam ...
CreateTeam(ctx context.Context, name string) (models.Team, error)
// DeleteTeam ...
DeleteTeam(ctx context.Context, id uuid.UUID) error
// GetTeam ...
GetTeam(ctx context.Context, id uuid.UUID) (models.Team, error)
}

type teamsController struct {
db ports.Teams
Expand All @@ -13,3 +27,18 @@ type teamsController struct {
func NewTeamsController(db ports.Teams) *teamsController {
return &teamsController{db}
}

// CreateTeam ...
func (c *teamsController) CreateTeam(ctx context.Context, name string) (models.Team, error) {
return c.db.CreateTeam(ctx, models.Team{Team: &authz.Team{Name: name}})
}

// DeleteTeam ...
func (c *teamsController) DeleteTeam(ctx context.Context, id uuid.UUID) error {
return c.db.DeleteTeam(ctx, id)
}

// GetTeam ...
func (c *teamsController) GetTeam(ctx context.Context, id uuid.UUID) (models.Team, error) {
return c.db.GetTeam(ctx, id)
}
4 changes: 2 additions & 2 deletions internal/api/ports/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package ports

// Repositories is the interface that wraps the methods to access data.
type Repositories interface {
Systems
Teams
Accounts
Operators
Systems
Teams
Users
}
16 changes: 15 additions & 1 deletion internal/api/ports/teams.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
package ports

import (
"context"

"github.com/google/uuid"
"github.com/zeiss/typhoon/internal/api/models"
)

// Teams is the interface that wraps the methods to access data.
type Teams interface{}
type Teams interface {
// CreateTeam creates a new team.
CreateTeam(ctx context.Context, team models.Team) (models.Team, error)
// GetTeam returns the team with the given id.
GetTeam(ctx context.Context, id uuid.UUID) (models.Team, error)
// DeleteTeam deletes the team with the given id.
DeleteTeam(ctx context.Context, id uuid.UUID) error
}
5 changes: 5 additions & 0 deletions pkg/apis/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ func (u *Unimplemented) GetTeam(ctx context.Context, request GetTeamRequestObjec
return nil, errors.New("not implemented")
}

// DeleteTeam ...
func (u *Unimplemented) DeleteTeam(ctx context.Context, request DeleteTeamRequestObject) (DeleteTeamResponseObject, error) {
return DeleteTeam501JSONResponse(DeleteTeam501JSONResponse{UnimplementedJSONResponse(NotImplemented("Not implemented"))}), nil
}

// ListAccounts ...
func (u *Unimplemented) ListTeamAccounts(ctx context.Context, request ListTeamAccountsRequestObject) (ListTeamAccountsResponseObject, error) {
return nil, errors.New("not implemented")
Expand Down
Loading

0 comments on commit 9f05a98

Please sign in to comment.