Skip to content

Commit

Permalink
Implement client side configuration (#26)
Browse files Browse the repository at this point in the history
* start working on implementing client side configuration

* use dynamic colorscheme

* update readme

* use default tui colorscheme
  • Loading branch information
adelowo authored Oct 16, 2024
1 parent c87b72b commit 5b3d147
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.ssh/
# deploy/
id_ed25*
id_ed25519*
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ I spend an awful amount of time in the terminal and it makes sense i should
be able to spin up and use a request bin on my terminal. Hence this
project sdump


### How to use public hosted version

```sh
Expand All @@ -32,7 +31,7 @@ ssh -p 2222 ssh.sdump.app
- `sdump http`: starts the HTTP server.
- `sdump ssh`: starts the SSH server
- `sdump delete-http`: deletes/prunes old ingested requests. This can be a form
of a cron job that runs every few days or so
of a cron job that runs every few days or so

### Configuration file

Expand All @@ -57,12 +56,12 @@ ssh:
## port to run ssh server on
port: 2222
## allow_list is a list of public keys that can connect to the ssh server
# this is useful if you were running a private instance for a few coworkers
# this is useful if you were running a private instance for a few coworkers
# or friends
allow_list:
- ./.ssh/id_rsa.pub
- /Users/lanreadelowo/.ssh/id_rsa.pub

## keys for the ssh server
identities:
- "id_ed25519"
Expand All @@ -80,8 +79,8 @@ http:
database:
## database dsn
dsn: postgres://sdump:sdump@localhost:3432/sdump?sslmode=disable
## should we log sql queries? In prod, no but in local mode,
## you probably want to
## should we log sql queries? In prod, no but in local mode,
## you probably want to
log_queries: true

# limit the size of jSON request body that can be sent to endpoints
Expand All @@ -93,7 +92,7 @@ http:
use_tls: true
## custom name you want to use to identify the service
service_name: SDUMP
## OTEL Endpoint
## OTEL Endpoint
endpoint: http://localhost:4200
## Should we trace all http and DB requests
is_enabled: false
Expand Down
1 change: 1 addition & 0 deletions cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func teaHandler(cfg *config.Config) func(s ssh.Session) (tea.Model, []tea.Progra
tui.WithWidth(pty.Window.Width),
tui.WithHeight(pty.Window.Height),
tui.WithSSHFingerPrint(sshFingerPrint),
tui.WithColorscheme(cfg.TUI.ColorScheme),
)
if err != nil {
wish.Fatalln(s, fmt.Errorf("%v...Could not set up TUI session", err))
Expand Down
12 changes: 7 additions & 5 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cron:
tui:
## the color_scheme to use for the request body
# see https://github.com/alecthomas/chroma/tree/master/styles
color_scheme: monokai
color_scheme: catppuccin-mocha

ssh:
## port to run ssh server on
Expand All @@ -35,14 +35,16 @@ http:
## limit the number of ingested requests from a specific client
requests_per_minute: 10

## database configuration. postgres essentially
## database configuration.
database:
## database dsn
dsn: postgres://sdump:sdump@localhost:3432/sdump?sslmode=disable
# dsn: "file::memory:?cache=shared"
# driver: "sqlite"

dsn: postgres://sdump:sdump@localhost:3432/sdump?sslmode=disable
driver: "postgres"

## should we log sql queries? In prod, no but in local mode, you probably want to
log_queries: true
# driver: "sqlite"

# limit the size of jSON request body that can be sent to endpoints
max_request_body_size: 500
Expand Down
8 changes: 5 additions & 3 deletions internal/tui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type model struct {

requestList list.Model
httpClient *http.Client
colorscheme string

sseClient *sse.Client
receiveChan chan item
Expand Down Expand Up @@ -87,9 +88,10 @@ func newModel(cfg *config.Config, width, height int) model {
}

m := model{
width: width,
height: height,
title: "Sdump",
colorscheme: cfg.TUI.ColorScheme,
width: width,
height: height,
title: "Sdump",
spinner: spinner.New(
spinner.WithSpinner(spinner.Line),
spinner.WithStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("205"))),
Expand Down
10 changes: 9 additions & 1 deletion internal/tui/option.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package tui

import "github.com/adelowo/sdump/config"
import (
"github.com/adelowo/sdump/config"
)

type Option func(*model)

func WithColorscheme(colorscheme string) Option {
return func(m *model) {
m.colorscheme = colorscheme
}
}

func WithConfig(cfg *config.Config) Option {
return func(m *model) {
m.cfg = cfg
Expand Down

0 comments on commit 5b3d147

Please sign in to comment.