client

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsConflict

func IsConflict(err error) bool

IsConflict returns true if the error is a 409 Conflict.

func IsForbidden

func IsForbidden(err error) bool

IsForbidden returns true if the error is a 403 Forbidden.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if the error is a 404 Not Found.

Types

type APIError

type APIError struct {
	StatusCode int
	Message    string
	URL        string
}

APIError represents an error returned by the Nginx Proxy Manager API.

func (*APIError) Error

func (e *APIError) Error() string

type AccessList

type AccessList struct {
	ID          int                    `json:"id"`
	CreatedOn   string                 `json:"created_on"`
	ModifiedOn  string                 `json:"modified_on"`
	OwnerUserID int                    `json:"owner_user_id"`
	Name        string                 `json:"name"`
	SatisfyAny  Bool                   `json:"satisfy_any"`
	PassAuth    Bool                   `json:"pass_auth"`
	Items       json.RawMessage        `json:"items"`
	Clients     json.RawMessage        `json:"clients"`
	Meta        map[string]interface{} `json:"meta"`
}

type AuditEntry

type AuditEntry struct {
	ID         int                    `json:"id"`
	CreatedOn  string                 `json:"created_on"`
	ModifiedOn string                 `json:"modified_on"`
	UserID     int                    `json:"user_id"`
	ObjectType string                 `json:"object_type"`
	ObjectID   int                    `json:"object_id"`
	Action     string                 `json:"action"`
	Meta       map[string]interface{} `json:"meta"`
}

type Bool

type Bool bool

Bool is a bool that tolerates the different encodings used by the Nginx Proxy Manager API. NPM releases before v2.12.0 return database boolean columns as JSON numbers (0/1); newer releases return real booleans. Bool accepts true/false, 0/1, "0"/"1"/"true"/"false", and null.

func (*Bool) UnmarshalJSON

func (b *Bool) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Certificate

type Certificate struct {
	ID          int                    `json:"id"`
	CreatedOn   string                 `json:"created_on"`
	ModifiedOn  string                 `json:"modified_on"`
	OwnerUserID int                    `json:"owner_user_id"`
	Provider    string                 `json:"provider"`
	NiceName    string                 `json:"nice_name"`
	DomainNames []string               `json:"domain_names"`
	ExpiresOn   string                 `json:"expires_on"`
	Meta        map[string]interface{} `json:"meta"`
}

type Client

type Client struct {
	BaseURL    string
	HTTPClient *http.Client
	Token      string
	UserAgent  string
}

Client is the Nginx Proxy Manager HTTP API client.

func NewClient

func NewClient(rc *config.ResolvedConfig) (*Client, error)

NewClient creates a new client from a ResolvedConfig. It authenticates with the NPM API to obtain a JWT token.

func NewClientWithToken

func NewClientWithToken(baseURL string, insecure bool) *Client

NewClientWithToken creates a client with a pre-existing JWT token (for login testing).

func (*Client) ChangePassword

func (c *Client) ChangePassword(ctx context.Context, id int, body interface{}) error

func (*Client) CreateAccessList

func (c *Client) CreateAccessList(ctx context.Context, body interface{}) (*AccessList, error)

func (*Client) CreateCertificate

func (c *Client) CreateCertificate(ctx context.Context, body interface{}) (*Certificate, error)

func (*Client) CreateDeadHost

func (c *Client) CreateDeadHost(ctx context.Context, body interface{}) (*DeadHost, error)

func (*Client) CreateProxyHost

func (c *Client) CreateProxyHost(ctx context.Context, body interface{}) (*ProxyHost, error)

func (*Client) CreateRedirectHost

func (c *Client) CreateRedirectHost(ctx context.Context, body interface{}) (*RedirectHost, error)

func (*Client) CreateStream

func (c *Client) CreateStream(ctx context.Context, body interface{}) (*Stream, error)

func (*Client) CreateUser

func (c *Client) CreateUser(ctx context.Context, body interface{}) (*User, error)

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string) (*Response, error)

Delete sends a DELETE request.

func (*Client) DeleteAccessList

