Skip to content

Commit

Permalink
Merge pull request #143 from picosh/am/send-log-sink
Browse files Browse the repository at this point in the history
Setup a send log sink
  • Loading branch information
antoniomika authored Oct 4, 2024
2 parents af3ceae + bca32c0 commit 63a91e3
Show file tree
Hide file tree
Showing 5 changed files with 408 additions and 11 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ jobs:
platforms: ${{ env.PLATFORMS }}
registry: ${{ env.REGISTRY }}
ssh: false
build-pico:
runs-on: ubuntu-22.04
needs: test
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup docker
uses: ./.github/actions/setup
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Run docker build for pico
uses: ./.github/actions/build
with:
app: pico
platforms: ${{ env.PLATFORMS }}
registry: ${{ env.REGISTRY }}
web: false
build-bouncer:
runs-on: ubuntu-22.04
needs: test
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ services:
- web
env_file:
- .env.prod
volumes:
- ./data/pastes-ssh/data:/app/ssh_data
pastes-ssh:
networks:
pastes:
Expand Down Expand Up @@ -116,6 +118,8 @@ services:
- web
env_file:
- .env.prod
volumes:
- ./data/pubsub-ssh/data:/app/ssh_data
pubsub-ssh:
networks:
pubsub:
Expand Down Expand Up @@ -158,6 +162,8 @@ services:
- web
env_file:
- .env.prod
volumes:
- ./data/prose-ssh/data:/app/ssh_data
prose-ssh:
networks:
prose:
Expand Down Expand Up @@ -202,6 +208,7 @@ services:
- .env.prod
volumes:
- ./data/storage/data:/app/.storage
- ./data/imgs-ssh/data:/app/ssh_data
imgs-ssh:
networks:
imgs:
Expand Down Expand Up @@ -248,6 +255,7 @@ services:
- .env.prod
volumes:
- ./data/storage/data:/app/.storage
- ./data/pgs-ssh/data:/app/ssh_data
pgs-ssh:
networks:
pgs:
Expand Down Expand Up @@ -296,6 +304,8 @@ services:
- web
env_file:
- .env.prod
volumes:
- ./data/feeds-ssh/data:/app/ssh_data
feeds-ssh:
networks:
feeds:
Expand Down
44 changes: 34 additions & 10 deletions pubsub/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,16 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
return
}

isAdmin := handler.DBPool.HasFeatureForUser(user.ID, "admin")

cmd := strings.TrimSpace(args[0])
if cmd == "help" {
wish.Println(sesh, helpStr(toSshCmd(handler.Cfg)))
next(sesh)
return
} else if cmd == "ls" {
topicFilter := fmt.Sprintf("%s/", user.Name)
if handler.DBPool.HasFeatureForUser(user.ID, "admin") {
if isAdmin {
topicFilter = ""
}

Expand Down Expand Up @@ -252,10 +254,18 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
if topic == "" {
topic = uuid.NewString()
}
name := toTopic(user.Name, topic)
if *public {
name = toPublicTopic(topic)

var name string

if isAdmin && strings.HasPrefix(topic, "/") {
name = strings.TrimPrefix(topic, "/")
} else {
name = toTopic(user.Name, topic)
if *public {
name = toPublicTopic(topic)
}
}

wish.Printf(
sesh,
"subscribe to this channel:\n\tssh %s sub %s\n",
Expand Down Expand Up @@ -363,9 +373,15 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
"topic", topic,
)

name := toTopic(user.Name, topic)
if *public {
name = toPublicTopic(topic)
var name string

if isAdmin && strings.HasPrefix(topic, "/") {
name = strings.TrimPrefix(topic, "/")
} else {
name = toTopic(user.Name, topic)
if *public {
name = toPublicTopic(topic)
}
}

err = pubsub.Sub(
Expand Down Expand Up @@ -405,10 +421,18 @@ func WishMiddleware(handler *CliHandler) wish.Middleware {
if isCreator {
topic = uuid.NewString()
}
name := toTopic(user.Name, topic)
if *public {
name = toPublicTopic(topic)

var name string

if isAdmin && strings.HasPrefix(topic, "/") {
name = strings.TrimPrefix(topic, "/")
} else {
name = toTopic(user.Name, topic)
if *public {
name = toPublicTopic(topic)
}
}

if isCreator {
wish.Printf(
sesh,
Expand Down
14 changes: 13 additions & 1 deletion shared/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,19 @@ func CreateLogger(space string) *slog.Logger {
log := slog.New(
slog.NewTextHandler(os.Stdout, opts),
)
return log.With("service", space)

newLogger := log

if strings.ToLower(GetEnv("PICO_SENDLOG_ENABLED", "true")) == "true" {
newLog, err := SendLogRegister(log, 100)
if err == nil {
newLogger = newLog
} else {
slog.Error("unable to start send logger", "error", err)
}
}

return newLogger.With("service", space)
}

func LoggerWithUser(logger *slog.Logger, user *db.User) *slog.Logger {
Expand Down
Loading

0 comments on commit 63a91e3

Please sign in to comment.