Documentation ¶
Index ¶
- Constants
- Variables
- type APIError
- type AuthAppInfo
- type AuthInfo
- type AuthResult
- type ChangeDirInfo
- type ChangeFileInfo
- type Client
- func (c *Client) Auth(ai AuthInfo) (AuthResult, error)
- func (c *Client) ChangeDir(cd ChangeDirInfo) error
- func (c *Client) ChangeFile(cf ChangeFileInfo) error
- func (c *Client) CreateDir(cd CreateDirInfo) error
- func (c *Client) CreateFile(cf CreateFileInfo) error
- func (c *Client) DNSAddService(das DNSAddServiceInfo) error
- func (c *Client) DNSCreateName(name string) error
- func (c *Client) DNSDeleteName(name string) error
- func (c *Client) DNSDeleteService(name, service string) error
- func (c *Client) DNSFile(df DNSFileInfo) (*DNSFile, error)
- func (c *Client) DNSNames() ([]string, error)
- func (c *Client) DNSRegister(dr DNSRegisterInfo) error
- func (c *Client) DNSServiceDir(name, service string) (DirResponse, error)
- func (c *Client) DNSServices(name string) ([]string, error)
- func (c *Client) DeleteDir(dd DeleteDirInfo) error
- func (c *Client) DeleteFile(df DeleteFileInfo) error
- func (c *Client) Do(req *Request) (*http.Response, error)
- func (c *Client) EnsureAuthed(ai AuthInfo) error
- func (c *Client) GetDir(gd GetDirInfo) (DirResponse, error)
- func (c *Client) GetFile(gf GetFileInfo) (io.ReadCloser, error)
- func (c *Client) IsValidToken() (bool, error)
- func (c *Client) MoveDir(md MoveDirInfo) error
- func (c *Client) MoveFile(mf MoveFileInfo) error
- func (c *Client) WriteFile(wf WriteFileInfo) error
- type Conf
- type CreateDirInfo
- type CreateFileInfo
- type DNSAddServiceInfo
- type DNSFile
- type DNSFileInfo
- type DNSRegisterInfo
- type DeleteDirInfo
- type DeleteFileInfo
- type DirInfo
- type DirResponse
- type Dirs
- type FileInfo
- type Files
- type GetDirInfo
- type GetFileInfo
- type MoveDirInfo
- type MoveFileInfo
- type Request
- type RequestBuilder
- type ResponseHandler
- type Time
- type WriteFileInfo
Constants ¶
const (
// AuthPermSafeDriveAccess is a permission to have access to the shared SAFE drive
AuthPermSafeDriveAccess = "SAFE_DRIVE_ACCESS"
)
Variables ¶
var ErrAuthDenied = errors.New("Auth denied")
ErrAuthDenied is the error returned when the user denied access to the application during Client.Auth and Client.EnsureAuthed
Functions ¶
This section is empty.
Types ¶
type APIError ¶
APIError represents a server-side API error on non-2xx responses
func NewAPIError ¶
NewAPIError creates an APIError object from the given HTTP response
type AuthAppInfo ¶
type AuthAppInfo struct { // The name of the app that will appear in the SAFE launcher Name string `json:"name"` // The ID of the app ID string `json:"id"` // The app version Version string `json:"version"` // The app vendor name Vendor string `json:"vendor"` }
AuthAppInfo is the app identification detail
type AuthInfo ¶
type AuthInfo struct { // This is the required app information App AuthAppInfo `json:"app"` // Set of permissions that this app will register with. See AuthPerm* constants. Permissions []string `json:"permissions"` // The public key to use when authorizing. Leave blank to generate at runtime. PublicKey []byte `json:"publicKey"` // The private key to use when authorizing. Leave blank to generate at runtime. PrivateKey []byte `json:"-"` // The nonce to use when authorizing. Leave blank to generate at runtime. Nonce []byte `json:"nonce"` }
AuthInfo is used by Client.Auth and Client.EnsureAuthed to authenticate an app
type AuthResult ¶
type AuthResult struct { // The original request Request AuthInfo // The JSON web token for this app to use Token string SharedKey []byte // The nonce to use when encrypting/decrypting to/from the SAFE launcher Nonce []byte }
AuthResult is the result of a successful authentication request
type ChangeDirInfo ¶
type ChangeDirInfo struct { // The path to change DirPath string `json:"-"` Shared bool `json:"-"` // The name to change it to. If Metadata is not set, this must be set. NewName string `json:"name,omitempty"` // The metadata to set. If NewName is not set, this must be set. Metadata string `json:"metadata,omitempty"` }
ChangeDirInfo are parameters to ChangeDir. One of NewName or Metadata must be present.
type ChangeFileInfo ¶
type ChangeFileInfo struct { FilePath string `json:"-"` NewName string `json:"name,omitempty"` Metadata string `json:"metadata,omitempty"` }
ChangeFileInfo are parameters for Client.ChangeFile. This is currently undocumented/unsupported. See https://maidsafe.atlassian.net/browse/CS-60 for more info.
type Client ¶
type Client struct { // The configuration for the client including auth and encryption information Conf Conf // The HTTP client to use. This must be present. NewClient populates this with http.DefaultClient by default. HTTPClient *http.Client // A custom request builder. If not set it will default to the normal builder. NewClient populates this with the // default value so developers can override this value as a proxy and call the existing one if necessary. RequestBuilder RequestBuilder // A custom response handler. If not set it will default to the normal builder. NewClient populates this with // the default value so developers can override this value as a proxy and call the existing one if necessary. ResponseHandler ResponseHandler // If present, debug logs will be logged here Logger *log.Logger }
Client for accessing SAFE. While this can be constructed manually, NewClient populates some of these values.
func (*Client) Auth ¶
func (c *Client) Auth(ai AuthInfo) (AuthResult, error)
Auth authenticates with the SAFE launcher which prompts the user to accept it. If the AuthInfo.PublicKey is not provided, it will be generated automatically along with the PrivateKey and Nonce. See https://maidsafe.readme.io/docs/auth for more info.
func (*Client) ChangeDir ¶
func (c *Client) ChangeDir(cd ChangeDirInfo) error
ChangeDir changes a directory's name, metadata, or both. There is no documentation for this. See https://maidsafe.atlassian.net/browse/CS-60 for more information.
func (*Client) ChangeFile ¶
func (c *Client) ChangeFile(cf ChangeFileInfo) error
ChangeFile changes the file name, metadata, or both. This is currently undocumented/unsupported. See https://maidsafe.atlassian.net/browse/CS-60 for more info.
func (*Client) CreateDir ¶
func (c *Client) CreateDir(cd CreateDirInfo) error
CreateDir creates a directory. See https://maidsafe.readme.io/docs/nfs-create-directory for more info.
func (*Client) CreateFile ¶
func (c *Client) CreateFile(cf CreateFileInfo) error
CreateFile creates a file. See https://maidsafe.readme.io/docs/nfsfile for more information.
func (*Client) DNSAddService ¶
func (c *Client) DNSAddService(das DNSAddServiceInfo) error
DNSAddService registers a service and directory to an existing DNS top level name. This differs from DNSRegister because it expects the name to already exist. This is not documented, see https://maidsafe.atlassian.net/browse/CS-60 for more info.
func (*Client) DNSCreateName ¶
DNSCreateName creates a new top level DNS name for this account. See https://maidsafe.readme.io/docs/dns-create-long-name for more info.
func (*Client) DNSDeleteName ¶
DNSDeleteName deletes a top-level DNS name
func (*Client) DNSDeleteService ¶
DNSDeleteService deletes a service from the given DNS name
func (*Client) DNSFile ¶
func (c *Client) DNSFile(df DNSFileInfo) (*DNSFile, error)
DNSFile fetches a public file from DNS. See https://maidsafe.readme.io/docs/dns-get-file-unauth for more information.
func (*Client) DNSNames ¶
DNSNames gets all top level DNS names on the account. See https://maidsafe.readme.io/docs/dns-list-long-names for more info.
func (*Client) DNSRegister ¶
func (c *Client) DNSRegister(dr DNSRegisterInfo) error
DNSRegister registers a DNS top level name, service, and directory. This differs from DNSAddService because it internally calls DNSCreateName. See https://maidsafe.readme.io/docs/dns-register-service for more info.
func (*Client) DNSServiceDir ¶
func (c *Client) DNSServiceDir(name, service string) (DirResponse, error)
DNSServiceDir gets directory detail for the given DNS name and service on the account. See https://maidsafe.readme.io/docs/dns-get-home-dir for more info.
func (*Client) DNSServices ¶
DNSServices gets all DNS services on the account for the given name. See https://maidsafe.readme.io/docs/dns-list-services for more information.
func (*Client) DeleteDir ¶
func (c *Client) DeleteDir(dd DeleteDirInfo) error
DeleteDir deletes a directory. See https://maidsafe.readme.io/docs/nfs-delete-directory for more info.
func (*Client) DeleteFile ¶
func (c *Client) DeleteFile(df DeleteFileInfo) error
DeleteFile deletes a file. See https://maidsafe.readme.io/docs/nfs-delete-file for more info.
func (*Client) Do ¶
Do makes the HTTP call to SAFE. Errors can be anything during the request or any non-2xx response.
func (*Client) EnsureAuthed ¶
EnsureAuthed checks Client.IsValidToken and if false runs Client.Auth after clearing existing information from Client.Conf. It autopopulates Client.Conf.Token, Client.Conf.SharedKey, and Client.Conf.Nonce if the current Client.Conf is not valid.
func (*Client) GetDir ¶
func (c *Client) GetDir(gd GetDirInfo) (DirResponse, error)
GetDir gets directory information. See https://maidsafe.readme.io/docs/nfs-get-directory for more info.
func (*Client) GetFile ¶
func (c *Client) GetFile(gf GetFileInfo) (io.ReadCloser, error)
GetFile obtains a file's contents. See https://maidsafe.readme.io/docs/nfs-get-file for more info.
func (*Client) IsValidToken ¶
IsValidToken checks if the current Client.Conf information is valid to access the API. See https://maidsafe.readme.io/docs/is-token-valid for more information.
func (*Client) MoveDir ¶
func (c *Client) MoveDir(md MoveDirInfo) error
MoveDir moves a directory. This is currently undocumented/unsupported. See https://maidsafe.atlassian.net/browse/CS-60 for more info.
func (*Client) MoveFile ¶
func (c *Client) MoveFile(mf MoveFileInfo) error
MoveFile moves a file. This is currently undocumented/unsupported. See https://maidsafe.atlassian.net/browse/CS-60 for more info.
func (*Client) WriteFile ¶
func (c *Client) WriteFile(wf WriteFileInfo) error
WriteFile writes a file. See https://maidsafe.readme.io/docs/nfs-update-file-content for more info.
type Conf ¶
type Conf struct { // The LauncherBaseURL. If this is not present it is defaulted to http://localhost:8100/ in NewClient. LauncherBaseURL string `json:"launcherServer,omitempty"` // The JSON web token to use to authenticate on authenticated calls. This is required for authenticated calls. // It is autopopulated by Client.EnsureAuthed if invalid. Token string `json:"token,omitempty"` // Client.EnsureAuthed if invalid. SharedKey []byte `json:"sharedKey,omitempty"` // The nonce for encryption/decryption. This is required for encrypted calls. It is autopopulated by // Client.EnsureAuthed if invalid. Nonce []byte `json:"nonce,omitempty"` }
Conf is the configuration for a client. It is built to marshal to JSON which can be stored in a file for reuse.
type CreateDirInfo ¶
type CreateDirInfo struct { // The path to create DirPath string `json:"dirPath"` // Whether the directory is private Private bool `json:"isPrivate"` // Whether the directory is versioned Versioned bool `json:"isVersioned"` // Metadata to store with the directory Metadata string `json:"metadata"` Shared bool `json:"isPathShared"` }
CreateDirInfo are parameters for Client.CreateDir
type CreateFileInfo ¶
type CreateFileInfo struct { // The path to create FilePath string `json:"filePath"` Shared bool `json:"isPathShared"` // Metadata to store with the file Metadata string `json:"metadata"` }
CreateFileInfo are parameters for Client.CreateFile
type DNSAddServiceInfo ¶
type DNSAddServiceInfo struct { // The DNS name to add the service to Name string `json:"longName"` // The service name to add ServiceName string `json:"serviceName"` // The directory to assign HomeDirPath string `json:"serviceHomeDirPath"` Shared bool `json:"isPathShared"` }
DNSAddServiceInfo is returned from the Client.DNSAddService
type DNSFile ¶
type DNSFile struct { // File info about the DNS file Info FileInfo // The mime type of the content from SAFE ContentType string // The contents of the file Body io.ReadCloser }
DNSFile is returned from the Client.DNSFile function
type DNSFileInfo ¶
type DNSFileInfo struct { // The DNS name this file is at Name string // The service name this file is at Service string // The path to the file FilePath string // The offset to read from Offset int64 // The number of bytes to read. 0 means no limit. Length int64 }
DNSFileInfo are parameters for Client.DNSFile
type DNSRegisterInfo ¶
type DNSRegisterInfo struct { // The DNS name to register Name string `json:"longName"` // The service name to register ServiceName string `json:"serviceName"` // The home directory path to register HomeDirPath string `json:"serviceHomeDirPath"` Shared bool `json:"isPathShared"` }
DNSRegisterInfo are parameters for Client.DNSRegister
type DeleteDirInfo ¶
DeleteDirInfo are parameters for Client.DeleteDir
type DeleteFileInfo ¶
DeleteFileInfo are parameters for Client.DeleteFile
type DirInfo ¶
type DirInfo struct { Name string `json:"name"` Private bool `json:"isPrivate"` Versioned bool `json:"isVersioned"` CreatedOn Time `json:"createdOn"` ModifiedOn Time `json:"modifiedOn"` Metadata string `json:"metadata"` }
DirInfo is information about a single directory
type DirResponse ¶
type DirResponse struct { // Info about the directory requested Info DirInfo `json:"info"` // All files inside the directory Files Files `json:"files"` // All sub directories in the directory SubDirs Dirs `json:"subDirectories"` }
DirResponse is a response from directory commands for a Client
type FileInfo ¶
type FileInfo struct { Name string `json:"name"` Size int64 `json:"size"` CreatedOn Time `json:"createdOn"` ModifiedOn Time `json:"modifiedOn"` Metadata string `json:"metadata"` }
FileInfo is information about a single directory
type GetDirInfo ¶
GetDirInfo are parameters for Client.GetDir
type GetFileInfo ¶
type GetFileInfo struct { // The path to get FilePath string Shared bool // The byte offset to start reading at Offset int64 // The amount of bytes to read. If the value is 0 then there is no length constraint Length int64 }
GetFileInfo are parameters for Client.GetFile
type MoveDirInfo ¶
type MoveDirInfo struct { SrcPath string `json:"srcPath"` DestPath string `json:"destPath"` RetainSource bool `json:"retainSource"` }
MoveDirInfo are parameters to MoveDir. This is currently undocumented/unsupported. See https://maidsafe.atlassian.net/browse/CS-60 for more info.
type MoveFileInfo ¶
type MoveFileInfo struct { SrcPath string `json:"srcPath"` DestPath string `json:"destPath"` RetainSource bool `json:"retainSource"` }
MoveFileInfo are parameters for Client.MoveFile. This is currently undocumented/unsupported. See https://maidsafe.atlassian.net/browse/CS-60 for more info.
type Request ¶
type Request struct { // The URL path to call not including the host information. Note, if there are things inside of the path that // should be URL encoded, they must be encoded before calling this. If this value does not start with a slash, // it is treated as though it does. Path string // The HTTP method to use for the call Method string // If not nil, this value will be JSON marshalled into the body overriding any value that may be in RawBody JSONBody interface{} // If not nil and JSONBody is nil, this will be used as the HTTP request body. NOTE: an empty array is still // considered a body of content length 0. RawBody []byte // The query values to send in the request Query url.Values // If true, the request body and query params will NOT be encrypted and the response body will NOT be decrypted DoNotEncrypt bool // If not nil, successful responses will JSON-unmarshalled into this object JSONResponse interface{} // If true, the request will not be authenticated with Client.Conf.Token DoNotAuth bool }
Request is a representation of a request to SAFE
type RequestBuilder ¶
RequestBuilder is a function type that is used to build an HTTP request from a client request.
type ResponseHandler ¶
type ResponseHandler func(c *Client, resp *http.Response, decrypt bool, jsonResponse interface{}) error
ResponseHandler is a function type that is used to alter an HTTP response as needed. If decrypt is true, implementers are expected to decrypt the response body and place it back on the response. If jsonResponse is not nil, implementers are expected to unmarshal the JSON into the object.
type WriteFileInfo ¶
type WriteFileInfo struct { // The path to write to FilePath string Shared bool // The contents to write Contents io.ReadCloser // The byte offset in the file to start writing Offset int64 }
WriteFileInfo are parameters for Client.WriteFile