func (c *Client) DeleteAccessList(ctx context.Context, id int) error

func (*Client) DeleteCertificate

func (c *Client) DeleteCertificate(ctx context.Context, id int) error

func (*Client) DeleteDeadHost

func (c *Client) DeleteDeadHost(ctx context.Context, id int) error

func (*Client) DeleteProxyHost

func (c *Client) DeleteProxyHost(ctx context.Context, id int) error

func (*Client) DeleteRedirectHost

func (c *Client) DeleteRedirectHost(ctx context.Context, id int) error

func (*Client) DeleteStream

func (c *Client) DeleteStream(ctx context.Context, id int) error

func (*Client) DeleteUser

func (c *Client) DeleteUser(ctx context.Context, id int) error

func (*Client) DisableDeadHost

func (c *Client) DisableDeadHost(ctx context.Context, id int) error

func (*Client) DisableProxyHost

func (c *Client) DisableProxyHost(ctx context.Context, id int) error

func (*Client) DisableRedirectHost

func (c *Client) DisableRedirectHost(ctx context.Context, id int) error

func (*Client) DisableStream

func (c *Client) DisableStream(ctx context.Context, id int) error

func (*Client) EnableDeadHost

func (c *Client) EnableDeadHost(ctx context.Context, id int) error

func (*Client) EnableProxyHost

func (c *Client) EnableProxyHost(ctx context.Context, id int) error

func (*Client) EnableRedirectHost

func (c *Client) EnableRedirectHost(ctx context.Context, id int) error

func (*Client) EnableStream

func (c *Client) EnableStream(ctx context.Context, id int) error

func (*Client) EnableVerboseLogging

func (c *Client) EnableVerboseLogging(w io.Writer)

EnableVerboseLogging wraps the client's HTTP transport with verbose logging.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string) (*Response, error)

Get sends a GET request.

func (*Client) GetAccessList

func (c *Client) GetAccessList(ctx context.Context, id int) (*AccessList, error)

func (*Client) GetAuditEntry

func (c *Client) GetAuditEntry(ctx context.Context, id int) (*AuditEntry, error)

func (*Client) GetCertificate

func (c *Client) GetCertificate(ctx context.Context, id int) (*Certificate, error)

func (*Client) GetDeadHost

func (c *Client) GetDeadHost(ctx context.Context, id int) (*DeadHost, error)

func (*Client) GetHostReport

func (c *Client) GetHostReport(ctx context.Context) (json.RawMessage, error)

func (*Client) GetProxyHost

func (c *Client) GetProxyHost(ctx context.Context, id int) (*ProxyHost, error)

func (*Client) GetRedirectHost

func (c *Client) GetRedirectHost(ctx context.Context, id int) (*RedirectHost, error)

func (*Client) GetSetting

func (c *Client) GetSetting(ctx context.Context, id string) (*Setting, error)

func (*Client) GetStatus

func (c *Client) GetStatus(ctx context.Context) (*Status, error)

func (*Client) GetStream

func (c *Client) GetStream(ctx context.Context, id int) (*Stream, error)

func (*Client) GetUser

func (c *Client) GetUser(ctx context.Context, id string) (*User, error)

func (*Client) ListAccessLists

func (c *Client) ListAccessLists(ctx context.Context) ([]AccessList, error)

func (*Client) ListAuditLog

func (c *Client) ListAuditLog(ctx context.Context) ([]AuditEntry, error)

func (*Client) ListCertificates

func (c *Client) ListCertificates(ctx context.Context) ([]Certificate, error)

func (*Client) ListDNSProviders

func (c *Client) ListDNSProviders(ctx context.Context) (json.RawMessage, error)

func (*Client) ListDeadHosts

func (c *Client) ListDeadHosts(ctx context.Context) ([]DeadHost, error)

func (*Client) ListProxyHosts

func (c *Client) ListProxyHosts(ctx context.Context) ([]ProxyHost, error)

func (*Client) ListRedirectHosts

func (c *Client) ListRedirectHosts(ctx context.Context) ([]RedirectHost, error)

