moibit

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2022 License: Apache-2.0 Imports: 5 Imported by: 1

README

go-moibit-client

Golang Client Library for interacting with MOIBit's Decentralized Storage API's

Types

Methods for File/Directory stats

Methods for Read/Write operations

Methods for App/Dev details

Client

Client provides various methods to interact with MOIBit.

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

App Descriptor

App Descriptors holds metadata of an app registered with MOIBit.

type AppDescriptor struct {
    IsActive  bool `json:"isActive"`
	IsRemoved bool `json:"isRemoved"`
    
    // app meta data
	AppID          string      `json:"appID"`
	AppName        string      `json:"appName"`
	AppDescription string      `json:"appDescription"`
	EndUsers       interface{} `json:"endUsers"`
    
    // network meta data
	NetworkID   string `json:"networkID"`
	NetworkName string `json:"networkName"`
    
	Replication    int         `json:"replication"`
	CanEncrypt     interface{} `json:"canEncrypt"`
	EncryptionType int         `json:"encryptionType"`
	CustomKey      interface{} `json:"customKey"`
	RecoveryTime   int64       `json:"recoveryTime"`
}

File Descriptor

File Descriptor holds metadata of a file.

type FileDescriptor struct {
	FileVersionDescriptor // inlined JSON

	Path        string `json:"path"`
	IsDirectory bool   `json:"isDir"`
	Directory   string `json:"directory"`
	NodeAddress string `json:"nodeAddress"`
}

Dev Descriptor

Dev Descriptor holds metadata of a developer.

type DevDescriptor struct {
	Active bool        `json:"active"`
	Key    interface{} `json:"key"`

	Name  string `json:"name"`
	Email string `json:"email"`

	Apps []struct {
		IsActive  bool `json:"isActive"`
		IsRemoved bool `json:"isRemoved"`

		AppID   string `json:"appID"`
		AppName string `json:"appName"`

		Replication    int    `json:"replication"`
		EncryptionType int    `json:"encryptionType"`
		EncryptionAlgo string `json:"encryptionAlgo"`
		RecoveryTime   int64  `json:"recoveryTime"`

		NetworkID   string `json:"networkID"`
		NetworkName string `json:"networkName"`
	} `json:"apps"`

	Networks   interface{} `json:"networks"`
	DevPubKey  interface{} `json:"devPubKey"`
	Encryption interface{} `json:"encryption"`

	IsActive         bool `json:"isActive"`
	Creditcard       bool `json:"creditcard"`
	Canencrypt       bool `json:"canencrypt"`
	Canreplicate     bool `json:"canreplicate"`
	Cancreatenetwork bool `json:"cancreatenetwork"`

	Maxstorage           int    `json:"maxstorage"`
	ReplicationFactor    int    `json:"replicationFactor"`
	Plan                 int    `json:"plan"`
	StripeCustomerID     string `json:"stripeCustomerID"`
	StripeSubscriptionID string `json:"stripeSubscriptionID"`

	NoOfPremiumNodes int         `json:"noOfPremiumNodes"`
	NoOfApps         int         `json:"noOfApps"`
	PremiumNodesList interface{} `json:"premiumNodesList"`

	Credit               int  `json:"credit"`
	FreeTrial            bool `json:"freeTrial"`
	AnnualSubscription   bool `json:"AnnualSubscription"`
	FreeTrialJoiningDate int  `json:"freeTrialJoiningDate"`
}

ListFiles(path string) ([]FileDescriptor, error)

ListFiles lists the files for a specified path,The files are returned as a slice of FileDescriptor objects. An error is returned if the API fails or the client cannot authenticate with MOIBit.

func (client *Client) ListFiles(path string) ([]FileDescriptor, error)

FileStatus(path string) (FileDescriptor, error)

FileStatus returns the status of a file at a specified path, The returned FileStatus is empty if the file does not exist, which can be checked with Exists(). An error is returned if the API fails or the client cannot authenticate with MOIBit.

func (client *Client) ListFiles(path string) ([]FileDescriptor, error)

FileVersions(path string) ([]FileVersionDescriptor, error)

