client

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 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) DownloadStation added in v0.1.3

func (cl *Client) DownloadStation() *DownloadStation

DownloadStation API

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 DownloadStation added in v0.1.3

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

DownloadStation API

func (*DownloadStation) Create added in v0.1.3

func (ds *DownloadStation) Create(ctx context.Context, task DownloadTask) error

Create download task in DownloadStation based on configuration.

func (*DownloadStation) Download added in v0.1.3

func (ds *DownloadStation) Download(ctx context.Context, destination string, urls ...string) error

Download remote data from HTTP/FTP/magnet/ED2K links or the file path starting with a shared folder. This is simplified version of Create.

func (*DownloadStation) List added in v0.1.3

func (ds *DownloadStation) List(ctx context.Context, offset, limit int) (*DownloadTasks, error)

List all download tasks in NAS. Implies 'detail' feature. Limit -1 means all.

type DownloadTask added in v0.1.3

type DownloadTask struct {
	URL           []string  // HTTP/FTP/magnet/ED2K links or the file path starting with a shared folder.
	File          io.Reader // Optional. File (ex: torrent) uploading from client
	Username      string    // Optional. Login username for remote resource (not NAS!)
	Password      string    // Optional. Login password for remote resource (not NAS!)
	UnzipPassword string    // Optional. Password for unzipping download tasks
	Destination   string    // Optional. Download destination path starting with a shared folder
}

type DownloadTasks added in v0.1.3

type DownloadTasks struct {
	Total  int64 `json:"total"`
	Offset int64 `json:"offset"`
	Tasks  []struct {
		Id         string `json:"id"`
		Type       string `json:"type"`
		Username   string `json:"username"`
		Title      string `json:"title"`
		Size       int64  `json:"size"`
		Status     string `json:"status"`
		Additional struct {
			Detail struct {
				CreateTime  int64  `json:"create_time"`
				Destination string `json:"destination"`
				Priority    string `json:"priority"`
				Uri         string `json:"uri"`
			} `json:"detail"`
		} `json:"additional"`
	} `json:"tasks"`
}

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