client

package
v0.0.0-...-af1e7d0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	URLsPerRequest  = 25
	APIKeyHeader    = "ss-api-key"
	TimestampHeader = "ss-request-timestamp"
	SignatureHeader = "ss-request-signature"
)

Variables

This section is empty.

Functions

func DeleteFileFromPackage

func DeleteFileFromPackage()

def delete_file_from_package(self, file_id): """ Deletes the file with the specified id from the package with the specified ID """ endpoint = "/package/" + self.package_id + "/file/" + file_id url = self.sendsafely.BASE_URL + endpoint headers = make_headers(self.sendsafely.API_SECRET, self.sendsafely.API_KEY, endpoint) try: response = requests.delete(url=url, headers=headers).json() except Exception as e: raise DeleteFileException(details=e) if response["response"] != "SUCCESS": raise DeleteFileException(details=response["message"]) return response

func ProgressNone

func ProgressNone(current uint64, total uint64)

func ProgressPrintBytes

func ProgressPrintBytes(current uint64, total uint64)

func UploadToS3

func UploadToS3(data []byte, URL string) error

UploadToS3 Uploads the file to the specified URL

Types

type AddFileResponse

type AddFileResponse struct {
	ResponseFields
	FileID          string `json:"fileId,omitempty"`
	FileName        string `json:"fileName,omitempty"`
	FileSize        string `json:"fileSize,omitempty"`
	Parts           int    `json:"parts,omitempty"`
	FileUploaded    string `json:"fileUploaded,omitempty"`
	FileUploadedStr string `json:"fileUploadedStr,omitempty"`
	FileVersion     string `json:"fileVersion,omitempty"`
	CreatedByEmail  string `json:"createdByEmail,omitempty"`
	FileState       string `json:"fileState,omitempty"`
}

func (*AddFileResponse) Success

func (r *AddFileResponse) Success() error

type AddRecipientResponse

type AddRecipientResponse struct {
	ApprovalRequired   bool   `json:"approvalRequired,omitempty"`
	CheckForPublicKeys bool   `json:"checkForPublicKeys,omitempty"`
	RecipientID        string `json:"recipientId,omitempty"`
	Email              string `json:"email,omitempty"`
	Phonenumbers       []struct {
		CountryCode         int  `json:"countryCode,omitempty"`
		Phonenumber         int  `json:"phonenumber,omitempty"`
		WasUsedMostRecently bool `json:"wasUsedMostRecently,omitempty"`
	} `json:"phonenumbers,omitempty"`
	FullName       string `json:"fullName,omitempty"`
	SmsAuth        bool   `json:"smsAuth,omitempty"`
	IsPackageOwner bool   `json:"isPackageOwner,omitempty"`
	RoleName       string `json:"roleName,omitempty"`
	ResponseFields
}

func (*AddRecipientResponse) Success

func (r *AddRecipientResponse) Success() error

type Client

type Client struct {
	BaseURL *url.URL
	// contains filtered or unexported fields
}

func NewClient

func NewClient(options Options) (*Client, error)

func (*Client) AddFile

func (c *Client) AddFile(p *Package, filePath string) (*AddFileResponse, error)

AddFile Adds the passed file to the package with the specified ID If bigger than 2.5 MBs, split the file by 2.5 MBs and set parts according to the amount of splits https://bump.sh/doc/sendsafely-rest-api/operation/operation-createfile

func (*Client) AddRecipient

func (c *Client) AddRecipient(p *Package, email string) (*AddRecipientResponse, error)

AddRecipient adds a recipient to this package https://bump.sh/doc/sendsafely-rest-api/operation/operation-addrecipient

func (*Client) CreatPackage

func (c *Client) CreatPackage() (*PackageCreateResponse, error)

CreatPackage Path: api/client.go https://bump.sh/doc/sendsafely-rest-api/operation/operation-createpackage

func (*Client) DeletePackage

func (*Client) DeletePackage()

def delete_package(self): """ Delete this package. """ try: response = delete_request(self.sendsafely, "/package/" + self.package_id) except Exception as e: raise DeletePackageException(details=str(e)) if response["response"] != "SUCCESS": raise DeletePackageException(response["message"])

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

func (*Client) DownloadAndDecryptFile

func (c *Client) DownloadAndDecryptFile(p PackageInfoResponse, fileID, directoryID, downloadDirectory, fileName, clientSecret string) error

func (*Client) EncryptAndUploadFile

func (c *Client) EncryptAndUploadFile(p *Package, filePath string, clientSecret string) (*FileUploadResponse, error)

EncryptAndUploadFile Adds the passed file to the package with the specified ID If bigger than 2621440 Bytes, split the file by 2621440 Bytes and set parts according to the amount of splits

func (*Client) EncryptAndUploadMessage

func (*Client) EncryptAndUploadMessage()

def encrypt_and_upload_message(self, message): """ Adds a message to this package :param message: the message to add :return: the JSON response """ self._block_operation_without_keycode() try: encrypted_message = _encrypt_message(message_to_encrypt=message, server_secret=self.server_secret, client_secret=self.client_secret) body = {'message': encrypted_message} endpoint = "/package/" + self.package_id + "/message/" url = self.sendsafely.BASE_URL + endpoint headers = make_headers(self.sendsafely.API_SECRET, self.sendsafely.API_KEY, endpoint, request_body=json.dumps(body)) response = requests.put(url, headers=headers, json=body).json() except Exception as e: raise UploadMessageException(details=str(e)) if response["response"] != "SUCCESS": raise UploadMessageException(details=response["message"]) return response

func (*Client) Finalize

func (c *Client) Finalize(p *Package, clientSecret string) (*FinalizePackageResponse, error)

Finalize finalizes the package, returns a link, including the keycode https://bump.sh/doc/sendsafely-rest-api/operation/operation-finalizepackage

func (*Client) GetFileInformation

func (c *Client) GetFileInformation(packageId, fileId, directoryId string) (*GetFileInformationResponse, error)

GetFileInformation retrieves information about a file https://bump.sh/doc/sendsafely-rest-api/operation/operation-get-package-parameter-directory-parameter-file-parameter

func (*Client) GetPackageFromURL

func (c *Client) GetPackageFromURL(packageURL string) (*PackageInfoResponse, error)

func (*Client) GetPackageMessage

func (*Client) GetPackageMessage()

def get_package_message(self): """ :returns: The decrypted message """ self._block_operation_without_keycode() try: packageChecksum = _calculate_package_checksum(package_code=self.package_code, keycode=self.client_secret) endpoint = '/package/' + self.package_id + '/message/' + packageChecksum["packageChecksum"] url = self.sendsafely.BASE_URL + endpoint headers = make_headers(self.sendsafely.API_SECRET, self.sendsafely.API_KEY, endpoint) response = requests.get(url, headers=headers).json() message = _decrypt_message(response["message"], server_secret=self.server_secret, client_secret=self.client_secret) return message except Exception as e: raise GetPackageMessageException(details=str(e))

func (*Client) GetUploadUrls

func (c *Client) GetUploadUrls(p *Package, fileID string, part int) (*UploadUrlsResponse, error)

GetUploadUrls Retrieves the S3 upload URLs from SendSafely https://bump.sh/doc/sendsafely-rest-api/operation/operation-getuploadurls

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, URL string, data interface{}) (*http.Request, error)

func (*Client) PackageInfo

func (c *Client) PackageInfo(packageId string) (*PackageInfoResponse, error)

PackageInfo Get a detailed status of a given package https://bump.sh/doc/sendsafely-rest-api/operation/operation-getpackageinformation

func (*Client) PublicKeys

func (c *Client) PublicKeys(p *Package) (*PublicKeysResponse, error)

PublicKeys get the public keys for authorised account https://bump.sh/doc/sendsafely-rest-api/operation/operation-get-package-parameter-public-keys

func (*Client) UpdateFileCompletionStatus

func (c *Client) UpdateFileCompletionStatus(p *Package, ID string, complete bool) (*UpdateFileCompletionStatusResponse, error)

UpdateFileCompletionStatus Sets the file upload status as complete, the server will verify if all segments have been uploaded https://bump.sh/doc/sendsafely-rest-api/operation/operation-uploadcomplete

func (*Client) UpdateRecipient

func (*Client) UpdateRecipient()

def update_recipient_phone_number(self, recipient_id, phone, country_code="US"): """ Update a recipient phone number :param recipient_id: The id of the recipient :param phone: The desired phone number, string in the form "(123) 456-7890" :param country_code: The country code :return: """ sendsafely = self.sendsafely endpoint = "/package/" + self.package_id + "/recipient/" + recipient_id url = sendsafely.BASE_URL + endpoint body = {'phoneNumber': phone, 'countrycode': country_code} headers = make_headers(sendsafely.API_SECRET, sendsafely.API_KEY, endpoint, request_body=json.dumps(body)) try: response = requests.post(url, headers=headers, json=body).json() except Exception as e: raise UpdateRecipientFailedException(details=str(e)) if response["response"] != "SUCCESS": raise UpdateRecipientFailedException(details=response["message"]) return response

func (*Client) UploadKeycodes

func (c *Client) UploadKeycodes(p *Package, publicKeys *PublicKeysResponse, clientSecret string) ([]string, error)

UploadKeycodes Get public keys available for the account

func (*Client) User

func (c *Client) User() (*UserResponse, error)

type DownloadUrlsResponse

type DownloadUrlsResponse struct {
	DownloadUrls []struct {
		Part int    `json:"part"`
		URL  string `json:"url"`
	} `json:"downloadUrls"`
	ResponseFields
}

func (*DownloadUrlsResponse) Success

func (r *DownloadUrlsResponse) Success() error

type File

type File struct {
	FileID          string `json:"fileId"`
	FileName        string `json:"fileName"`
	FileSize        string `json:"fileSize"`
	Parts           int    `json:"parts"`
	FileUploaded    string `json:"fileUploaded"`
	FileUploadedStr string `json:"fileUploadedStr"`
	FileVersion     string `json:"fileVersion"`
	CreatedByEmail  string `json:"createdByEmail"`
}

type FileUploadResponse

type FileUploadResponse struct {
	ResponseFields
}

type FinalizePackageResponse

type FinalizePackageResponse struct {
	ResponseFields
	Approvers  []string `json:"approvers,omitempty"`
	Recipients []string `json:"recipients,omitempty"`
	NeedsLink  bool     `json:"needsLink,omitempty"`
	Response   string   `json:"response,omitempty"`
	Message    string   `json:"message,omitempty"`
}

func (*FinalizePackageResponse) Success

func (r *FinalizePackageResponse) Success() error

type GetFileInformationResponse

type GetFileInformationResponse struct {
	File struct {
		FileID         string `json:"fileId"`
		FileName       string `json:"fileName"`
		FileSize       string `json:"fileSize"`
		CreatedByEmail string `json:"createdByEmail"`
		Uploaded       string `json:"uploaded"`
		UploadedStr    string `json:"uploadedStr"`
		FileParts      int    `json:"fileParts"`
		OldVersions    []struct {
			FileID         string `json:"fileId"`
			FileName       string `json:"fileName"`
			FileSize       string `json:"fileSize"`
			CreatedByEmail string `json:"createdByEmail"`
			Uploaded       string `json:"uploaded"`
			UploadedStr    string `json:"uploadedStr"`
			FileParts      int    `json:"fileParts"`
		} `json:"oldVersions"`
	} `json:"file"`
	ResponseFields
}

func (*GetFileInformationResponse) FileSizeHumanize

func (f *GetFileInformationResponse) FileSizeHumanize() string

func (*GetFileInformationResponse) FileSizeInt

func (f *GetFileInformationResponse) FileSizeInt() uint64

func (*GetFileInformationResponse) Success

func (r *GetFileInformationResponse) Success() error

func (*GetFileInformationResponse) TotalFileParts

func (f *GetFileInformationResponse) TotalFileParts() int

type Options

type Options struct {
	APIKey    string
	APISecret string
	Host      string
}

type Package

type Package struct {
	ID                 string   `json:"packageId"`
	ParentID           string   `json:"packageParentId"`
	UserName           string   `json:"packageUserName"`
	UserID             string   `json:"packageUserId"`
	UpdateTimestampStr string   `json:"packageUpdateTimestampStr"`
	State              string   `json:"packageState"`
	StateStr           string   `json:"packageStateStr"`
	StateColor         string   `json:"packageStateColor"`
	Life               int      `json:"packageLife"`
	UpdateTimestamp    string   `json:"packageUpdateTimestamp"`
	Code               string   `json:"packageCode"`
	Browser            string   `json:"packageBrowser"`
	OS                 string   `json:"packageOS"`
	HasMessage         bool     `json:"packageContainsMessage"`
	Recipients         []string `json:"recipients"`
	RecipientCount     int      `json:"recipientCount"`
	Filenames          []string `json:"filenames"`
	ContactGroups      []string `json:"contactGroups"`
	ServerSecret       string   `json:"serverSecret,omitempty"` //It's package specific TODO: investigate which requests returns it
}

func NewPackage

func NewPackage(resp *PackageCreateResponse) *Package
func (*Package) DownloadLink(response *FinalizePackageResponse, clientSecret string) (string, error)

type PackageCreateResponse

type PackageCreateResponse struct {
	Package
	ResponseFields
}

func (*PackageCreateResponse) Success

func (r *PackageCreateResponse) Success() error

type PackageInfoResponse

type PackageInfoResponse struct {
	PackageID   string `json:"packageId"`
	PackageCode string `json:"packageCode"`
	Recipients  []struct {
		RecipientID        string        `json:"recipientId"`
		Email              string        `json:"email"`
		FullName           string        `json:"fullName"`
		NeedsApproval      bool          `json:"needsApproval"`
		RecipientCode      string        `json:"recipientCode"`
		Confirmations      []interface{} `json:"confirmations"`
		IsPackageOwner     bool          `json:"isPackageOwner"`
		CheckForPublicKeys bool          `json:"checkForPublicKeys"`
		RoleName           string        `json:"roleName"`
	} `json:"recipients"`
	ContactGroups []struct {
		ContactGroupID                  string `json:"contactGroupId"`
		ContactGroupName                string `json:"contactGroupName"`
		ContactGroupIsOrganizationGroup bool   `json:"contactGroupIsOrganizationGroup"`
		Users                           []struct {
			UserEmail string `json:"userEmail"`
			UserID    string `json:"userId"`
		} `json:"users"`
	} `json:"contactGroups"`
	Files            []File        `json:"files"`
	Directories      []interface{} `json:"directories"`
	ApproverList     []interface{} `json:"approverList"`
	NeedsApproval    bool          `json:"needsApproval"`
	State            string        `json:"state"`
	PasswordRequired bool          `json:"passwordRequired"`
	Life             int           `json:"life"`
	Label            string        `json:"label"`
	IsVDR            bool          `json:"isVDR"`
	IsArchived       bool          `json:"isArchived"`
	PackageSender    string        `json:"packageSender"`
	PackageTimestamp string        `json:"packageTimestamp"`
	RootDirectoryID  string        `json:"rootDirectoryId"`
	ResponseFields
	ServerSecret string `json:"serverSecret,omitempty"` //TODO: investigate which requests returns it
}

PackageInfoResponse TODO: use it as a compasition of Pakage instead

func (*PackageInfoResponse) Package

func (r *PackageInfoResponse) Package() Package

func (*PackageInfoResponse) Success

func (r *PackageInfoResponse) Success() error

type PackageMetadata

type PackageMetadata struct {
	Thread      string
	PackageCode string
	KeyCode     string
}

func PackageMetadataFromURL

func PackageMetadataFromURL(u string) (PackageMetadata, error)

PackageMetadataFromURL Extracts PackageMetadata from string URL

type PublicKeysResponse

type PublicKeysResponse struct {
	PublicKeys []struct {
		ID  string `json:"id,omitempty"`
		Key string `json:"key,omitempty"`
	} `json:"publicKeys,omitempty"`
	ResponseFields
}

func (*PublicKeysResponse) Success

func (r *PublicKeysResponse) Success() error

type RequestBuildingError

type RequestBuildingError string

func (*RequestBuildingError) Error

func (e *RequestBuildingError) Error() string

type RequestMakingError

type RequestMakingError string

func (*RequestMakingError) Error

func (e *RequestMakingError) Error() string

type ResponseChecker

type ResponseChecker interface {
	Success() error
}

type ResponseFields

type ResponseFields struct {
	Response string `json:"response"`
	Message  string `json:"message,omitempty"`
}

type UpdateFileCompletionStatusResponse

type UpdateFileCompletionStatusResponse struct {
	ResponseFields
}

func (*UpdateFileCompletionStatusResponse) Success

type UploadKeycodesResponse

type UploadKeycodesResponse struct {
	ResponseFields
}

func (*UploadKeycodesResponse) Success

func (r *UploadKeycodesResponse) Success() error

type UploadUrl

type UploadUrl struct {
	Part int    `json:"part,omitempty"`
	URL  string `json:"url,omitempty"`
}

type UploadUrlsResponse

type UploadUrlsResponse struct {
	UploadUrls []UploadUrl `json:"uploadUrls,omitempty"`
	ResponseFields
}

func (*UploadUrlsResponse) Success

func (r *UploadUrlsResponse) Success() error

type User

type User struct {
	ID          string `json:"id"`
	Email       string `json:"email"`
	ClientKey   string `json:"clientKey"`
	FirstName   string `json:"firstName"`
	LastName    string `json:"lastName"`
	BetaUser    bool   `json:"betaUser"`
	AdminUser   bool   `json:"adminUser"`
	PublicKey   bool   `json:"publicKey"`
	PackageLife int    `json:"packageLife"`
}

type UserResponse

type UserResponse struct {
	User
	ResponseFields
}

func (*UserResponse) Success

func (r *UserResponse) Success() error

Jump to

Keyboard shortcuts

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