FileVersions returns the version information of the file at the given path. Returns a slice of FileVersionDescriptor objects, one for each version.

func (client *Client) FileVersions(path string) ([]FileVersionDescriptor, error)

ReadFile(path string, version int) ([]byte, error)

ReadFile reads a file from MOIBit at the given path for the given version. Returns the []byte data of the file and an error.

func (client *Client) ReadFile(path string, version int) ([]byte, error)

WriteFile(data []byte, name string, opts ...WriteOption) (FileDescriptor, error)

WriteFile writes a given file to MOIBit. Accepts the file data as raw bytes and the file name. It also accepts a variadic number of WriteOption to modify the write request. Returns a FileDescriptor (and error) containing the status of the file after successful write.

func (client *Client) WriteFile(data []byte, name string, opts ...WriteOption) (FileDescriptor, error) 

RemoveFile(path string, version int, opts ...RemoveOption) error

RemoveFile removes a file at the given path of the specified version. It also accepts a variadic number of RemoveOption to modify the remove request.

  • To remove directories, use the path to the directory and pass the RemoveDirectory option.
  • To restore files, pass the file path and version to restore with the PerformRestore option. This call is used to create and assign an activity to a user, this call return an error in the following cases.
func (client *Client) RemoveFile(path string, version int, opts ...RemoveOption) error 

MakeDirectory(path string) error

MakeDirectory creates a new directory at the given path which can than be used for storing files.

func (client *Client) MakeDirectory(path string) error 

AppDetails() (AppDescriptor, error) {

AppDetails returns the details of the application the client is configured for as a AppDescriptor object

func (client *Client) AppDetails() (AppDescriptor, error)

DevDetails() (DevDescriptor, error) {

DevDetails returns the details of developer user the client is configured for as a DevDescriptor object

func (client *Client) DevDetails() (DevDescriptor, error) 

Documentation

Index

Constants

View Source
const (
	// DefaultNetworkID represents the network ID of the default MOIBit Network.
	// Can be overridden using the NetworkID() option while constructing the client
	DefaultNetworkID = "12D3KooWSMAGyrB9TG45AAWaQNJmMdfJpnLQ5e1XM21hkm3FokHk"

	// DefaultBaseURL represents the default base URL for the MOIBit Client.
	// It is the primary production service endpoint. API endpoints are built on this base URL
	DefaultBaseURL = "https://api.moinet.io/moibit/v1"
)

Variables

This section is empty.

Functions

func Authenticate

func Authenticate(client *Client) (string, error)

Authenticate attempts to authenticate a set of credentials with MOIBit. Accepts the nonce and signature of the developer and returns the public or an error if either the authentication routine fails or if the credentials are invalid.

Types

type AppDescriptor

type AppDescriptor struct {
	IsActive  bool `json:"isActive"`
	IsRemoved bool `json:"isRemoved"`

	AppID          string      `json:"appID"`
	AppName        string      `json:"appName"`
	AppDescription string      `json:"appDescription"`
	EndUsers       interface{} `json:"endUsers"`

	NetworkID   string `json:"networkID"`
	NetworkName string `json:"networkName"`

	Replication    int         `json:"replication"`
	CanEncrypt     interface{} `json:"canEncrypt"`
	EncryptionType int         `json:"encryptionType"`
	CustomKey      interface{} `json:"customKey"`
	RecoveryTime   int64       `json:"recoveryTime"`
}

AppDescriptor describes the status of an application

type Client

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

Client represents a MOIBit API Client

func NewClient

func NewClient(signature, nonce string, opts ...ClientOption) (*Client, error)

NewClient creates a new MOIBit API Client for the given signature and nonce Accepts a variadic number of ClientOption arguments to set the App ID, Network ID or Base URL Uses the DefaultNetworkID, DefaultBaseURL and no App ID, by default.

func (*Client) AppDetails

func (client *Client) AppDetails() (AppDescriptor, error)

AppDetails returns the details of the application the client is configured for as a AppDescriptor object

func (*Client) DevDetails

func (client *Client) DevDetails() (DevDescriptor, error)

DevDetails returns the details of developer user the client is configured for as a DevDescriptor object

func (*Client) FileStatus

func (client *Client) FileStatus(path string) (FileDescriptor, error)

FileStatus returns the status of a file at a specified path. The returned FileStatus is empty if the file does not exist, which can be checked with Exists(). An error is returned if the API fails or the client cannot authenticate with MOIBit.

func (*Client) FileVersions

func (client *Client) FileVersions(path string) ([]FileVersionDescriptor, error)

FileVersions returns the version information of the file at the given path. Returns a slice of FileVersionDescriptor objects, one for each version.

func (*Client) ListFiles

func (client *Client) ListFiles(path string) ([]FileDescriptor, error)

ListFiles lists the files for a specified path. The files are returned as a slice of FileDescriptor objects. An error is returned if the API fails or the client cannot authenticate with MOIBit.

func (*Client) MakeDirectory

func (client *Client) MakeDirectory(path string) error

MakeDirectory creates a new directory at the given path which can than be used for storing files.

func (*Client) ReadFile

func (client *Client) ReadFile(path string, version int) ([]byte, error)

ReadFile reads a file from MOIBit at the given path for the given version. Returns the []byte data of the file and an error.

func (*Client) RemoveFile

func (client *Client) RemoveFile(path string, version int, opts ...RemoveOption) error

RemoveFile removes a file at the given path of the specified version. It also accepts a variadic number of RemoveOption to modify the remove request.

  • To remove directories, use the path to the directory and pass the RemoveDirectory option.
  • To restore files, pass the file path and version to restore with the PerformRestore option.

func (*Client) WriteFile

func (client *Client) WriteFile(data []byte, name string, opts ...WriteOption) (FileDescriptor, error)

WriteFile writes a given file to MOIBit. Accepts the file data as raw bytes and the file name. It also accepts a variadic number of WriteOption to modify the write request. Returns a FileDescriptor (and error) containing the status of the file after successful write.

type ClientOption

type ClientOption func(*Client) error

ClientOption is a MOIBit client option provided to the Client Constructor

func AppID

func AppID(app string) ClientOption

AppID returns ClientOption that can be used to set the App ID for a Client

func BaseURL added in v0.0.2

func BaseURL(url string) ClientOption

BaseURL returns a ClientOption that can be used to set a Base URL for a Client The Base URL can be used to have the Client dial a local development instance or custom network.

func NetworkID

func NetworkID(net string) ClientOption

NetworkID returns a ClientOption that can be used to set the Network ID for a Client

type DevDescriptor

type DevDescriptor struct {
	Active bool        `json:"active"`
	Key    interface{} `json:"key"`

	Name  string `json:"name"`
	Email string `json:"email"`

	Apps []struct {
		IsActive  bool `json:"isActive"`
		IsRemoved bool `json:"isRemoved"`

		AppID   string `json:"appID"`
		AppName string `json:"appName"`

		Replication    int    `json:"replication"`
		EncryptionType int    `json:"encryptionType"`
		EncryptionAlgo string `json:"encryptionAlgo"`
		RecoveryTime   int64  `json:"recoveryTime"`

		NetworkID   string `json:"networkID"`
		NetworkName string `json:"networkName"`
	} `json:"apps"`

	Networks   interface{} `json:"networks"`
	DevPubKey  interface{} `json:"devPubKey"`
	Encryption interface{} `json:"encryption"`

	IsActive         bool `json:"isActive"`
	Creditcard       bool `json:"creditcard"`
	Canencrypt       bool `json:"canencrypt"`
	Canreplicate     bool `json:"canreplicate"`
	Cancreatenetwork bool `json:"cancreatenetwork"`

	Maxstorage           int    `json:"maxstorage"`
	ReplicationFactor    int    `json:"replicationFactor"`
	Plan                 int    `json:"plan"`
	StripeCustomerID     string `json:"stripeCustomerID"`
	StripeSubscriptionID string `json:"stripeSubscriptionID"`

	NoOfPremiumNodes int         `json:"noOfPremiumNodes"`
	NoOfApps         int         `json:"noOfApps"`
	PremiumNodesList interface{} `json:"premiumNodesList"`

	Credit               int  `json:"credit"`
	FreeTrial            bool `json:"freeTrial"`
	AnnualSubscription   bool `json:"AnnualSubscription"`
	FreeTrialJoiningDate int  `json:"freeTrialJoiningDate"`
}

DevDescriptor describes the status of a developer/user

type EncryptionType

type EncryptionType int

EncryptionType represents an enumeration for the types of Encryption Schemes supported by MOIBit

const (
	// NoEncryption applies no encryption on the file when storing on MOIBit
	NoEncryption EncryptionType = iota - 1

	// DefaultNetworkEncryption applies the default network
	// encryption scheme on the file when storing on MOIBit.
	DefaultNetworkEncryption

	// DeveloperKeyEncryption applies the default encryption scheme defined for
	// the user/developer authenticated with client making the write request
	DeveloperKeyEncryption

	// EndUserKeyEncryption applies the encryption scheme defined by
	// the end user's key for whom the file is being stored.
	EndUserKeyEncryption

	// CustomKeyEncryption applies the custom encryption scheme defined
	// for the application on the file when storing on MOIBit
	CustomKeyEncryption

	// MESEncryption applies the Modern Encryption Standard
	// on the file when storing on MOIBit.
	MESEncryption
)

type FileDescriptor

type FileDescriptor struct {
	FileVersionDescriptor // inlined JSON

	Path        string `json:"path"`
	IsDirectory bool   `json:"isDir"`
	Directory   string `json:"directory"`
	NodeAddress string `json:"nodeAddress"`
}

FileDescriptor describes the status of file

func (FileDescriptor) Exists

func (file FileDescriptor) Exists() bool

Exists returns whether a file exists or not. Returns true if the file is a directory or has a non nil hash

func (FileDescriptor) String

func (file FileDescriptor) String() string

String implements the Stringer interface for FileDescriptor

type FileVersionDescriptor

type FileVersionDescriptor struct {
	Active bool `json:"active"`
	Enable bool `json:"enable"`

	Hash           string `json:"hash"`
	ProvenanceHash string `json:"provenanceHash"`
	Version        int    `json:"version"`
	Replication    int    `json:"replication"`
	FileSize       int    `json:"filesize"`

	EncryptionKey string `json:"encryptionKey"`
	LastUpdated   string `json:"lastUpdated"`
}

FileVersionDescriptor describes the version information of file

type RemoveOption

type RemoveOption func(*requestRemoveFile) error

RemoveOption is a request option for the RemoveFile method of Client.

func PerformRestore

func PerformRestore() RemoveOption

PerformRestore returns a RemoveOption that will set the operation mode of RemoveFile to restoration, which will result in MOIBit attempting to restore the file version

func RemoveDirectory

func RemoveDirectory() RemoveOption

RemoveDirectory returns a RemoveOption that will specify that the file to delete is a directory. Note: This will cause RemoveFile to fail if it is a file and not a directory.

type WriteOption

type WriteOption func(*requestWriteFile) error

WriteOption is a request option for the WriteFile method of Client.

func ApplyEncryption

func ApplyEncryption(encryption EncryptionType) WriteOption

ApplyEncryption returns a WriteOption that can specify the encryption scheme for the file while being written to MOIBit.

func CreateFolders

func CreateFolders() WriteOption

CreateFolders returns a WriteOption that can be used to specify that the file write should create all folders (that do not exist) specified in the path of the file name

func CreateOnlyFile

func CreateOnlyFile() WriteOption

CreateOnlyFile returns a WriteOption that can be used to specify that the file write should fail in case folders specified in the path of the file do not exist already.

func KeepPrevious

func KeepPrevious() WriteOption

KeepPrevious returns a WriteOption that can be used to preserve the versioning of the file that is written, in case the file already exists.

func Provenance

func Provenance() WriteOption

Provenance returns a WriteOption that can be used to specify that the proof of the file needs to be stored on MOI's Indus Provenance Network.

func ReplicationFactor

func ReplicationFactor(n int) WriteOption

ReplicationFactor returns a WriteOption that can be used to specify the number of replications for the written file on its network.

Jump to

Keyboard shortcuts

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