sdump

package module
v0.0.0-...-c406796 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2024 License: MIT Imports: 8 Imported by: 0

README

Sdump

An opensource HTTP request bin built over SSH

Sdump is a HTTP request bin built over SSH. I usually have to google for some 3rd party server or download a binary to inspect certain requests.

Inspect, test and debug any request or webhook from your terminal

sdump TUI

Why?

There is always a new flavor of an online HTTP request bin i have to use every other month. Or sometimes, people have to download Ngrok to get a request bin functionality i.e people have to download or use external services to get a request bin.

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
ssh -p 2222 ssh.sdump.app

Getting started

  • 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
Configuration file

Here is a full config file for all possible values:

## log level
log: debug

cron:
  ## how often should the `delete-http` command run
  ttl: "48h"
  ## Do soft deletes or actually wipe them off the database
  soft_deletes: false

tui:
  ## the color_scheme to use for the request body
  # see https://github.com/alecthomas/chroma/tree/master/styles
  color_scheme: monokai

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 
  # or friends
  allow_list:
    - ./.ssh/id_rsa.pub
    - /Users/lanreadelowo/.ssh/id_rsa.pub
    
  ## keys for the ssh server
  identities:
    - "id_ed25519"

http:
  ## port to run http server on
  port: 4200
  ## what domain name you want to use?
  domain: http://localhost:4200
  ## rate limiting clients
  rate_limit:
    ## limit the number of ingested requests from a specific client
    requests_per_minute: 60
  ## database configuration. postgres essentially
  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 
    log_queries: true

  #  limit the size of jSON request body that can be sent to endpoints
  max_request_body_size: 500

  ## Opentelemetry and tracing config
  otel:
    ## does OTEL endpoint have tls enabled?
    use_tls: true
    ## custom name you want to use to identify the service
    service_name: SDUMP
    ## OTEL Endpoint 
    endpoint: http://localhost:4200
    ## Should we trace all http and DB requests
    is_enabled: false

  ## Prometheus configuration
  prometheus:
    ## protect your /metrics endpoint with basic auth
    ## if provided, password must also be provided too
    username: sdump
    ## basic auth password for your /metrics
    password: sdump

    ## enable /metrics endpoint and metrics collection?
    is_enabled: true
Developers' note

Use ssh-keygen -f .ssh/id_rsa to generate a test ssh key

Deployment to your own server?

I have added a guide here on how I have deployed the public version

Documentation

Index

Constants

View Source
const (
	ErrPlanNotFound     = appError("plan does not exists")
	ErrUserNotFound     = appError("user not found")
	ErrCounterExhausted = appError("no more units left")
)
View Source
const (
	ErrURLEndpointNotFound = appError("endpoint not found")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Counter

type Counter int64

func (*Counter) Add

func (c *Counter) Add()

func (*Counter) Take

func (c *Counter) Take() error

func (*Counter) TakeN

func (c *Counter) TakeN(n int64) error

type DeleteIngestedRequestOptions

type DeleteIngestedRequestOptions struct {
	Before         time.Time
	UseSoftDeletes bool
}

type FindURLOptions

type FindURLOptions struct {
	Reference string
	ID        uuid.UUID
}

type FindUserOptions

type FindUserOptions struct {
	SSHKeyFingerprint string
}

type IngestHTTPRequest

type IngestHTTPRequest struct {
	ID      uuid.UUID         `bun:"type:uuid,default:uuid_generate_v4()" json:"id,omitempty" mapstructure:"id"`
	UrlID   uuid.UUID         `json:"url_id,omitempty"`
	Request RequestDefinition `json:"request,omitempty"`

	CreatedAt time.Time  `bun:",nullzero,notnull,default:current_timestamp" json:"created_at,omitempty" bson:"created_at" mapstructure:"created_at"`
	UpdatedAt time.Time  `bun:",nullzero,notnull,default:current_timestamp" json:"updated_at,omitempty" bson:"updated_at" mapstructure:"updated_at"`
	DeletedAt *time.Time `bun:",soft_delete,nullzero" json:"-,omitempty" bson:"deleted_at" mapstructure:"deleted_at"`

	bun.BaseModel `bun:"table:ingests"`
}

type IngestRepository

type IngestRepository interface {
	Create(context.Context, *IngestHTTPRequest) error
	Delete(context.Context, *DeleteIngestedRequestOptions) error
}

type RequestDefinition

type RequestDefinition struct {
	Body      string      `mapstructure:"body" json:"body,omitempty"`
	Query     string      `json:"query,omitempty"`
	Headers   http.Header `json:"headers,omitempty"`
	IPAddress net.IP      `json:"ip_address,omitempty" bson:"ip_address"`
	Size      int64       `json:"size,omitempty"`
	Method    string      `json:"method,omitempty"`
}

type URLEndpoint

type URLEndpoint struct {
	ID        uuid.UUID `bun:"type:uuid,default:uuid_generate_v4()" json:"id,omitempty"`
	Reference string    `json:"reference,omitempty"`
	IsActive  bool      `json:"is_active,omitempty"`
	UserID    uuid.UUID `json:"user_id,omitempty"`

	Metadata URLEndpointMetadata `json:"metadata,omitempty"`

	CreatedAt time.Time  `bun:",nullzero,notnull,default:current_timestamp" json:"created_at,omitempty" bson:"created_at"`
	UpdatedAt time.Time  `bun:",nullzero,notnull,default:current_timestamp" json:"updated_at,omitempty" bson:"updated_at"`
	DeletedAt *time.Time `bun:",soft_delete,nullzero" json:"-,omitempty" bson:"deleted_at"`

	bun.BaseModel `bun:"table:urls"`
}

func NewURLEndpoint

func NewURLEndpoint(userID uuid.UUID) *URLEndpoint

func (*URLEndpoint) PubChannel

func (u *URLEndpoint) PubChannel() string

type URLEndpointMetadata

type URLEndpointMetadata struct{}

type URLRepository

type URLRepository interface {
	Create(context.Context, *URLEndpoint) error
	Get(context.Context, *FindURLOptions) (*URLEndpoint, error)
	Latest(context.Context, uuid.UUID) (*URLEndpoint, error)
}

type User

type User struct {
	ID             uuid.UUID `bun:"type:uuid,default:uuid_generate_v4()" json:"id,omitempty"`
	SSHFingerPrint string    `json:"ssh_finger_print,omitempty"`
	IsBanned       bool      `json:"is_banned,omitempty"`

	CreatedAt time.Time  `bun:",nullzero,notnull,default:current_timestamp" json:"created_at,omitempty" bson:"created_at"`
	UpdatedAt time.Time  `bun:",nullzero,notnull,default:current_timestamp" json:"updated_at,omitempty" bson:"updated_at"`
	DeletedAt *time.Time `bun:",soft_delete,nullzero" json:"-,omitempty" bson:"deleted_at"`

	bun.BaseModel `bun:"table:users"`
}

type UserRepository

type UserRepository interface {
	Create(context.Context, *User) error
	Find(context.Context, *FindUserOptions) (*User, error)
}

Directories

Path Synopsis
datastore
internal
tui
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
server

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL