client

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvURL  = "SYNOLOGY_URL"
	EnvUser = "SYNOLOGY_USER"
	EnvPass = "SYNOLOGY_PASSWORD" //nolint:gosec
)
View Source
const DefaultTimeout = 30 * time.Second

Variables

View Source
var ErrBadStatus = errors.New("bad response status")
View Source
var ErrInvalidFileType = errors.New("not a valid FileType")
View Source
var ErrUnknownFileType = errors.New("unknown file type")

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 new HTTP client. Client MUST support cookies. Keep it nil for most cases is a good idea.
	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. Enhanced by some undocumented API from JS.

See https://global.download.synology.com/download/Document/Software/DeveloperGuide/Package/DownloadStation/All/enu/Synology_Download_Station_Web_API.pdf

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
	FileType      FileType  // Optional. Type of File. If not set, it will try automatically detect (which may fail, so better set it).
	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  []ScheduledTask `json:"tasks"`
}

type FileType added in v0.2.0

type FileType string

FileType defines content type. Extracted from 'allowfilters' in JS (download.js) ENUM(unknown = "", auto, torrent, nzb, txt)

const (
	// FileTypeUnknown is a FileType of type unknown.
	FileTypeUnknown FileType = ""
	// FileTypeAuto is a FileType of type auto.
	FileTypeAuto FileType = "auto"
	// FileTypeTorrent is a FileType of type torrent.
	FileTypeTorrent FileType = "torrent"
	// FileTypeNzb is a FileType of type nzb.
	FileTypeNzb FileType = "nzb"
	// FileTypeTxt is a FileType of type txt.
	FileTypeTxt FileType = "txt"
)

func FileTypeValues added in v0.2.0

func FileTypeValues() []FileType

FileTypeValues returns a list of the values for FileType

func ParseFileType added in v0.2.0

func ParseFileType(name string) (FileType, error)

ParseFileType attempts to convert a string to a FileType.

func (FileType) IsValid added in v0.2.0

func (x FileType) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (FileType) String added in v0.2.0

func (x FileType) String() string

String implements the Stringer interface.

func (*FileType) UnmarshalFlag added in v0.2.0

func (ft *FileType) UnmarshalFlag(value string) error

UnmarshalFlag is an adapter for go-flags.

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 ScheduledTask added in v0.2.0

type ScheduledTask 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"`
}

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