feat: Add auth flow (#146)

This adds a simple way to incorporate a centralized authentication flow.

The idea is to have the user, API and SSH (for machine authentication)
all in one place using `openauthjs` + `SST`

We also have a database now :)

> We are using InstantDB as it allows us to authenticate a use with just
the email. Plus it is super simple simple to use _of course after the
initial fumbles trying to design the db and relationships_
This commit is contained in:
Wanjohi
2025-01-04 00:02:28 +03:00
committed by GitHub
parent 33895974a7
commit fc5a755408
136 changed files with 3512 additions and 1914 deletions

View File

@@ -0,0 +1,76 @@
package session
import (
"bytes"
"context"
"fmt"
"io"
"strings"
"github.com/docker/docker/api/types/container"
)
// ExecResult holds the output from a container command
type ExecResult struct {
ExitCode int
Stdout string
Stderr string
}
func (s *Session) execInContainer(ctx context.Context, cmd []string) (*ExecResult, error) {
execConfig := container.ExecOptions{
Cmd: cmd,
AttachStdout: true,
AttachStderr: true,
}
execID, err := s.client.ContainerExecCreate(ctx, s.containerID, execConfig)
if err != nil {
return nil, err
}
resp, err := s.client.ContainerExecAttach(ctx, execID.ID, container.ExecAttachOptions{})
if err != nil {
return nil, err
}
defer resp.Close()
var outBuf bytes.Buffer
_, err = io.Copy(&outBuf, resp.Reader)
if err != nil {
return nil, err
}
inspect, err := s.client.ContainerExecInspect(ctx, execID.ID)
if err != nil {
return nil, err
}
return &ExecResult{
ExitCode: inspect.ExitCode,
Stdout: outBuf.String(),
}, nil
}
// CheckSteamGames returns the list of installed games in the container
func (s *Session) CheckInstalledSteamGames(ctx context.Context) ([]uint64, error) {
result, err := s.execInContainer(ctx, []string{
"sh", "-c",
"find /home/nestri/.steam/steam/steamapps -name '*.acf' -exec grep -H '\"appid\"' {} \\;",
})
if err != nil {
return nil, fmt.Errorf("failed to check steam games: %v", err)
}
var gameIDs []uint64
for _, line := range strings.Split(result.Stdout, "\n") {
if strings.Contains(line, "appid") {
var id uint64
if _, err := fmt.Sscanf(line, `"appid" "%d"`, &id); err == nil {
gameIDs = append(gameIDs, id)
}
}
}
return gameIDs, nil
}