Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,26 @@ Usage:
keepitup <noun> <verb> [args...]

Nouns:
game add <name>
game add <name>
update <id> <name>
delete <id>
access grant <game id> <player id>
access grant <game id> <player id>
revoke <game id> <player id>
player add <name> <username> <password>
rename <id> <name>
passwd <id> <current password> <new password>
check <game id> <player id>
player add <name> <username> <password>
rename <id> <name>
passwd <id> <current password> <new password>
passwd-force <id> <password>
delete <id>
delete <id>
auth validate-passwd <password>
hash-passwd <password>
check-passwd <username> <password>
fetch games <player id>
shared <game id>
hash-passwd <password>
check-passwd <username> <password>
fetch games <player id>
shared <game id>
interactions <game id> <limit>
command save <game id> <player id> <duration in seconds>
command save <game id> <player id> <duration in seconds>
resume <game id> <player id>
pause <game id> <player id>
pause <game id> <player id>
```

## HTTP API
Expand Down
6 changes: 6 additions & 0 deletions database/queries/access.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ RETURNING game_id, player_id;
-- name: RevokePlayerAccess :exec
DELETE FROM access
WHERE game_id = ? AND player_id = ?;

-- name: CheckPlayerAccess :one
SELECT EXISTS (
SELECT 1 FROM access
WHERE game_id = ? AND player_id = ?
);
24 changes: 24 additions & 0 deletions internal/application/usecase/access_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,27 @@ func (uc *AccessManagement) RevokePlayerAccess(
},
)
}

func (uc *AccessManagement) CheckPlayerAccess(
ctx context.Context, gameId, playerId int64,
) (bool, error) {
if uc.q == nil {
return false, errors.New("database queries are not initialized")
}

if gameId < 1 {
return false, fmt.Errorf("invalid game ID: %d", gameId)
}

if playerId < 1 {
return false, fmt.Errorf("invalid player ID: %d", playerId)
}

return uc.q.CheckPlayerAccess(
ctx,
database.CheckPlayerAccessParams{
GameID: gameId,
PlayerID: playerId,
},
)
}
6 changes: 0 additions & 6 deletions internal/application/usecase/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,3 @@ func (uc *Authentication) LoginPlayer(
Player: player,
}, nil
}

func (uc *Authentication) ValidateSession(
ctx context.Context, token string,
) (database.Player, error) {
return database.Player{}, nil
}
26 changes: 11 additions & 15 deletions internal/core/port/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ type GameManagement interface {
}

type AccessManagement interface {
GrantPlayerAccess(ctx context.Context, gameId int64, playerId int64) error
RevokePlayerAccess(ctx context.Context, gameId int64, playerId int64) error
GrantPlayerAccess(ctx context.Context, gameId, playerId int64) error
RevokePlayerAccess(ctx context.Context, gameId, playerId int64) error
CheckPlayerAccess(ctx context.Context, gameId, playerId int64) (bool, error)
}

type PlayerManagement interface {
AddPlayer(
ctx context.Context, name string, username string, password string,
ctx context.Context, name, username, password string,
) (database.Player, error)
UpdatePlayerName(
ctx context.Context, id int64, name string,
) error
UpdatePlayerPassword(
ctx context.Context, id int64, currentPassword string, newPassword string,
ctx context.Context, id int64, currentPassword, newPassword string,
) error
UpdatePlayerPasswordForce(
ctx context.Context, id int64, password string,
Expand All @@ -37,14 +38,11 @@ type PlayerManagement interface {

type Authentication interface {
CheckPlayerPassword(
ctx context.Context, username string, password string,
ctx context.Context, username, password string,
) (bool, error)
LoginPlayer(
ctx context.Context, username string, password string,
ctx context.Context, username, password string,
) (model.AuthResult, error)
ValidateSession(
ctx context.Context, token string,
) (database.Player, error)
}

type DataFetching interface {
Expand All @@ -55,17 +53,15 @@ type DataFetching interface {
ctx context.Context, gameId int64,
) (*model.SharedData, error)
ListInteractions(
ctx context.Context, gameId int64, limit int64,
ctx context.Context, gameId, limit int64,
) ([]database.Interaction, error)
// TODO: List Player Interactions
// TODO: First Interaction
// TODO: Last Interaction
}

type GameCommands interface {
SaveGame(
ctx context.Context, gameId int64, playerId int64, duration int64,
) error
ResumeGame(ctx context.Context, gameId int64, playerId int64) error
PauseGame(ctx context.Context, gameId int64, playerId int64) error
SaveGame(ctx context.Context, gameId, playerId, duration int64) error
ResumeGame(ctx context.Context, gameId, playerId int64) error
PauseGame(ctx context.Context, gameId, playerId int64) error
}
19 changes: 19 additions & 0 deletions internal/infrastructure/database/access.sql.go

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

52 changes: 37 additions & 15 deletions internal/infrastructure/driver/cliadapter/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,27 @@ var (

const usage = `keep-it-up --- system management CLI

Usage:
keepitup <noun> <verb> [args...]

Nouns:
game add <name>
game add <name>
update <id> <name>
delete <id>
access grant <game id> <player id>
access grant <game id> <player id>
revoke <game id> <player id>
player add <name> <username> <password>
rename <id> <name>
passwd <id> <current password> <new password>
check <game id> <player id>
player add <name> <username> <password>
rename <id> <name>
passwd <id> <current password> <new password>
passwd-force <id> <password>
delete <id>
delete <id>
auth validate-passwd <password>
hash-passwd <password>
check-passwd <username> <password>
fetch games <player id>
shared <game id>
hash-passwd <password>
check-passwd <username> <password>
fetch games <player id>
shared <game id>
interactions <game id> <limit>
command save <game id> <player id> <duration in seconds>
command save <game id> <player id> <duration in seconds>
resume <game id> <player id>
pause <game id> <player id>
pause <game id> <player id>
`

// Deps groups the driver ports and I/O streams the CLI needs. It is a
Expand Down Expand Up @@ -215,6 +213,30 @@ func (c *CLI) runAccess(ctx context.Context, args []string) error {
fmt.Fprintf(c.d.Stdout, "player %d access to game %d revoked\n", playerID, gameID)
return nil

case "check":
if len(rest) != 2 {
return wrongArgs("access check", "access check <game id> <player id>")
}
gameID, err := parseID(rest[0])
if err != nil {
return fmt.Errorf("access check: %w", err)
}
playerID, err := parseID(rest[1])
if err != nil {
return fmt.Errorf("access check: %w", err)
}

access, err := c.d.Access.CheckPlayerAccess(ctx, gameID, playerID)
if err != nil {
return fmt.Errorf("access check: %w", err)
}
fmt.Fprintf(
c.d.Stdout,
"player %d access to game %d: %v\n",
playerID, gameID, access,
)
return nil

default:
return fmt.Errorf("access %s: %w", verb, ErrUnknownSubcommand)
}
Expand Down
Loading