func (*Client) ListSettings

func (c *Client) ListSettings(ctx context.Context) ([]Setting, error)

func (*Client) ListStreams

func (c *Client) ListStreams(ctx context.Context) ([]Stream, error)

func (*Client) ListUsers

func (c *Client) ListUsers(ctx context.Context) ([]User, error)

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body interface{}) (*Response, error)

Post sends a POST request with a JSON body.

func (*Client) PostMultipart

func (c *Client) PostMultipart(ctx context.Context, path string, body io.Reader, contentType string) (*Response, error)

PostMultipart sends a POST request with a raw body and custom content type.

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, body interface{}) (*Response, error)

Put sends a PUT request with a JSON body.

func (*Client) RenewCertificate

func (c *Client) RenewCertificate(ctx context.Context, id int) error

func (*Client) SetUserPermissions

func (c *Client) SetUserPermissions(ctx context.Context, id int, body interface{}) error

func (*Client) TestHTTP

func (c *Client) TestHTTP(ctx context.Context, body interface{}) error

func (*Client) UpdateAccessList

func (c *Client) UpdateAccessList(ctx context.Context, id int, body interface{}) (*AccessList, error)

func (*Client) UpdateDeadHost

func (c *Client) UpdateDeadHost(ctx context.Context, id int, body interface{}) (*DeadHost, error)

func (*Client) UpdateProxyHost

func (c *Client) UpdateProxyHost(ctx context.Context, id int, body interface{}) (*ProxyHost, error)

func (*Client) UpdateRedirectHost

func (c *Client) UpdateRedirectHost(ctx context.Context, id int, body interface{}) (*RedirectHost, error)

func (*Client) UpdateSetting

func (c *Client) UpdateSetting(ctx context.Context, id string, body interface{}) (*Setting, error)

func (*Client) UpdateStream

func (c *Client) UpdateStream(ctx context.Context, id int, body interface{}) (*Stream, error)

func (*Client) UpdateUser

func (c *Client) UpdateUser(ctx context.Context, id int, body interface{}) (*User, error)

type DeadHost

type DeadHost struct {
	ID             int                    `json:"id"`
	CreatedOn      string                 `json:"created_on"`
	ModifiedOn     string                 `json:"modified_on"`
	OwnerUserID    int                    `json:"owner_user_id"`
	DomainNames    []string               `json:"domain_names"`
	CertificateID  interface{}            `json:"certificate_id"`
	SSLForced      Bool                   `json:"ssl_forced"`
	HSTSEnabled    Bool                   `json:"hsts_enabled"`
	HSTSSubdomains Bool                   `json:"hsts_subdomains"`
	HTTP2Support   Bool                   `json:"http2_support"`
	AdvancedConfig string                 `json:"advanced_config"`
	Enabled        Bool                   `json:"enabled"`
	Meta           map[string]interface{} `json:"meta"`
}

type ProxyHost

type ProxyHost struct {
	ID                    int                    `json:"id"`
	CreatedOn             string                 `json:"created_on"`
	ModifiedOn            string                 `json:"modified_on"`
	OwnerUserID           int                    `json:"owner_user_id"`
	DomainNames           []string               `json:"domain_names"`
	ForwardHost           string                 `json:"forward_host"`
	ForwardPort           int                    `json:"forward_port"`
	ForwardScheme         string                 `json:"forward_scheme"`
	AccessListID          int                    `json:"access_list_id"`
	CertificateID         interface{}            `json:"certificate_id"` // int or "new"
	SSLForced             Bool                   `json:"ssl_forced"`
	HSTSEnabled           Bool                   `json:"hsts_enabled"`
	HSTSSubdomains        Bool                   `json:"hsts_subdomains"`
	HTTP2Support          Bool                   `json:"http2_support"`
	BlockExploits         Bool                   `json:"block_exploits"`
	CachingEnabled        Bool                   `json:"caching_enabled"`
	AllowWebsocketUpgrade Bool                   `json:"allow_websocket_upgrade"`
	AdvancedConfig        string                 `json:"advanced_config"`
	Enabled               Bool                   `json:"enabled"`
	Meta                  map[string]interface{} `json:"meta"`
	Locations             []ProxyLocation        `json:"locations"`
}

