diff --git a/.env.example b/.env.example index a231f5f3..cd56239e 100644 --- a/.env.example +++ b/.env.example @@ -146,19 +146,19 @@ AUTH_DOMAIN=http://auth.dev.pico.sh:3006 AUTH_ISSUER=pico.sh AUTH_WEB_PORT=3000 -PUBSUB_CADDYFILE=./caddy/Caddyfile -PUBSUB_V4= -PUBSUB_V6= -PUBSUB_HTTP_V4=$PUBSUB_V4:80 -PUBSUB_HTTP_V6=[$PUBSUB_V6]:80 -PUBSUB_HTTPS_V4=$PUBSUB_V4:443 -PUBSUB_HTTPS_V6=[$PUBSUB_V6]:443 -PUBSUB_SSH_V4=$PUBSUB_V4:22 -PUBSUB_SSH_V6=[$PUBSUB_V6]:22 -PUBSUB_HOST= -PUBSUB_SSH_PORT=2222 -PUBSUB_WEB_PORT=3000 -PUBSUB_PROM_PORT=9222 -PUBSUB_DOMAIN=pubsub.dev.pico.sh:3001 -PUBSUB_PROTOCOL=http -PUBSUB_DEBUG=1 +PIPE_CADDYFILE=./caddy/Caddyfile +PIPE_V4= +PIPE_V6= +PIPE_HTTP_V4=$PIPE_V4:80 +PIPE_HTTP_V6=[$PIPE_V6]:80 +PIPE_HTTPS_V4=$PIPE_V4:443 +PIPE_HTTPS_V6=[$PIPE_V6]:443 +PIPE_SSH_V4=$PIPE_V4:22 +PIPE_SSH_V6=[$PIPE_V6]:22 +PIPE_HOST= +PIPE_SSH_PORT=2222 +PIPE_WEB_PORT=3000 +PIPE_PROM_PORT=9222 +PIPE_DOMAIN=pipe.dev.pico.sh:3001 +PIPE_PROTOCOL=http +PIPE_DEBUG=1 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2485ac8d..c51a306c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,7 +41,7 @@ jobs: needs: test strategy: matrix: - APP: [prose, pastes, imgs, pgs, feeds, pubsub] + APP: [prose, pastes, imgs, pgs, feeds, pipe] steps: - name: Checkout repo uses: actions/checkout@v3 diff --git a/Makefile b/Makefile index 2c836a47..0451193e 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,7 @@ bp-%: bp-setup $(DOCKER_BUILDX_BUILD) --build-arg "APP=$*" -t "ghcr.io/picosh/pico/$*-web:$(DOCKER_TAG)" --target release-web . .PHONY: bp-% -bp-all: bp-prose bp-pastes bp-imgs bp-feeds bp-pgs bp-auth bp-bouncer bp-pubsub +bp-all: bp-prose bp-pastes bp-imgs bp-feeds bp-pgs bp-auth bp-bouncer bp-pipe .PHONY: bp-all build-auth: @@ -74,7 +74,7 @@ build-%: go build -o "build/$*-ssh" "./cmd/$*/ssh" .PHONY: build-% -build: build-prose build-pastes build-imgs build-feeds build-pgs build-auth build-pico build-pubsub +build: build-prose build-pastes build-imgs build-feeds build-pgs build-auth build-pico build-pipe .PHONY: build store-clean: diff --git a/caddy/Caddyfile.auth b/caddy/Caddyfile.auth index 8aa34726..7a5651df 100644 --- a/caddy/Caddyfile.auth +++ b/caddy/Caddyfile.auth @@ -1,9 +1,4 @@ { - on_demand_tls { - ask http://web:3000/check - interval 1m - burst 10 - } servers { metrics } @@ -129,11 +124,3 @@ Access-Control-Allow-Headers "*" } } - -:443 { - reverse_proxy web:3000 - tls {$APP_EMAIL} { - on_demand - } - encode zstd gzip -} diff --git a/caddy/Caddyfile.monitoring b/caddy/Caddyfile.monitoring deleted file mode 100644 index e611c7ba..00000000 --- a/caddy/Caddyfile.monitoring +++ /dev/null @@ -1,102 +0,0 @@ -{ - on_demand_tls { - ask http://web:3000/check - interval 1m - burst 10 - } - servers { - metrics - } -} - -*.{$APP_DOMAIN}, {$APP_DOMAIN} { - reverse_proxy web:3000 - tls {$APP_EMAIL} { - dns cloudflare {$CF_API_TOKEN} - resolvers 1.1.1.1 - } - encode zstd gzip - - header { - # disable FLoC tracking - Permissions-Policy interest-cohort=() - - # enable HSTS - Strict-Transport-Security max-age=31536000; - - # disable clients from sniffing the media type - X-Content-Type-Options nosniff - - # clickjacking protection - X-Frame-Options DENY - - # keep referrer data off of HTTP connections - Referrer-Policy no-referrer-when-downgrade - - Content-Security-Policy "default-src 'self'; img-src * 'unsafe-inline'; style-src * 'unsafe-inline'" - - X-XSS-Protection "1; mode=block" - } - - @caddymetrics { - host {$APP_DOMAIN} - path /_caddy/metrics - } - - metrics @caddymetrics { - disable_openmetrics - } - - @appmetrics { - host {$APP_DOMAIN} - path /_app/metrics - } - - handle @appmetrics { - rewrite * /metrics - reverse_proxy ssh:9222 - } -} - -monitoring.{$MONITORING_APP_DOMAIN}, prometheus.{$MONITORING_APP_DOMAIN}, grafana.{$MONITORING_APP_DOMAIN} { - @grafana { - host grafana.{$MONITORING_APP_DOMAIN} - } - - @prometheus { - host prometheus.{$MONITORING_APP_DOMAIN} - } - - tls {$MONITORING_APP_EMAIL} { - dns cloudflare {$CF_API_TOKEN} - resolvers 1.1.1.1 - } - - encode zstd gzip - - reverse_proxy @grafana grafana:3000 - - basicauth @prometheus { - eric JDJhJDE0JDdPOXhoNUdhSmNVNDl6UWpmeTE0cWVkLjRwcUNJUnc0dVQ4MTZNSmVaNjA1TlptaVZYY1hh - antonio JDJhJDE0JHI5dkVtMW0vcGxIb011OG4vME5HOU91c3U2VjM2QTZiWVpUeXdSbEg3VUtNZVdhN3BRazFH - bot JDJhJDE0JFVsRlNHSDlJbFhDeUd0NldRR2JkcGVFYUJtWGluTHZDVlc5L3QwNWNwWUMuODRlcXZNZHpT - } - reverse_proxy @prometheus prometheus:9090 - - @caddymetrics { - host monitoring.{$MONITORING_APP_DOMAIN} - path /_caddy/metrics - } - - metrics @caddymetrics { - disable_openmetrics - } -} - -:443 { - reverse_proxy web:3000 - tls {$APP_EMAIL} { - on_demand - } - encode zstd gzip -} diff --git a/caddy/Caddyfile.pico b/caddy/Caddyfile.pico index 40604325..9a2ff260 100644 --- a/caddy/Caddyfile.pico +++ b/caddy/Caddyfile.pico @@ -1,4 +1,4 @@ -{$APP_DOMAIN}, tmp.pico.sh { +{$APP_DOMAIN} { reverse_proxy https://pico-docs-prod.pgs.sh { header_up Host pico-docs-prod.pgs.sh } diff --git a/caddy/Caddyfile.pipe b/caddy/Caddyfile.pipe new file mode 100644 index 00000000..df59c7e8 --- /dev/null +++ b/caddy/Caddyfile.pipe @@ -0,0 +1,54 @@ +{ + servers { + metrics + } +} + +*.{$APP_DOMAIN}, {$APP_DOMAIN} { + reverse_proxy web:3000 + tls {$APP_EMAIL} { + dns cloudflare {$CF_API_TOKEN} + resolvers 1.1.1.1 + } + encode zstd gzip + + header { + # disable FLoC tracking + Permissions-Policy interest-cohort=() + + # enable HSTS + Strict-Transport-Security max-age=31536000; + + # disable clients from sniffing the media type + X-Content-Type-Options nosniff + + # clickjacking protection + X-Frame-Options DENY + + # keep referrer data off of HTTP connections + Referrer-Policy no-referrer-when-downgrade + + Content-Security-Policy "default-src 'self'; img-src * 'unsafe-inline'; style-src * 'unsafe-inline'" + + X-XSS-Protection "1; mode=block" + } + + @caddymetrics { + host {$APP_DOMAIN} + path /_caddy/metrics + } + + metrics @caddymetrics { + disable_openmetrics + } + + @appmetrics { + host {$APP_DOMAIN} + path /_app/metrics + } + + handle @appmetrics { + rewrite * /metrics + reverse_proxy ssh:9222 + } +} diff --git a/caddy/Caddyfile.pubsub b/caddy/Caddyfile.pubsub deleted file mode 100644 index d6fcea4c..00000000 --- a/caddy/Caddyfile.pubsub +++ /dev/null @@ -1,8 +0,0 @@ -{$APP_DOMAIN} { - reverse_proxy web:3000 - - tls {$APP_EMAIL} { - dns cloudflare {$CF_API_TOKEN} - resolvers 1.1.1.1 - } -} diff --git a/cmd/pipe/ssh/main.go b/cmd/pipe/ssh/main.go new file mode 100644 index 00000000..6f3c41f0 --- /dev/null +++ b/cmd/pipe/ssh/main.go @@ -0,0 +1,7 @@ +package main + +import "github.com/picosh/pico/pipe" + +func main() { + pipe.StartSshServer() +} diff --git a/cmd/pipe/web/main.go b/cmd/pipe/web/main.go new file mode 100644 index 00000000..ac2ea8e9 --- /dev/null +++ b/cmd/pipe/web/main.go @@ -0,0 +1,7 @@ +package main + +import "github.com/picosh/pico/pipe" + +func main() { + pipe.StartApiServer() +} diff --git a/cmd/pubsub/ssh/main.go b/cmd/pubsub/ssh/main.go deleted file mode 100644 index d2d818b6..00000000 --- a/cmd/pubsub/ssh/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "github.com/picosh/pico/pubsub" - -func main() { - pubsub.StartSshServer() -} diff --git a/cmd/pubsub/web/main.go b/cmd/pubsub/web/main.go deleted file mode 100644 index cccc9b11..00000000 --- a/cmd/pubsub/web/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "github.com/picosh/pico/pubsub" - -func main() { - pubsub.StartApiServer() -} diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 64dea139..dce05a22 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -45,24 +45,24 @@ services: - ./data/pastes-ssh/data:/app/ssh_data ports: - "2221:2222" - pubsub-web: + pipe-web: build: args: - APP: pubsub + APP: pipe target: release-web env_file: - .env.example ports: - "3001:3000" - pubsub-ssh: + pipe-ssh: build: args: - APP: pubsub + APP: pipe target: release-ssh env_file: - .env.example volumes: - - ./data/pubsub-ssh/data:/app/ssh_data + - ./data/pipe-ssh/data:/app/ssh_data ports: - "2221:2222" prose-web: diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index 2b6133a6..12cb24ad 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -88,50 +88,50 @@ services: ports: - "${PASTES_SSH_V4:-22}:2222" - "${PASTES_SSH_V6:-[::1]:22}:2222" - pubsub-caddy: + pipe-caddy: image: ghcr.io/picosh/pico/caddy:latest restart: always networks: - - pubsub + - pipe env_file: - .env.prod environment: - APP_DOMAIN: ${PUBSUB_DOMAIN:-pipe.pico.sh} - APP_EMAIL: ${PUBSUB_EMAIL:-hello@pico.sh} + APP_DOMAIN: ${PIPE_DOMAIN:-pipe.pico.sh} + APP_EMAIL: ${PIPE_EMAIL:-hello@pico.sh} volumes: - - ${PUBSUB_CADDYFILE}:/etc/caddy/Caddyfile - - ./data/pubsub-caddy/data:/data - - ./data/pubsub-caddy/config:/config + - ${PIPE_CADDYFILE}:/etc/caddy/Caddyfile + - ./data/pipe-caddy/data:/data + - ./data/pipe-caddy/config:/config ports: - - "${PUBSUB_HTTPS_V4:-443}:443" - - "${PUBSUB_HTTP_V4:-80}:80" - - "${PUBSUB_HTTPS_V6:-[::1]:443}:443" - - "${PUBSUB_HTTP_V6:-[::1]:80}:80" + - "${PIPE_HTTPS_V4:-443}:443" + - "${PIPE_HTTP_V4:-80}:80" + - "${PIPE_HTTPS_V6:-[::1]:443}:443" + - "${PIPE_HTTP_V6:-[::1]:80}:80" profiles: - - pubsub + - pipe - caddy - all - pubsub-web: + pipe-web: networks: - pubsub: + pipe: aliases: - web env_file: - .env.prod volumes: - - ./data/pubsub-ssh/data:/app/ssh_data - pubsub-ssh: + - ./data/pipe-ssh/data:/app/ssh_data + pipe-ssh: networks: - pubsub: + pipe: aliases: - ssh env_file: - .env.prod volumes: - - ./data/pubsub-ssh/data:/app/ssh_data + - ./data/pipe-ssh/data:/app/ssh_data ports: - - "${PUBSUB_SSH_V4:-22}:2222" - - "${PUBSUB_SSH_V6:-[::1]:22}:2222" + - "${PIPE_SSH_V4:-22}:2222" + - "${PIPE_SSH_V6:-[::1]:22}:2222" prose-caddy: image: ghcr.io/picosh/pico/caddy:latest restart: always @@ -396,9 +396,9 @@ networks: ipam: config: - subnet: 172.25.0.0/16 - pubsub: + pipe: driver_opts: - com.docker.network.bridge.name: pubsub + com.docker.network.bridge.name: pipe ipam: config: - subnet: 172.27.0.0/16 diff --git a/docker-compose.yml b/docker-compose.yml index 68b4f856..b2d03143 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -43,18 +43,18 @@ services: - pastes - services - all - pubsub-web: - image: ghcr.io/picosh/pico/pubsub-web:latest + pipe-web: + image: ghcr.io/picosh/pico/pipe-web:latest restart: always profiles: - - pubsub + - pipe - services - all - pubsub-ssh: - image: ghcr.io/picosh/pico/pubsub-ssh:latest + pipe-ssh: + image: ghcr.io/picosh/pico/pipe-ssh:latest restart: always profiles: - - pubsub + - pipe - services - all prose-web: diff --git a/feeds/ssh.go b/feeds/ssh.go index 16f9755b..caba5a59 100644 --- a/feeds/ssh.go +++ b/feeds/ssh.go @@ -13,7 +13,7 @@ import ( "github.com/charmbracelet/wish" "github.com/picosh/pico/db/postgres" "github.com/picosh/pico/filehandlers" - "github.com/picosh/pico/filehandlers/util" + "github.com/picosh/pico/shared" "github.com/picosh/pico/shared/storage" wsh "github.com/picosh/pico/wish" "github.com/picosh/send/auth" @@ -83,7 +83,7 @@ func StartSshServer() { } handler := filehandlers.NewFileHandlerRouter(cfg, dbh, fileMap) - sshAuth := util.NewSshAuthHandler(dbh, logger, cfg) + sshAuth := shared.NewSshAuthHandler(dbh, logger, cfg) s, err := wish.NewServer( wish.WithAddress(fmt.Sprintf("%s:%s", host, port)), wish.WithHostKeyPath("ssh_data/term_info_ed25519"), diff --git a/filehandlers/assets/handler.go b/filehandlers/assets/handler.go index d40caf30..2ed16d9e 100644 --- a/filehandlers/assets/handler.go +++ b/filehandlers/assets/handler.go @@ -16,8 +16,6 @@ import ( "github.com/charmbracelet/ssh" "github.com/charmbracelet/wish" "github.com/picosh/pico/db" - "github.com/picosh/pico/filehandlers/util" - futil "github.com/picosh/pico/filehandlers/util" "github.com/picosh/pico/shared" "github.com/picosh/pico/shared/storage" "github.com/picosh/pobj" @@ -118,7 +116,7 @@ func (h *UploadAssetHandler) GetLogger() *slog.Logger { } func (h *UploadAssetHandler) Read(s ssh.Session, entry *sendutils.FileEntry) (os.FileInfo, sendutils.ReaderAtCloser, error) { - user, err := futil.GetUser(s.Context()) + user, err := shared.GetUser(s.Context()) if err != nil { return nil, nil, err } @@ -152,7 +150,7 @@ func (h *UploadAssetHandler) Read(s ssh.Session, entry *sendutils.FileEntry) (os func (h *UploadAssetHandler) List(s ssh.Session, fpath string, isDir bool, recursive bool) ([]os.FileInfo, error) { var fileList []os.FileInfo - user, err := futil.GetUser(s.Context()) + user, err := shared.GetUser(s.Context()) if err != nil { return fileList, err } @@ -194,7 +192,7 @@ func (h *UploadAssetHandler) List(s ssh.Session, fpath string, isDir bool, recur } func (h *UploadAssetHandler) Validate(s ssh.Session) error { - user, err := util.GetUser(s.Context()) + user, err := shared.GetUser(s.Context()) if err != nil { return err } @@ -245,7 +243,7 @@ func (h *UploadAssetHandler) findDenylist(bucket sst.Bucket, project *db.Project } func (h *UploadAssetHandler) Write(s ssh.Session, entry *sendutils.FileEntry) (string, error) { - user, err := futil.GetUser(s.Context()) + user, err := shared.GetUser(s.Context()) if err != nil { h.Cfg.Logger.Error("user not found in ctx", "err", err.Error()) return "", err @@ -311,7 +309,7 @@ func (h *UploadAssetHandler) Write(s ssh.Session, entry *sendutils.FileEntry) (s return "", err } - featureFlag, err := futil.GetFeatureFlag(s.Context()) + featureFlag, err := shared.GetFeatureFlag(s.Context()) if err != nil { return "", err } @@ -403,7 +401,7 @@ func (h *UploadAssetHandler) Write(s ssh.Session, entry *sendutils.FileEntry) (s } func (h *UploadAssetHandler) Delete(s ssh.Session, entry *sendutils.FileEntry) error { - user, err := futil.GetUser(s.Context()) + user, err := shared.GetUser(s.Context()) if err != nil { h.Cfg.Logger.Error("user not found in ctx", "err", err.Error()) return err diff --git a/filehandlers/imgs/handler.go b/filehandlers/imgs/handler.go index 04ad2c6b..b8354c35 100644 --- a/filehandlers/imgs/handler.go +++ b/filehandlers/imgs/handler.go @@ -14,7 +14,6 @@ import ( "github.com/charmbracelet/ssh" exifremove "github.com/neurosnap/go-exif-remove" "github.com/picosh/pico/db" - "github.com/picosh/pico/filehandlers/util" "github.com/picosh/pico/shared" "github.com/picosh/pico/shared/storage" "github.com/picosh/pobj" @@ -49,7 +48,7 @@ func NewUploadImgHandler(dbpool db.DB, cfg *shared.ConfigSite, storage storage.S } func (h *UploadImgHandler) Read(s ssh.Session, entry *sendutils.FileEntry) (os.FileInfo, sendutils.ReaderAtCloser, error) { - user, err := util.GetUser(s.Context()) + user, err := shared.GetUser(s.Context()) if err != nil { return nil, nil, err } @@ -89,7 +88,7 @@ func (h *UploadImgHandler) Read(s ssh.Session, entry *sendutils.FileEntry) (os.F func (h *UploadImgHandler) Write(s ssh.Session, entry *sendutils.FileEntry) (string, error) { logger := h.Cfg.Logger - user, err := util.GetUser(s.Context()) + user, err := shared.GetUser(s.Context()) if err != nil { logger.Error("could not get user from ctx", "err", err.Error()) return "", err @@ -146,7 +145,7 @@ func (h *UploadImgHandler) Write(s ssh.Session, entry *sendutils.FileEntry) (str logger.Info("unable to find image, continuing", "filename", nextPost.Filename, "err", err.Error()) } - featureFlag, err := util.GetFeatureFlag(s.Context()) + featureFlag, err := shared.GetFeatureFlag(s.Context()) if err != nil { return "", err } @@ -193,7 +192,7 @@ func (h *UploadImgHandler) Write(s ssh.Session, entry *sendutils.FileEntry) (str } func (h *UploadImgHandler) Delete(s ssh.Session, entry *sendutils.FileEntry) error { - user, err := util.GetUser(s.Context()) + user, err := shared.GetUser(s.Context()) if err != nil { return err } diff --git a/filehandlers/imgs/img.go b/filehandlers/imgs/img.go index 730441b2..45c44a86 100644 --- a/filehandlers/imgs/img.go +++ b/filehandlers/imgs/img.go @@ -8,7 +8,6 @@ import ( "github.com/charmbracelet/ssh" "github.com/picosh/pico/db" - "github.com/picosh/pico/filehandlers/util" "github.com/picosh/pico/shared" sendutils "github.com/picosh/send/utils" "github.com/picosh/utils" @@ -81,7 +80,7 @@ func (h *UploadImgHandler) writeImg(s ssh.Session, data *PostMetaData) error { if !valid { return err } - user, err := util.GetUser(s.Context()) + user, err := shared.GetUser(s.Context()) if err != nil { return err } diff --git a/filehandlers/post_handler.go b/filehandlers/post_handler.go index 390f0e5f..63f57c05 100644 --- a/filehandlers/post_handler.go +++ b/filehandlers/post_handler.go @@ -12,7 +12,6 @@ import ( "github.com/charmbracelet/ssh" "github.com/picosh/pico/db" - "github.com/picosh/pico/filehandlers/util" "github.com/picosh/pico/shared" "github.com/picosh/pico/shared/storage" sendutils "github.com/picosh/send/utils" @@ -48,7 +47,7 @@ func NewScpPostHandler(dbpool db.DB, cfg *shared.ConfigSite, hooks ScpFileHooks, } func (h *ScpUploadHandler) Read(s ssh.Session, entry *sendutils.FileEntry) (os.FileInfo, sendutils.ReaderAtCloser, error) { - user, err := util.GetUser(s.Context()) + user, err := shared.GetUser(s.Context()) if err != nil { return nil, nil, err } @@ -77,7 +76,7 @@ func (h *ScpUploadHandler) Read(s ssh.Session, entry *sendutils.FileEntry) (os.F func (h *ScpUploadHandler) Write(s ssh.Session, entry *sendutils.FileEntry) (string, error) { logger := h.Cfg.Logger - user, err := util.GetUser(s.Context()) + user, err := shared.GetUser(s.Context()) if err != nil { logger.Error("error getting user from ctx", "err", err.Error()) return "", err @@ -264,7 +263,7 @@ func (h *ScpUploadHandler) Write(s ssh.Session, entry *sendutils.FileEntry) (str func (h *ScpUploadHandler) Delete(s ssh.Session, entry *sendutils.FileEntry) error { logger := h.Cfg.Logger - user, err := util.GetUser(s.Context()) + user, err := shared.GetUser(s.Context()) if err != nil { logger.Error("could not get user from ctx", "err", err.Error()) return err diff --git a/filehandlers/router_handler.go b/filehandlers/router_handler.go index 76dbbf85..9b7be132 100644 --- a/filehandlers/router_handler.go +++ b/filehandlers/router_handler.go @@ -10,7 +10,6 @@ import ( "github.com/charmbracelet/ssh" "github.com/picosh/pico/db" - "github.com/picosh/pico/filehandlers/util" "github.com/picosh/pico/shared" "github.com/picosh/send/utils" ) @@ -83,7 +82,7 @@ func (r *FileHandlerRouter) Read(s ssh.Session, entry *utils.FileEntry) (os.File func BaseList(s ssh.Session, fpath string, isDir bool, recursive bool, spaces []string, dbpool db.DB) ([]os.FileInfo, error) { var fileList []os.FileInfo - user, err := util.GetUser(s.Context()) + user, err := shared.GetUser(s.Context()) if err != nil { return fileList, err } @@ -154,7 +153,7 @@ func (r *FileHandlerRouter) GetLogger() *slog.Logger { } func (r *FileHandlerRouter) Validate(s ssh.Session) error { - user, err := util.GetUser(s.Context()) + user, err := shared.GetUser(s.Context()) if err != nil { return err } diff --git a/filehandlers/util/pubkey_auth.go b/filehandlers/util/pubkey_auth.go deleted file mode 100644 index aa9850fd..00000000 --- a/filehandlers/util/pubkey_auth.go +++ /dev/null @@ -1,64 +0,0 @@ -package util - -import ( - "log/slog" - - "github.com/charmbracelet/ssh" - "github.com/picosh/pico/db" - "github.com/picosh/pico/shared" - "github.com/picosh/utils" -) - -type SshAuthHandler struct { - DBPool db.DB - Logger *slog.Logger - Cfg *shared.ConfigSite -} - -func NewSshAuthHandler(dbpool db.DB, logger *slog.Logger, cfg *shared.ConfigSite) *SshAuthHandler { - return &SshAuthHandler{ - DBPool: dbpool, - Logger: logger, - Cfg: cfg, - } -} - -func (r *SshAuthHandler) PubkeyAuthHandler(ctx ssh.Context, key ssh.PublicKey) bool { - shared.SetPublicKeyCtx(ctx, key) - - pubkey := utils.KeyForKeyText(key) - - user, err := r.DBPool.FindUserForKey(ctx.User(), pubkey) - if err != nil { - r.Logger.Error( - "could not find user for key", - "key", key, - "err", err, - ) - return false - } - - if user.Name == "" { - r.Logger.Error("username is not set") - return false - } - - ff, _ := r.DBPool.FindFeatureForUser(user.ID, "plus") - // we have free tiers so users might not have a feature flag - // in which case we set sane defaults - if ff == nil { - ff = db.NewFeatureFlag( - user.ID, - "plus", - r.Cfg.MaxSize, - r.Cfg.MaxAssetSize, - ) - } - // this is jank - ff.Data.StorageMax = ff.FindStorageMax(r.Cfg.MaxSize) - ff.Data.FileMax = ff.FindFileMax(r.Cfg.MaxAssetSize) - - SetUser(ctx, user) - SetFeatureFlag(ctx, ff) - return true -} diff --git a/filehandlers/util/util.go b/filehandlers/util/util.go deleted file mode 100644 index f4335b1b..00000000 --- a/filehandlers/util/util.go +++ /dev/null @@ -1,35 +0,0 @@ -package util - -import ( - "fmt" - - "github.com/charmbracelet/ssh" - "github.com/picosh/pico/db" -) - -type ctxUserKey struct{} -type ctxFeatureFlagKey struct{} - -func GetUser(ctx ssh.Context) (*db.User, error) { - user, ok := ctx.Value(ctxUserKey{}).(*db.User) - if !ok { - return user, fmt.Errorf("user not set on `ssh.Context()` for connection") - } - return user, nil -} - -func SetUser(ctx ssh.Context, user *db.User) { - ctx.SetValue(ctxUserKey{}, user) -} - -func GetFeatureFlag(ctx ssh.Context) (*db.FeatureFlag, error) { - ff, ok := ctx.Value(ctxFeatureFlagKey{}).(*db.FeatureFlag) - if !ok || ff.Name == "" { - return ff, fmt.Errorf("feature flag not set on `ssh.Context()` for connection") - } - return ff, nil -} - -func SetFeatureFlag(ctx ssh.Context, ff *db.FeatureFlag) { - ctx.SetValue(ctxFeatureFlagKey{}, ff) -} diff --git a/pastes/ssh.go b/pastes/ssh.go index 0e7795e6..dcf3cdfa 100644 --- a/pastes/ssh.go +++ b/pastes/ssh.go @@ -13,7 +13,7 @@ import ( "github.com/charmbracelet/wish" "github.com/picosh/pico/db/postgres" "github.com/picosh/pico/filehandlers" - "github.com/picosh/pico/filehandlers/util" + "github.com/picosh/pico/shared" "github.com/picosh/pico/shared/storage" wsh "github.com/picosh/pico/wish" "github.com/picosh/send/auth" @@ -81,7 +81,7 @@ func StartSshServer() { "fallback": filehandlers.NewScpPostHandler(dbh, cfg, hooks, st), } handler := filehandlers.NewFileHandlerRouter(cfg, dbh, fileMap) - sshAuth := util.NewSshAuthHandler(dbh, logger, cfg) + sshAuth := shared.NewSshAuthHandler(dbh, logger, cfg) s, err := wish.NewServer( wish.WithAddress(fmt.Sprintf("%s:%s", host, port)), wish.WithHostKeyPath("ssh_data/term_info_ed25519"), diff --git a/pgs/ssh.go b/pgs/ssh.go index b6b142df..57b7e146 100644 --- a/pgs/ssh.go +++ b/pgs/ssh.go @@ -14,7 +14,6 @@ import ( "github.com/picosh/pico/db" "github.com/picosh/pico/db/postgres" uploadassets "github.com/picosh/pico/filehandlers/assets" - "github.com/picosh/pico/filehandlers/util" "github.com/picosh/pico/shared" "github.com/picosh/pico/shared/storage" wsh "github.com/picosh/pico/wish" @@ -97,7 +96,7 @@ func StartSshServer() { HttpHandler: createHttpHandler(apiConfig), } - sshAuth := util.NewSshAuthHandler(dbpool, logger, cfg) + sshAuth := shared.NewSshAuthHandler(dbpool, logger, cfg) s, err := wish.NewServer( wish.WithAddress(fmt.Sprintf("%s:%s", host, port)), wish.WithHostKeyPath("ssh_data/term_info_ed25519"), diff --git a/pgs/tunnel.go b/pgs/tunnel.go index 037783b0..3af42262 100644 --- a/pgs/tunnel.go +++ b/pgs/tunnel.go @@ -38,7 +38,7 @@ func createHttpHandler(apiConfig *shared.ApiConfig) CtxHttpBridge { "impersonating", asUser, ) - pubkey, err := shared.GetPublicKeyCtx(ctx) + pubkey, err := shared.GetPublicKey(ctx) if err != nil { log.Error(err.Error(), "subdomain", subdomain) return http.HandlerFunc(shared.UnauthorizedHandler) @@ -88,7 +88,7 @@ func createHttpHandler(apiConfig *shared.ApiConfig) CtxHttpBridge { requester, _ = dbh.FindUserForName(asUser) } - shared.SetUserCtx(ctx, requester) + shared.SetUser(ctx, requester) if !HasProjectAccess(project, owner, requester, pubkey) { log.Error("no access") @@ -101,7 +101,7 @@ func createHttpHandler(apiConfig *shared.ApiConfig) CtxHttpBridge { // special API endpoint for tunnel users accessing site shared.NewCorsRoute("GET", "/api/current_user", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - user, err := shared.GetUserCtx(ctx) + user, err := shared.GetUser(ctx) if err != nil { logger.Error("could not find user", "err", err.Error()) shared.JSONError(w, err.Error(), http.StatusNotFound) diff --git a/pico/file_handler.go b/pico/file_handler.go index f56578f6..15a1d65c 100644 --- a/pico/file_handler.go +++ b/pico/file_handler.go @@ -14,7 +14,6 @@ import ( "github.com/charmbracelet/ssh" "github.com/charmbracelet/wish" "github.com/picosh/pico/db" - "github.com/picosh/pico/filehandlers/util" "github.com/picosh/pico/shared" sendutils "github.com/picosh/send/utils" "github.com/picosh/utils" @@ -57,7 +56,7 @@ func (h *UploadHandler) Delete(s ssh.Session, entry *sendutils.FileEntry) error } func (h *UploadHandler) Read(s ssh.Session, entry *sendutils.FileEntry) (os.FileInfo, sendutils.ReaderAtCloser, error) { - user, err := util.GetUser(s.Context()) + user, err := shared.GetUser(s.Context()) if err != nil { return nil, nil, err } @@ -81,7 +80,7 @@ func (h *UploadHandler) Read(s ssh.Session, entry *sendutils.FileEntry) (os.File func (h *UploadHandler) List(s ssh.Session, fpath string, isDir bool, recursive bool) ([]os.FileInfo, error) { var fileList []os.FileInfo - user, err := util.GetUser(s.Context()) + user, err := shared.GetUser(s.Context()) if err != nil { return fileList, err } @@ -136,7 +135,7 @@ func (h *UploadHandler) Validate(s ssh.Session) error { return fmt.Errorf("must have username set") } - util.SetUser(s.Context(), user) + shared.SetUser(s.Context(), user) return nil } @@ -277,7 +276,7 @@ func (h *UploadHandler) ProcessAuthorizedKeys(text []byte, logger *slog.Logger, func (h *UploadHandler) Write(s ssh.Session, entry *sendutils.FileEntry) (string, error) { logger := h.Cfg.Logger - user, err := util.GetUser(s.Context()) + user, err := shared.GetUser(s.Context()) if err != nil { logger.Error(err.Error()) return "", err diff --git a/pico/ssh.go b/pico/ssh.go index cd6864ee..6288832c 100644 --- a/pico/ssh.go +++ b/pico/ssh.go @@ -28,7 +28,7 @@ import ( ) func authHandler(ctx ssh.Context, key ssh.PublicKey) bool { - shared.SetPublicKeyCtx(ctx, key) + shared.SetPublicKey(ctx, key) return true } diff --git a/pubsub/api.go b/pipe/api.go similarity index 99% rename from pubsub/api.go rename to pipe/api.go index ad66fcde..60454382 100644 --- a/pubsub/api.go +++ b/pipe/api.go @@ -1,4 +1,4 @@ -package pubsub +package pipe import ( "fmt" diff --git a/pubsub/cli.go b/pipe/cli.go similarity index 99% rename from pubsub/cli.go rename to pipe/cli.go index a3c50382..88c9ff5b 100644 --- a/pubsub/cli.go +++ b/pipe/cli.go @@ -1,4 +1,4 @@ -package pubsub +package pipe import ( "bytes" diff --git a/pubsub/config.go b/pipe/config.go similarity index 53% rename from pubsub/config.go rename to pipe/config.go index dfbbe865..17990d16 100644 --- a/pubsub/config.go +++ b/pipe/config.go @@ -1,4 +1,4 @@ -package pubsub +package pipe import ( "github.com/picosh/pico/shared" @@ -6,17 +6,17 @@ import ( ) func NewConfigSite() *shared.ConfigSite { - domain := utils.GetEnv("PUBSUB_DOMAIN", "pipe.pico.sh") - port := utils.GetEnv("PUBSUB_WEB_PORT", "3000") + domain := utils.GetEnv("PIPE_DOMAIN", "pipe.pico.sh") + port := utils.GetEnv("PIPE_WEB_PORT", "3000") dbURL := utils.GetEnv("DATABASE_URL", "") - protocol := utils.GetEnv("PUBSUB_PROTOCOL", "https") + protocol := utils.GetEnv("PIPE_PROTOCOL", "https") return &shared.ConfigSite{ Domain: domain, Port: port, Protocol: protocol, DbURL: dbURL, - Logger: shared.CreateLogger("pubsub"), - Space: "pubsub", + Logger: shared.CreateLogger("pipe"), + Space: "pipe", } } diff --git a/pubsub/html/base.layout.tmpl b/pipe/html/base.layout.tmpl similarity index 100% rename from pubsub/html/base.layout.tmpl rename to pipe/html/base.layout.tmpl diff --git a/pubsub/html/footer.partial.tmpl b/pipe/html/footer.partial.tmpl similarity index 100% rename from pubsub/html/footer.partial.tmpl rename to pipe/html/footer.partial.tmpl diff --git a/pubsub/html/marketing-footer.partial.tmpl b/pipe/html/marketing-footer.partial.tmpl similarity index 100% rename from pubsub/html/marketing-footer.partial.tmpl rename to pipe/html/marketing-footer.partial.tmpl diff --git a/pubsub/html/marketing.page.tmpl b/pipe/html/marketing.page.tmpl similarity index 100% rename from pubsub/html/marketing.page.tmpl rename to pipe/html/marketing.page.tmpl diff --git a/pubsub/public/anim.js b/pipe/public/anim.js similarity index 100% rename from pubsub/public/anim.js rename to pipe/public/anim.js diff --git a/pubsub/public/apple-touch-icon.png b/pipe/public/apple-touch-icon.png similarity index 100% rename from pubsub/public/apple-touch-icon.png rename to pipe/public/apple-touch-icon.png diff --git a/pubsub/public/favicon-16x16.png b/pipe/public/favicon-16x16.png similarity index 100% rename from pubsub/public/favicon-16x16.png rename to pipe/public/favicon-16x16.png diff --git a/pubsub/public/favicon.ico b/pipe/public/favicon.ico similarity index 100% rename from pubsub/public/favicon.ico rename to pipe/public/favicon.ico diff --git a/pubsub/public/robots.txt b/pipe/public/robots.txt similarity index 100% rename from pubsub/public/robots.txt rename to pipe/public/robots.txt diff --git a/pubsub/ssh.go b/pipe/ssh.go similarity index 79% rename from pubsub/ssh.go rename to pipe/ssh.go index b18f8b6e..7dd3a618 100644 --- a/pubsub/ssh.go +++ b/pipe/ssh.go @@ -1,4 +1,4 @@ -package pubsub +package pipe import ( "context" @@ -12,17 +12,17 @@ import ( "github.com/charmbracelet/promwish" "github.com/charmbracelet/wish" "github.com/picosh/pico/db/postgres" - "github.com/picosh/pico/filehandlers/util" + "github.com/picosh/pico/shared" wsh "github.com/picosh/pico/wish" psub "github.com/picosh/pubsub" "github.com/picosh/utils" ) func StartSshServer() { - host := utils.GetEnv("PUBSUB_HOST", "0.0.0.0") - port := utils.GetEnv("PUBSUB_SSH_PORT", "2222") - portOverride := utils.GetEnv("PUBSUB_SSH_PORT_OVERRIDE", port) - promPort := utils.GetEnv("PUBSUB_PROM_PORT", "9222") + host := utils.GetEnv("PIPE_HOST", "0.0.0.0") + port := utils.GetEnv("PIPE_SSH_PORT", "2222") + portOverride := utils.GetEnv("PIPE_SSH_PORT_OVERRIDE", port) + promPort := utils.GetEnv("PIPE_PROM_PORT", "9222") cfg := NewConfigSite() logger := cfg.Logger dbh := postgres.NewDB(cfg.DbURL, cfg.Logger) @@ -40,14 +40,14 @@ func StartSshServer() { Waiters: syncmap.New[string, []string](), } - sshAuth := util.NewSshAuthHandler(dbh, logger, cfg) + sshAuth := shared.NewSshAuthHandler(dbh, logger, cfg) s, err := wish.NewServer( wish.WithAddress(fmt.Sprintf("%s:%s", host, port)), wish.WithHostKeyPath("ssh_data/term_info_ed25519"), wish.WithPublicKeyAuth(sshAuth.PubkeyAuthHandler), wish.WithMiddleware( WishMiddleware(handler), - promwish.Middleware(fmt.Sprintf("%s:%s", host, promPort), "pubsub-ssh"), + promwish.Middleware(fmt.Sprintf("%s:%s", host, promPort), "pipe-ssh"), wsh.LogMiddleware(logger), ), ) diff --git a/prose/ssh.go b/prose/ssh.go index 3e57c16c..0f0c480e 100644 --- a/prose/ssh.go +++ b/prose/ssh.go @@ -14,7 +14,7 @@ import ( "github.com/picosh/pico/db/postgres" "github.com/picosh/pico/filehandlers" uploadimgs "github.com/picosh/pico/filehandlers/imgs" - "github.com/picosh/pico/filehandlers/util" + "github.com/picosh/pico/shared" "github.com/picosh/pico/shared/storage" wsh "github.com/picosh/pico/wish" "github.com/picosh/send/auth" @@ -92,7 +92,7 @@ func StartSshServer() { DBPool: dbh, } - sshAuth := util.NewSshAuthHandler(dbh, logger, cfg) + sshAuth := shared.NewSshAuthHandler(dbh, logger, cfg) s, err := wish.NewServer( wish.WithAddress(fmt.Sprintf("%s:%s", host, port)), wish.WithHostKeyPath("ssh_data/term_info_ed25519"), diff --git a/shared/ssh.go b/shared/ssh.go index d3dd1ea2..90c55153 100644 --- a/shared/ssh.go +++ b/shared/ssh.go @@ -1,7 +1,105 @@ package shared -import "github.com/charmbracelet/ssh" +import ( + "fmt" + "log/slog" -func PubkeyAuthHandler(ctx ssh.Context, key ssh.PublicKey) bool { + "github.com/charmbracelet/ssh" + "github.com/picosh/pico/db" + "github.com/picosh/utils" +) + +type ctxUserKey struct{} +type ctxFeatureFlagKey struct{} + +func GetUser(ctx ssh.Context) (*db.User, error) { + user, ok := ctx.Value(ctxUserKey{}).(*db.User) + if !ok { + return user, fmt.Errorf("user not set on `ssh.Context()` for connection") + } + return user, nil +} + +func SetUser(ctx ssh.Context, user *db.User) { + ctx.SetValue(ctxUserKey{}, user) +} + +func GetFeatureFlag(ctx ssh.Context) (*db.FeatureFlag, error) { + ff, ok := ctx.Value(ctxFeatureFlagKey{}).(*db.FeatureFlag) + if !ok || ff.Name == "" { + return ff, fmt.Errorf("feature flag not set on `ssh.Context()` for connection") + } + return ff, nil +} + +func SetFeatureFlag(ctx ssh.Context, ff *db.FeatureFlag) { + ctx.SetValue(ctxFeatureFlagKey{}, ff) +} + +type ctxPublicKey struct{} + +func GetPublicKey(ctx ssh.Context) (ssh.PublicKey, error) { + pk, ok := ctx.Value(ctxPublicKey{}).(ssh.PublicKey) + if !ok { + return nil, fmt.Errorf("public key not set on `ssh.Context()` for connection") + } + return pk, nil +} + +func SetPublicKey(ctx ssh.Context, pk ssh.PublicKey) { + ctx.SetValue(ctxPublicKey{}, pk) +} + +type SshAuthHandler struct { + DBPool db.DB + Logger *slog.Logger + Cfg *ConfigSite +} + +func NewSshAuthHandler(dbpool db.DB, logger *slog.Logger, cfg *ConfigSite) *SshAuthHandler { + return &SshAuthHandler{ + DBPool: dbpool, + Logger: logger, + Cfg: cfg, + } +} + +func (r *SshAuthHandler) PubkeyAuthHandler(ctx ssh.Context, key ssh.PublicKey) bool { + SetPublicKey(ctx, key) + + pubkey := utils.KeyForKeyText(key) + + user, err := r.DBPool.FindUserForKey(ctx.User(), pubkey) + if err != nil { + r.Logger.Error( + "could not find user for key", + "key", key, + "err", err, + ) + return false + } + + if user.Name == "" { + r.Logger.Error("username is not set") + return false + } + + ff, _ := r.DBPool.FindFeatureForUser(user.ID, "plus") + // we have free tiers so users might not have a feature flag + // in which case we set sane defaults + if ff == nil { + ff = db.NewFeatureFlag( + user.ID, + "plus", + r.Cfg.MaxSize, + r.Cfg.MaxAssetSize, + ) + } + // this is jank + ff.Data.StorageMax = ff.FindStorageMax(r.Cfg.MaxSize) + ff.Data.FileMax = ff.FindFileMax(r.Cfg.MaxAssetSize) + + SetUser(ctx, user) + SetFeatureFlag(ctx, ff) return true } diff --git a/shared/tunnel.go b/shared/tunnel.go index 189f0c0f..a29b5e40 100644 --- a/shared/tunnel.go +++ b/shared/tunnel.go @@ -1,35 +1 @@ package shared - -import ( - "fmt" - - "github.com/charmbracelet/ssh" - "github.com/picosh/pico/db" -) - -type ctxPublicKey struct{} -type ctxUserKey struct{} - -func GetPublicKeyCtx(ctx ssh.Context) (ssh.PublicKey, error) { - pk, ok := ctx.Value(ctxPublicKey{}).(ssh.PublicKey) - if !ok { - return nil, fmt.Errorf("public key not set on `ssh.Context()` for connection") - } - return pk, nil -} - -func SetPublicKeyCtx(ctx ssh.Context, pk ssh.PublicKey) { - ctx.SetValue(ctxPublicKey{}, pk) -} - -func GetUserCtx(ctx ssh.Context) (*db.User, error) { - pk, ok := ctx.Value(ctxUserKey{}).(*db.User) - if !ok { - return nil, fmt.Errorf("user not set on `ssh.Context()` for connection") - } - return pk, nil -} - -func SetUserCtx(ctx ssh.Context, user *db.User) { - ctx.SetValue(ctxUserKey{}, user) -} diff --git a/ui/api.go b/ui/api.go index 2df5b866..b4bb7625 100644 --- a/ui/api.go +++ b/ui/api.go @@ -47,7 +47,7 @@ func registerUser(apiConfig *shared.ApiConfig, ctx ssh.Context, pubkey ssh.Publi } picoApi := shared.NewUserApi(user, pubkey) - shared.SetUserCtx(ctx, user) + shared.SetUser(ctx, user) err = json.NewEncoder(w).Encode(picoApi) if err != nil { logger.Error("json encoding error", "err", err.Error()) @@ -63,7 +63,7 @@ func getFeatures(apiConfig *shared.ApiConfig, ctx ssh.Context) http.HandlerFunc logger := apiConfig.Cfg.Logger return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - user, _ := shared.GetUserCtx(ctx) + user, _ := shared.GetUser(ctx) if !ensureUser(w, user) { return } @@ -93,7 +93,7 @@ func findOrCreateRssToken(apiConfig *shared.ApiConfig, ctx ssh.Context) http.Han logger := apiConfig.Cfg.Logger return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - user, _ := shared.GetUserCtx(ctx) + user, _ := shared.GetUser(ctx) if !ensureUser(w, user) { return } @@ -132,7 +132,7 @@ func getPublicKeys(httpCtx *shared.ApiConfig, ctx ssh.Context) http.HandlerFunc logger := httpCtx.Cfg.Logger return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - user, _ := shared.GetUserCtx(ctx) + user, _ := shared.GetUser(ctx) if !ensureUser(w, user) { return } @@ -169,7 +169,7 @@ func createPubkey(httpCtx *shared.ApiConfig, ctx ssh.Context) http.HandlerFunc { logger := httpCtx.Cfg.Logger return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - user, _ := shared.GetUserCtx(ctx) + user, _ := shared.GetUser(ctx) if !ensureUser(w, user) { return } @@ -207,7 +207,7 @@ func deletePubkey(httpCtx *shared.ApiConfig, ctx ssh.Context) http.HandlerFunc { logger := httpCtx.Cfg.Logger return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - user, _ := shared.GetUserCtx(ctx) + user, _ := shared.GetUser(ctx) if !ensureUser(w, user) { return } @@ -249,7 +249,7 @@ func patchPubkey(httpCtx *shared.ApiConfig, ctx ssh.Context) http.HandlerFunc { logger := httpCtx.Cfg.Logger return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - user, _ := shared.GetUserCtx(ctx) + user, _ := shared.GetUser(ctx) if !ensureUser(w, user) { return } @@ -303,7 +303,7 @@ func getTokens(httpCtx *shared.ApiConfig, ctx ssh.Context) http.HandlerFunc { logger := httpCtx.Cfg.Logger return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - user, _ := shared.GetUserCtx(ctx) + user, _ := shared.GetUser(ctx) if !ensureUser(w, user) { return } @@ -339,7 +339,7 @@ func createToken(httpCtx *shared.ApiConfig, ctx ssh.Context) http.HandlerFunc { logger := httpCtx.Cfg.Logger return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - user, _ := shared.GetUserCtx(ctx) + user, _ := shared.GetUser(ctx) if !ensureUser(w, user) { return } @@ -379,7 +379,7 @@ func deleteToken(httpCtx *shared.ApiConfig, ctx ssh.Context) http.HandlerFunc { logger := httpCtx.Cfg.Logger return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - user, _ := shared.GetUserCtx(ctx) + user, _ := shared.GetUser(ctx) if !ensureUser(w, user) { return } @@ -425,7 +425,7 @@ func getProjects(httpCtx *shared.ApiConfig, ctx ssh.Context) http.HandlerFunc { logger := httpCtx.Cfg.Logger return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - user, _ := shared.GetUserCtx(ctx) + user, _ := shared.GetUser(ctx) if !ensureUser(w, user) { return } @@ -456,7 +456,7 @@ func getPosts(httpCtx *shared.ApiConfig, ctx ssh.Context, space string) http.Han logger := httpCtx.Cfg.Logger return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - user, _ := shared.GetUserCtx(ctx) + user, _ := shared.GetUser(ctx) if !ensureUser(w, user) { return } @@ -502,7 +502,7 @@ func createFeature(httpCtx *shared.ApiConfig, ctx ssh.Context) http.HandlerFunc logger := httpCtx.Cfg.Logger return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - user, _ := shared.GetUserCtx(ctx) + user, _ := shared.GetUser(ctx) if !ensureUser(w, user) { return } @@ -542,7 +542,7 @@ func deleteFeature(httpCtx *shared.ApiConfig, ctx ssh.Context) http.HandlerFunc logger := httpCtx.Cfg.Logger return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - user, _ := shared.GetUserCtx(ctx) + user, _ := shared.GetUser(ctx) if !ensureUser(w, user) { return } @@ -574,7 +574,7 @@ func getProjectObjects(apiConfig *shared.ApiConfig, ctx ssh.Context) http.Handle storage := apiConfig.Storage return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - user, _ := shared.GetUserCtx(ctx) + user, _ := shared.GetUser(ctx) if !ensureUser(w, user) { return } @@ -616,7 +616,7 @@ func getAnalytics(apiConfig *shared.ApiConfig, ctx ssh.Context, sumtype, bytype, dbpool := apiConfig.Dbpool return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - user, _ := shared.GetUserCtx(ctx) + user, _ := shared.GetUser(ctx) if !ensureUser(w, user) { return } @@ -655,7 +655,7 @@ func getAnalytics(apiConfig *shared.ApiConfig, ctx ssh.Context, sumtype, bytype, func CreateRoutes(apiConfig *shared.ApiConfig, ctx ssh.Context) []shared.Route { logger := apiConfig.Cfg.Logger - pubkey, err := shared.GetPublicKeyCtx(ctx) + pubkey, err := shared.GetPublicKey(ctx) if err != nil { logger.Error("could not get pubkey from ctx", "err", err.Error()) return []shared.Route{}