client

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvURL  = "SYNOLOGY_URL"
	EnvUser = "SYNOLOGY_USER"
	EnvPass = "SYNOLOGY_PASSWORD" //nolint:gosec
)

Variables

View Source
var ErrBadStatus = errors.New("bad response status")

Functions

This section is empty.

Types

type API

type API struct {
	MaxVersion int64  `json:"maxVersion"`
	Path       string `json:"path"`
}

type CTime

type CTime time.Time

func (*CTime) MarshalJSON

func (ct *CTime) MarshalJSON() ([]byte, error)

func (CTime) Time

func (ct CTime) Time() time.Time

func (*CTime) UnmarshalJSON

func (ct *CTime) UnmarshalJSON(bytes []byte) error

type CertUploadResult

type CertUploadResult struct {
	CertificateID string `json:"id"`
	ServerStatus
}

type Certificate

type Certificate struct {
	ID                 string    `json:"id"`
	Description        string    `json:"desc"`
	IsBroken           bool      `json:"is_broken"`
	IsDefault          bool      `json:"is_default"`
	Issuer             Issuer    `json:"issuer"`
	KeyTypes           string    `json:"key_types"`
	Renewable          bool      `json:"renewable"`
	Services           []Service `json:"services"`
	SignatureAlgorithm string    `json:"signature_algorithm"`
	Subject            Subject   `json:"subject"`
	UserDeletable      bool      `json:"user_deletable"`
	ValidFrom          CTime     `json:"valid_from"`
	ValidTill          CTime     `json:"valid_till"`
}

func (*Certificate) Expired

func (ct *Certificate) Expired() bool

type Client

type Client struct {
	// contains filtered or unexported fields
}

func Default

func Default() *Client

Default client based on env variables.

func New

func New(cfg Config) *Client

New instance of Synology API client.

func (*Client) APIVersion

func (cl *Client) APIVersion(ctx context.Context, apiName string) (API, error)

APIVersion returns max version for specific API. It queries Synology for all APIs and caches result.

func (*Client) DeleteCertByID

func (cl *Client) DeleteCertByID(ctx context.Context, id string) (*ServerStatus, error)

DeleteCertByID deletes certificate by known ID (not name).

func (*Client) ListCerts

func (cl *Client) ListCerts(ctx context.Context) ([]Certificate, error)

func (*Client) Login

func (cl *Client) Login(ctx context.Context) error

Login to Synology and get token. Token will be cached. If token already obtained, API call will not be executed.

func (*Client) UploadCert

func (cl *Client) UploadCert(ctx context.Context, draft NewCertificate) (*CertUploadResult, error)

UploadCert uploads certificate to Synology. Replaces if name (used field description) already exists.

func (*Client) WithClient

func (cl *Client) WithClient(client HTTPClient) *Client

WithClient returns copy of Synology client with custom HTTP client.

type Config

type Config struct {
	Client   HTTPClient // HTTP client to perform requests, default is http.DefaultClient
	User     string     // User name
	Password string     // User password
	URL      string     // Synology url, default is http://localhost:5000
}

func FromEnv

func FromEnv(envFunc func(string) string) Config

FromEnv creates config based on standard environment variables. If envFunc not defined, os.Getenv will be used.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type HTTPClientFunc

type HTTPClientFunc func(req *http.Request) (*http.Response, error)

func (HTTPClientFunc) Do

func (hf HTTPClientFunc) Do(req *http.Request) (*http.Response, error)

type Issuer

type Issuer struct {
	CommonName   string `json:"common_name"`
	Country      string `json:"country"`
	Organization string `json:"organization"`
}

type NewCertificate

type NewCertificate struct {
	Name      string    // unique logical name for certificate
	AsDefault bool      // use certificate as default
	Cert      io.Reader // PEM certificate
	CA        io.Reader // optional
	Key       io.Reader // PEM private key
}

type RemoteError

type RemoteError struct {
	Code int64 `json:"code"`
}

func (*RemoteError) Error

func (e *RemoteError) Error() string

type ServerStatus

type ServerStatus struct {
	ServerRestarted bool `json:"restart_httpd"`
}

type Service

type Service struct {
	DisplayName     string `json:"display_name"`
	DisplayNameI18N string `json:"display_name_i18n,omitempty"`
	IsPkg           bool   `json:"isPkg"`
	Owner           string `json:"owner"`
	Service         string `json:"service"`
	Subscriber      string `json:"subscriber"`
	MultipleCert    bool   `json:"multiple_cert,omitempty"`
	UserSetable     bool   `json:"user_setable,omitempty"`
}

type Subject

type Subject struct {
	CommonName string   `json:"common_name"`
	SubAltName []string `json:"sub_alt_name"`
}

Jump to

Keyboard shortcuts

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