type ProxyLocation

type ProxyLocation struct {
	Path           string `json:"path"`
	ForwardScheme  string `json:"forward_scheme"`
	ForwardHost    string `json:"forward_host"`
	ForwardPort    int    `json:"forward_port"`
	ForwardPath    string `json:"forward_path"`
	AdvancedConfig string `json:"advanced_config"`
}

type RedirectHost

type RedirectHost struct {
	ID                int                    `json:"id"`
	CreatedOn         string                 `json:"created_on"`
	ModifiedOn        string                 `json:"modified_on"`
	OwnerUserID       int                    `json:"owner_user_id"`
	DomainNames       []string               `json:"domain_names"`
	ForwardScheme     string                 `json:"forward_scheme"`
	ForwardHTTPCode   int                    `json:"forward_http_code"`
	ForwardDomainName string                 `json:"forward_domain_name"`
	PreservePath      Bool                   `json:"preserve_path"`
	CertificateID     interface{}            `json:"certificate_id"`
	SSLForced         Bool                   `json:"ssl_forced"`
	HSTSEnabled       Bool                   `json:"hsts_enabled"`
	HSTSSubdomains    Bool                   `json:"hsts_subdomains"`
	HTTP2Support      Bool                   `json:"http2_support"`
	BlockExploits     Bool                   `json:"block_exploits"`
	AdvancedConfig    string                 `json:"advanced_config"`
	Enabled           Bool                   `json:"enabled"`
	Meta              map[string]interface{} `json:"meta"`
}

type Response

type Response struct {
	HTTPResponse *http.Response
	RequestURL   string
}

Response wraps an http.Response with convenience methods.

func (*Response) Error

func (r *Response) Error() error

Error checks if the response indicates an error and returns an APIError. It always closes the response body to prevent leaks.

func (*Response) JSON

func (r *Response) JSON(v interface{}) error

JSON reads the response body and unmarshals it into v. It also checks for error status codes.

func (*Response) RawBody

func (r *Response) RawBody() ([]byte, error)

RawBody reads and returns the raw response body.

func (*Response) StatusCode

func (r *Response) StatusCode() int

StatusCode returns the HTTP status code.

type Setting

type Setting struct {
	ID    string                 `json:"id"`
	Value interface{}            `json:"value"`
	Meta  map[string]interface{} `json:"meta"`
}

type Status

type Status struct {
	Status  string `json:"status"`
	Version struct {
		Major    int `json:"major"`
		Minor    int `json:"minor"`
		Revision int `json:"revision"`
	} `json:"version"`
	Setup bool `json:"setup"`
}

type Stream

type Stream struct {
	ID             int                    `json:"id"`
	CreatedOn      string                 `json:"created_on"`
	ModifiedOn     string                 `json:"modified_on"`
	OwnerUserID    int                    `json:"owner_user_id"`
	IncomingPort   int                    `json:"incoming_port"`
	ForwardingHost string                 `json:"forwarding_host"`
	ForwardingPort int                    `json:"forwarding_port"`
	TCPForwarding  Bool                   `json:"tcp_forwarding"`
	UDPForwarding  Bool                   `json:"udp_forwarding"`
	CertificateID  interface{}            `json:"certificate_id"`
	Enabled        Bool                   `json:"enabled"`
	Meta           map[string]interface{} `json:"meta"`
}

type User

type User struct {
	ID          int             `json:"id"`
	CreatedOn   string          `json:"created_on"`
	ModifiedOn  string          `json:"modified_on"`
	Name        string          `json:"name"`
	Nickname    string          `json:"nickname"`
	Email       string          `json:"email"`
	Avatar      string          `json:"avatar"`
	IsDisabled  Bool            `json:"is_disabled"`
	Roles       []string        `json:"roles"`
	Permissions json.RawMessage `json:"permissions"`
}

Jump to

Keyboard shortcuts

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