models

package
v2.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2019 License: MIT Imports: 11 Imported by: 24

Documentation

Index

Constants

View Source
const (
	// ErrShorterGCD is an error triggered when updating to update an upload for a user
	// with a hold time that would result in a shorter garbage collection date
	ErrShorterGCD = "upload would not extend garbage collection date so there is no need to process"
	// ErrAlreadyExistingUpload is an error triggered when attempting to insert  a new row into the database
	// for a content that already exists in the database for a user. This means you should be using the UpdateUpload
	// function to allow for updating garbage collection dates.
	ErrAlreadyExistingUpload = "the content you are inserting into the database already exists, please use the UpdateUpload function"
)

Variables

View Source
var (
	// Free is what every signed up user is automatically registered as
	// Restrictions of free:
	//			* No on-demand data encryption
	//			* 3GB/month max
	//			* IPNS limit of 5, with no automatic republishes
	//			* 5 keys
	Free DataUsageTier = "free"

	// Partner is for partners of RTrade
	// partners have 100GB/month free
	//			* on-demand data encryption
	//			* 0.16GB/month after 100GB limit
	Partner DataUsageTier = "partner"

	// Light is the first non-free, and non-partner tier
	// tier is from 3GB -> 100GB
	// after reaching 100GB they are upgraded to Plus
	//			* on-demand data encryption
	//			* 0.22
	Light DataUsageTier = "light"

	// Plus is the other non-free, non-partner, non-light tier
	// tier is from 100GB -> 1TB to our max monthly usage of 1TB
	// 			* on-demand data encryption
	//			* $0.165
	Plus DataUsageTier = "plus"

	// FreeUploadLimit is the maximum data usage for free accounts
	// Currrently set to 3GB
	FreeUploadLimit = 3 * datasize.GB.Bytes()

	// NonFreeUploadLimit is the maximum data usage for non-free accounts
	// Currently set to 1TB
	NonFreeUploadLimit = datasize.TB.Bytes()

	// PlusTierMinimumUpload is the current data usage
	// needed to upgrade from Light -> Plus
	// currently set to 100GB
	PlusTierMinimumUpload = 100 * datasize.GB.Bytes()

	// FreeKeyLimit defines how many keys free accounts can create
	FreeKeyLimit int64 = 5
	// FreePubSubLimit defines how many pubsub messages free accounts can send
	FreePubSubLimit int64 = 100
	// FreeIPNSLimit defines how many ipns records free accounts can publish
	FreeIPNSLimit int64 = 5

	// PartnerKeyLimit defines how many keys partner accounts can create
	PartnerKeyLimit int64 = 200
	// PartnerPubSubLimit defines how many pubsub messages partner accounts can send
	PartnerPubSubLimit int64 = 20000
	// PartnerIPNSLimit defines how many ipns records partner accounts can publish
	PartnerIPNSLimit int64 = 200

	// LightKeyLimit defines how many keys light accounts can create
	LightKeyLimit int64 = 100
	// LightPubSubLimit defines how many pubsub messages light accounts can send
	LightPubSubLimit int64 = 10000
	// LightIPNSLimit defines how many ipns records light accounts can publish
	LightIPNSLimit int64 = 100

	// PlusKeyLimit defines how many keys plus accounts can create
	PlusKeyLimit int64 = 150
	// PlusPubSubLimit defines how many pubsub messages plus accounts can send
	PlusPubSubLimit int64 = 15000
	// PlusIPNSRecordLimit defines how many ipns records plus accounts can publish
	PlusIPNSRecordLimit int64 = 150
)
View Source
var AdminAddress = "0xC6C35f43fDD71f86a2D8D4e3cA1Ce32564c38bd9"

AdminAddress is the eth address of the admin account

View Source
var (
	// EmptyCustomerObjectHash is an empty customer object published to ipfs
	EmptyCustomerObjectHash = "zdpuAnUGSDoNQoHQ2jpjhPePHEvg26mYLsAAGxr4jkzCWUpde"
)

Functions

This section is empty.

Types

type APIDetails added in v1.3.0

type APIDetails struct {
	AllowedOrigin string
}

APIDetails provides data about IPFS API connection

type DataUsageTier added in v1.3.0

type DataUsageTier string

DataUsageTier is a type of usage tier which governs the price per gb ratio

func (DataUsageTier) PricePerGB added in v1.3.0

func (d DataUsageTier) PricePerGB() float64

PricePerGB returns the price per gb of a usage tier

func (DataUsageTier) String added in v1.3.0

func (d DataUsageTier) String() string

String returns the value of DataUsageTier as a string

type EncryptedUpload added in v1.0.6

type EncryptedUpload struct {
	gorm.Model
	UserName      string `gorm:"type:varchar(255)"`
	FileName      string `gorm:"type:varchar(255)"`
	FileNameUpper string `gorm:"type:varchar(255)"`
	FileNameLower string `gorm:"type:varchar(255)"`
	NetworkName   string `gorm:"type:varchar(255)"`
	IPFSHash      string `gorm:"type:varchar(255)"`
}

EncryptedUpload is an uploaded that has been encrypted by Temporal

type EncryptedUploadManager added in v1.0.6

type EncryptedUploadManager struct {
	DB *gorm.DB
}

EncryptedUploadManager is used to manipulate encrypted uplaods

func NewEncryptedUploadManager added in v1.0.6

func NewEncryptedUploadManager(db *gorm.DB) *EncryptedUploadManager

NewEncryptedUploadManager is used to generate our db helper

func (*EncryptedUploadManager) FindUploadsByUser added in v1.0.6

func (ecm *EncryptedUploadManager) FindUploadsByUser(username string) (*[]EncryptedUpload, error)

FindUploadsByUser is used to find all uploads for a given user

func (*EncryptedUploadManager) NewUpload added in v1.0.6

func (ecm *EncryptedUploadManager) NewUpload(username, filename, networname, ipfsHash string) (*EncryptedUpload, error)

NewUpload is used to store a new encrypted upload in the database

type HostedNetwork

type HostedNetwork struct {
	ID        uint `gorm:"primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time

	Name      string     `gorm:"unique;type:varchar(255)"` // Name of the network node
	Activated *time.Time // Activated represents the most recent activation, null if offline
	Disabled  bool

	PeerKey string // Private key used to generate peerID for this network node

	// SwarmAddr is the address of swarm port. Slated for deprecation if HTTP path
	// support is added to the multiaddr spec and go-multiaddr
	SwarmAddr string `gorm:"type:varchar(255)"`
	// SwarmKey is the key used to connect to this peer
	SwarmKey string `gorm:"type:varchar(255)"`

	// Used to set Allowed-Origin headers on API requests
	APIAllowedOrigin string `gorm:"type:varchar(255)"`

	// Toggles whether gateway should be exposed through Nexus delegator
	GatewayPublic bool `gorm:"type:boolean"`

	// Peers to bootstrap node onto
	BootstrapPeerAddresses pq.StringArray `gorm:"type:text[]"`
	BootstrapPeerIDs       pq.StringArray `gorm:"type:text[];column:bootstrap_peer_ids"`

	// Resources for deployed node
	ResourcesCPUs     int
	ResourcesDiskGB   int
	ResourcesMemoryGB int

	// Owner is the creator of the private network, and is allowed to invoke
	// administrative commands, such as network destruction.
	Owners pq.StringArray `gorm:"type:text[]"`
	// Users allowed to control this node. Includes API access.
	Users pq.StringArray `gorm:"type:text[]"` // these are the users to which this IPFS network connection applies to specified by eth address
}

HostedNetwork is a private network for which we are responsible of the infrastructure

type HostedNetworkManager

type HostedNetworkManager struct {
	DB *gorm.DB
}

HostedNetworkManager is used to manipulate IPFS network models in the database

func NewHostedNetworkManager

func NewHostedNetworkManager(db *gorm.DB) *HostedNetworkManager

NewHostedNetworkManager is used to initialize our database connection

func (*HostedNetworkManager) CreateHostedPrivateNetwork

func (im *HostedNetworkManager) CreateHostedPrivateNetwork(
	name, swarmKey string,
	peers []string,
	access NetworkAccessOptions,
) (*HostedNetwork, error)

CreateHostedPrivateNetwork is used to store a new hosted private network in the database

func (*HostedNetworkManager) Delete

func (im *HostedNetworkManager) Delete(name string) error

Delete is used to remove a network from the database

func (*HostedNetworkManager) GetAPIDetails

func (im *HostedNetworkManager) GetAPIDetails(network string) (*APIDetails, error)

GetAPIDetails is used to retrieve data about IPFS API connection

func (*HostedNetworkManager) GetNetworkByName

func (im *HostedNetworkManager) GetNetworkByName(name string) (*HostedNetwork, error)

GetNetworkByName is used to retrieve a network from the database based off of its name

func (*HostedNetworkManager) GetOfflineNetworks

func (im *HostedNetworkManager) GetOfflineNetworks(disabled bool) ([]*HostedNetwork, error)

GetOfflineNetworks returns all currently offline networks

func (*HostedNetworkManager) GetSwarmDetails

func (im *HostedNetworkManager) GetSwarmDetails(network string) (*SwarmDetails, error)

GetSwarmDetails is used to retrieve data about IPFS swarm connection

func (*HostedNetworkManager) SaveNetwork

func (im *HostedNetworkManager) SaveNetwork(n *HostedNetwork) error

SaveNetwork saves the given HostedNetwork in the database

func (*HostedNetworkManager) UpdateNetworkByName

func (im *HostedNetworkManager) UpdateNetworkByName(name string, attrs map[string]interface{}) error

UpdateNetworkByName updates the given network with given attributes

type IPNS

type IPNS struct {
	gorm.Model
	Sequence int64 `gorm:"type:integer"`
	// the ipns hash, is the peer id of the peer used to sign the entry
	IPNSHash string `gorm:"type:varchar(255);unique"`
	// List of content hashes this IPNS entry has pointed to
	IPFSHashes      pq.StringArray `gorm:"type:text[]"`
	CurrentIPFSHash string         `gorm:"type:varchar(255)"`
	LifeTime        string         `gorm:"type:varchar(255)"`
	TTL             string         `gorm:"type:varchar(255)"`
	Key             string         `gorm:"type:varchar(255)"`
	NetworkName     string         `gorm:"type:varchar(255)"`
	UserName        string         `gorm:"type:varchar(255)"`
}

IPNS will hold all of the IPNS entries in our system

type IpnsManager

type IpnsManager struct {
	DB *gorm.DB
}

IpnsManager is used for manipulating IPNS records in our database

func NewIPNSManager

func NewIPNSManager(db *gorm.DB) *IpnsManager

NewIPNSManager is used to generate our model manager

func (*IpnsManager) CreateEntry

func (im *IpnsManager) CreateEntry(ipnsHash, ipfsHash, key, networkName, username string, lifetime, ttl time.Duration) (*IPNS, error)

CreateEntry is used to create a brand new IPNS entry in our database

func (*IpnsManager) FindAll

func (im *IpnsManager) FindAll() ([]IPNS, error)

FindAll is used to find all IPNS records

func (*IpnsManager) FindByIPNSHash

func (im *IpnsManager) FindByIPNSHash(ipnsHash string) (*IPNS, error)

FindByIPNSHash is used to find an IPNS record from our database searching for the public key hash of the key that was used to pulish a record

func (*IpnsManager) FindByUserName added in v1.0.4

func (im *IpnsManager) FindByUserName(username string) (*[]IPNS, error)

FindByUserName is used to find all IPNS entries published by a given user

func (*IpnsManager) UpdateIPNSEntry

func (im *IpnsManager) UpdateIPNSEntry(ipnsHash, ipfsHash, networkName, username string, lifetime, ttl time.Duration) (*IPNS, error)

UpdateIPNSEntry is used to update an already existing IPNS entry, creating a no record matching the hash exists

type NetworkAccessOptions added in v1.3.0

type NetworkAccessOptions struct {
	Owner            string
	Users            []string
	APIAllowedOrigin string
	PublicGateway    bool
}

NetworkAccessOptions configures access to a hosted private network

type PaymentManager

type PaymentManager struct {
	DB *gorm.DB
}

PaymentManager is used to interact with payment information in our database

func NewPaymentManager

func NewPaymentManager(db *gorm.DB) *PaymentManager

NewPaymentManager is used to generate our payment manager helper

func (*PaymentManager) ConfirmPayment added in v1.0.2

func (pm *PaymentManager) ConfirmPayment(txHash string) (*Payments, error)

ConfirmPayment is used to mark a payment as confirmed

func (*PaymentManager) FindPaymentByNumber added in v1.0.5

func (pm *PaymentManager) FindPaymentByNumber(username string, number int64) (*Payments, error)

FindPaymentByNumber is used to find a payment by its payment number

func (*PaymentManager) FindPaymentByTxHash added in v1.0.2

func (pm *PaymentManager) FindPaymentByTxHash(txHash string) (*Payments, error)

FindPaymentByTxHash is used to find a payment by its tx hash

func (*PaymentManager) GetLatestPaymentNumber added in v1.0.5

func (pm *PaymentManager) GetLatestPaymentNumber(username string) (int64, error)

GetLatestPaymentNumber is used to get the latest payment number for a user

func (*PaymentManager) NewPayment

func (pm *PaymentManager) NewPayment(number int64, depositAddress string, txHash string, usdValue, chargeAmount float64, blockchain string, paymentType string, username string) (*Payments, error)

NewPayment is used to create a payment in our database

func (*PaymentManager) UpdatePaymentTxHash added in v1.0.5

func (pm *PaymentManager) UpdatePaymentTxHash(username, txHash string, number int64) (*Payments, error)

UpdatePaymentTxHash UpdatePaymentTxHash is used to update the tx hash of a payment

type Payments added in v1.0.2

type Payments struct {
	gorm.Model
	Number         int64   `gorm:"type:integer"`
	DepositAddress string  `gorm:"type:varchar(255)"`
	TxHash         string  `gorm:"type:varchar(255);unique"`
	USDValue       float64 `gorm:"type:float"` // USDValue is also a "Credit" value, since 1 USD -> 1 Credit
	ChargeAmount   float64 `gorm:"type:float"`
	Blockchain     string  `gorm:"type:varchar(255)"`
	Type           string  `gorm:"type:varchar(255)"` // ETH, RTC, XMR, BTC, LTC
	UserName       string  `gorm:"type:varchar(255)"`
	Confirmed      bool    `gorm:"type:varchar(255)"`
}

Payments is our payment model

type Record added in v1.0.6

type Record struct {
	gorm.Model
	UserName       string      `gorm:"type:varchar(255)"`
	Name           string      `gorm:"type:varchar(255)"`
	RecordKeyName  string      `gorm:"type:varchar(255)"`
	LatestIPFSHash string      `gorm:"type:varchar(255)"`
	ZoneName       string      `gorm:"type:varchar(255)"`
	MetaData       interface{} `gorm:"type:text"` // we need to parse this to a "string json"
}

Record is an entry within a tns zone

type RecordManager added in v1.0.6

type RecordManager struct {
	DB *gorm.DB
}

RecordManager is used to manipulate records in our db

func NewRecordManager added in v1.0.6

func NewRecordManager(db *gorm.DB) *RecordManager

NewRecordManager is used to generate our record manager

func (*RecordManager) AddRecord added in v1.0.6

func (rm *RecordManager) AddRecord(username, recordName, recordKeyName, zoneName string, metadata map[string]interface{}) (*Record, error)

AddRecord is used to save a record to our database

func (*RecordManager) FindRecordByNameAndUser added in v1.0.6

func (rm *RecordManager) FindRecordByNameAndUser(username, name string) (*Record, error)

FindRecordByNameAndUser is used to search fro a record by name and user

func (*RecordManager) FindRecordsByZone added in v1.0.6

func (rm *RecordManager) FindRecordsByZone(username, zoneName string) (*[]Record, error)

FindRecordsByZone is used to find records by zone

func (*RecordManager) UpdateLatestIPFSHash added in v1.0.6

func (rm *RecordManager) UpdateLatestIPFSHash(username, recordName, ipfsHash string) (*Record, error)

UpdateLatestIPFSHash is used to update the latest IPFS hash that can be used to examine this record

type SwarmDetails added in v1.3.0

type SwarmDetails struct {
	Addr string
	Key  string
}

SwarmDetails provides data about IPFS swarm connection

type Upload

type Upload struct {
	gorm.Model
	Hash               string `gorm:"type:varchar(255);not null;"`
	Type               string `gorm:"type:varchar(255);not null;"` //  file, pin
	NetworkName        string `gorm:"type:varchar(255)"`
	HoldTimeInMonths   int64  `gorm:"type:integer;not null;"`
	UserName           string `gorm:"type:varchar(255);not null;"`
	GarbageCollectDate time.Time
	Encrypted          bool `gorm:"type:bool"`
}

Upload is a file or pin based upload to temporal

type UploadManager

type UploadManager struct {
	DB *gorm.DB
}

UploadManager is used to manipulate upload objects in the database

func NewUploadManager

func NewUploadManager(db *gorm.DB) *UploadManager

NewUploadManager is used to generate an upload manager interface

func (*UploadManager) ExtendGarbageCollectionPeriod

func (um *UploadManager) ExtendGarbageCollectionPeriod(username, hash, network string, holdTimeInMonths int) error

ExtendGarbageCollectionPeriod is used to extend the garbage collection period for a particular upload

func (*UploadManager) FindUploadByHashAndNetwork

func (um *UploadManager) FindUploadByHashAndNetwork(hash, networkName string) (*Upload, error)

FindUploadByHashAndNetwork is used to search for an upload by its hash, and the network it was stored on

func (*UploadManager) FindUploadByHashAndUserAndNetwork

func (um *UploadManager) FindUploadByHashAndUserAndNetwork(username, hash, networkName string) (*Upload, error)

FindUploadByHashAndUserAndNetwork is used to look for an upload based off its hash, user, and network

func (*UploadManager) FindUploadsByHash

func (um *UploadManager) FindUploadsByHash(hash string) ([]Upload, error)

FindUploadsByHash is used to return all instances of uploads matching the given hash

func (*UploadManager) FindUploadsByNetwork

func (um *UploadManager) FindUploadsByNetwork(networkName string) ([]Upload, error)

FindUploadsByNetwork is used to find all uploads corresponding to a given network

func (*UploadManager) GetUploadByHashForUser

func (um *UploadManager) GetUploadByHashForUser(hash string, username string) ([]Upload, error)

GetUploadByHashForUser is used to retrieve the last (most recent) upload for a user

func (*UploadManager) GetUploads

func (um *UploadManager) GetUploads() ([]Upload, error)

GetUploads is used to return all uploads

func (*UploadManager) GetUploadsForUser

func (um *UploadManager) GetUploadsForUser(username string) ([]Upload, error)

GetUploadsForUser is used to retrieve all uploads by a user name

func (*UploadManager) NewUpload

func (um *UploadManager) NewUpload(contentHash, uploadType string, opts UploadOptions) (*Upload, error)

NewUpload is used to create a new upload in the database

func (*UploadManager) UpdateUpload

func (um *UploadManager) UpdateUpload(holdTimeInMonths int64, username, contentHash, networkName string) (*Upload, error)

UpdateUpload is used to update the garbage collection time for an already existing upload

type UploadOptions added in v1.0.6

type UploadOptions struct {
	NetworkName      string
	Username         string
	HoldTimeInMonths int64
	Encrypted        bool
}

UploadOptions is used to configure an upload

type Usage added in v1.3.0

type Usage struct {
	gorm.Model
	UserName string `gorm:"type:varchar(255);unique"`
	// keeps track of the max monthly upload limit for the user
	MonthlyDataLimitBytes uint64 `gorm:"type:numeric;default:0"`
	// keeps track of the current monthyl upload limit used
	CurrentDataUsedBytes uint64 `gorm:"type:numeric;default:0"`
	// keeps track of how many IPNS records the user has published
	IPNSRecordsPublished int64 `gorm:"type:integer;default:0"`
	// keeps track of how many ipns records the user is allowed to publish
	IPNSRecordsAllowed int64 `gorm:"type:integer;default:0"`
	// keeps track of how many messages the user has sent
	PubSubMessagesSent int64 `gorm:"type:integer;default:0"`
	// keeps track of the number of pubsub messages a user is allowed to send
	PubSubMessagesAllowed int64 `gorm:"type:integer;default:0"`
	// keeps track of how many keys the user has created
	KeysCreated int64 `gorm:"type:integer;default:0"`
	// keeps track of how many keys the user is allowed to create
	KeysAllowed int64 `gorm:"type:integer;default:0"`
	// keeps track of the tier the user belongs to
	Tier DataUsageTier `gorm:"type:varchar(255)"`
}

Usage is used to handle Usage of Temporal accounts

type UsageManager added in v1.3.0

type UsageManager struct {
	DB *gorm.DB
}

UsageManager is used to manage Usage models

func NewUsageManager added in v1.3.0

func NewUsageManager(db *gorm.DB) *UsageManager

NewUsageManager is used to instantiate a Usage manager

func (*UsageManager) CanCreateKey

func (bm *UsageManager) CanCreateKey(username string) error

CanCreateKey is used to check if a user can create an ipfs key

func (*UsageManager) CanPublishIPNS added in v1.3.0

func (bm *UsageManager) CanPublishIPNS(username string) error

CanPublishIPNS is used to check if a user can publish IPNS records

func (*UsageManager) CanPublishPubSub added in v1.3.0

func (bm *UsageManager) CanPublishPubSub(username string) error

CanPublishPubSub is used to check if a user can publish pubsub messages

func (*UsageManager) CanUpload

func (bm *UsageManager) CanUpload(username string, dataSizeBytes uint64) error

CanUpload is used to check if a user can upload an object with the given data size

func (*UsageManager) FindByUserName added in v1.3.0

func (bm *UsageManager) FindByUserName(username string) (*Usage, error)

FindByUserName is used to find a Usage model by the associated username

func (*UsageManager) GetUploadPricePerGB added in v1.3.0

func (bm *UsageManager) GetUploadPricePerGB(username string) (float64, error)

GetUploadPricePerGB is used to get the upload price per gb for a user allows us to specify whether the payment

func (*UsageManager) IncrementIPNSUsage added in v1.3.0

func (bm *UsageManager) IncrementIPNSUsage(username string, count int64) error

IncrementIPNSUsage is used to increment the ipns record publish counter

func (*UsageManager) IncrementKeyCount

func (bm *UsageManager) IncrementKeyCount(username string, count int64) error

IncrementKeyCount is used to increment the key created counter

func (*UsageManager) IncrementPubSubUsage added in v1.3.0

func (bm *UsageManager) IncrementPubSubUsage(username string, count int64) error

IncrementPubSubUsage is used to increment the pubsub publish counter

func (*UsageManager) NewUsageEntry added in v1.3.0

func (bm *UsageManager) NewUsageEntry(username string, tier DataUsageTier) (*Usage, error)

NewUsageEntry is used to create a new usage entry in our database if tier is free, limit to 3GB monthly otherwise set to 1TB

func (*UsageManager) ReduceDataUsage

func (bm *UsageManager) ReduceDataUsage(username string, uploadSizeBytes uint64) error

ReduceDataUsage is used to reduce a users current data used. This is used in cases where processing within the queue system fails, and we need to reset their data usage

func (*UsageManager) ReduceKeyCount

func (bm *UsageManager) ReduceKeyCount(username string, count int64) error

ReduceKeyCount is used to reduce the number of keys a user has created

func (*UsageManager) ResetCounts

func (bm *UsageManager) ResetCounts(username string) error

ResetCounts is used to reset monthly usage counts. This does not apply to keys, as keys are a fixed limitation

func (*UsageManager) UpdateDataUsage added in v1.3.0

func (bm *UsageManager) UpdateDataUsage(username string, uploadSizeBytes uint64) error

UpdateDataUsage is used to update the users' data usage amount If the account is non free, and the upload pushes their total monthly usage above the tier limit, they will be upgraded to the next tier to receive the discounted price the discounted price will apply on subsequent uploads. If the 1TB maximum monthly limit is hit, then we throw an error

func (*UsageManager) UpdateTier added in v1.3.0

func (bm *UsageManager) UpdateTier(username string, tier DataUsageTier) error

UpdateTier is used to update the Usage tier associated with an account accounts may never be downgraded back to Free

type User

type User struct {
	gorm.Model
	UserName               string  `gorm:"type:varchar(255);unique"`
	EmailAddress           string  `gorm:"type:varchar(255);unique"`
	AccountEnabled         bool    `gorm:"type:boolean"`
	EmailEnabled           bool    `gorm:"type:boolean"`
	EmailVerificationToken string  `gorm:"type:varchar(255)"`
	AdminAccess            bool    `gorm:"type:boolean"`
	HashedPassword         string  `gorm:"type:varchar(255)"`
	Free                   bool    `gorm:"type:boolean"`
	Credits                float64 `gorm:"type:float;default:0"`
	CustomerObjectHash     string  `gorm:"type:varchar(255)"`
	// IPFSKeyNames is an array of IPFS key name this user has created
	IPFSKeyNames pq.StringArray `gorm:"type:text[];column:ipfs_key_names"`
	// IPFSKeyIDs is an array of public key hashes for IPFS keys this user has created
	IPFSKeyIDs pq.StringArray `gorm:"type:text[];column:ipfs_key_ids"`
	// IPFSNetworkNames is an array of private IPFS networks this user has access to
	IPFSNetworkNames pq.StringArray `gorm:"type:text[];column:ipfs_network_names"`
}

User is our user model for anyone who signs up with Temporal

type UserManager

type UserManager struct {
	DB *gorm.DB
}

UserManager is our helper to interact with our database

func NewUserManager

func NewUserManager(db *gorm.DB) *UserManager

NewUserManager is used to generate our user manager helper

func (*UserManager) AddCredits added in v1.0.3

func (um *UserManager) AddCredits(username string, credits float64) (*User, error)

AddCredits is used to add credits to a user account

func (*UserManager) AddIPFSKeyForUser

func (um *UserManager) AddIPFSKeyForUser(username, keyName, keyID string) error

AddIPFSKeyForUser is used to add a key to a user

func (*UserManager) AddIPFSNetworkForUser

func (um *UserManager) AddIPFSNetworkForUser(username, networkName string) error

AddIPFSNetworkForUser is used to update a users allowed private ipfs networks

func (*UserManager) ChangePassword

func (um *UserManager) ChangePassword(username, currentPassword, newPassword string) (bool, error)

ChangePassword is used to change a users password

func (*UserManager) CheckIfAdmin added in v1.0.3

func (um *UserManager) CheckIfAdmin(username string) (bool, error)

CheckIfAdmin is used to check if an account is an administrator

func (*UserManager) CheckIfKeyOwnedByUser

func (um *UserManager) CheckIfKeyOwnedByUser(username, keyName string) (bool, error)

CheckIfKeyOwnedByUser is used to check if a key is owned by a user

func (*UserManager) CheckIfUserAccountEnabled

func (um *UserManager) CheckIfUserAccountEnabled(username string) (bool, error)

CheckIfUserAccountEnabled is used to check if a user account is enabled

func (*UserManager) CheckIfUserHasAccessToNetwork

func (um *UserManager) CheckIfUserHasAccessToNetwork(username, networkName string) (bool, error)

CheckIfUserHasAccessToNetwork is used to check if a user has access to a private ipfs network

func (*UserManager) ComparePlaintextPasswordToHash

func (um *UserManager) ComparePlaintextPasswordToHash(username, password string) (bool, error)

ComparePlaintextPasswordToHash is a helper method used to validate a users password

func (*UserManager) FindByEmail added in v1.0.6

func (um *UserManager) FindByEmail(email string) (*User, error)

FindByEmail is used to find a particular user based on their email address

func (*UserManager) FindByUserName added in v1.0.2

func (um *UserManager) FindByUserName(username string) (*User, error)

FindByUserName is used to find a user by their username

func (*UserManager) GenerateEmailVerificationToken added in v1.0.6

func (um *UserManager) GenerateEmailVerificationToken(username string) (*User, error)

GenerateEmailVerificationToken is used to generate a token we use to validate that the user actually owns the email they are signing up with

func (*UserManager) GetCreditsForUser added in v1.0.2

func (um *UserManager) GetCreditsForUser(username string) (float64, error)

GetCreditsForUser is used to get the user's current credits

func (*UserManager) GetCustomerObjectHash

func (um *UserManager) GetCustomerObjectHash(username string) (string, error)

GetCustomerObjectHash is used to retrieve the object hash of a customer

func (*UserManager) GetKeyIDByName

func (um *UserManager) GetKeyIDByName(username, keyName string) (string, error)

GetKeyIDByName is used to get the ID of a key by searching for its name

func (*UserManager) GetKeysForUser

func (um *UserManager) GetKeysForUser(username string) (map[string][]string, error)

GetKeysForUser is used to get a mapping of a users keys

func (*UserManager) GetPrivateIPFSNetworksForUser

func (um *UserManager) GetPrivateIPFSNetworksForUser(username string) ([]string, error)

GetPrivateIPFSNetworksForUser is used to get a list of allowed private ipfs networks for a user

func (*UserManager) NewUserAccount

func (um *UserManager) NewUserAccount(username, password, email string) (*User, error)

NewUserAccount is used to create a new user account

func (*UserManager) RemoveCredits added in v1.0.2

func (um *UserManager) RemoveCredits(username string, credits float64) (*User, error)

RemoveCredits is used to remove credits from a users balance

func (*UserManager) RemoveIPFSKeyForUser

func (um *UserManager) RemoveIPFSKeyForUser(username, keyName, keyID string) error

RemoveIPFSKeyForUser is used to remove a given key name and its id from the users available keys they have created.

func (*UserManager) RemoveIPFSNetworkForUser added in v1.1.0

func (um *UserManager) RemoveIPFSNetworkForUser(username, networkName string) error

RemoveIPFSNetworkForUser is used to remove a configured ipfs network from the users authorized networks

func (*UserManager) ResetPassword added in v1.0.6

func (um *UserManager) ResetPassword(username string) (string, error)

ResetPassword is used to reset a user's password if they forgot it

func (*UserManager) SignIn

func (um *UserManager) SignIn(username, password string) (bool, error)

SignIn is used to authenticate a user, and check if their account is enabled. Returns bool on succesful login, or false with an error on failure

func (*UserManager) ToggleAdmin added in v1.0.6

func (um *UserManager) ToggleAdmin(username string) (bool, error)

ToggleAdmin toggles the admin permissions of given user

func (*UserManager) UpdateCustomerObjectHash

func (um *UserManager) UpdateCustomerObjectHash(username, newHash string) error

UpdateCustomerObjectHash is used to update the customer object hash associated with the user

func (*UserManager) ValidateEmailVerificationToken added in v1.0.6

func (um *UserManager) ValidateEmailVerificationToken(username, token string) (*User, error)

ValidateEmailVerificationToken is used to validate an email token to enable email access

type Zone added in v1.0.6

type Zone struct {
	gorm.Model
	UserName             string         `gorm:"type:varchar(255)"`
	Name                 string         `gorm:"type:varchar(255)"`
	ManagerPublicKeyName string         `gorm:"type:varchar(255)"`
	ZonePublicKeyName    string         `gorm:"type:varchar(255)"`
	LatestIPFSHash       string         `gorm:"type:varchar(255)"`
	RecordNames          pq.StringArray `gorm:"type:text[]"`
}

Zone is a TNS zone

type ZoneManager added in v1.0.6

type ZoneManager struct {
	DB *gorm.DB
}

ZoneManager is used to manipulate zone entries in the database

func NewZoneManager added in v1.0.6

func NewZoneManager(db *gorm.DB) *ZoneManager

NewZoneManager is used to generate our zone manager helper to interact with the db

func (*ZoneManager) AddRecordForZone added in v1.0.6

func (zm *ZoneManager) AddRecordForZone(zoneName, recordName, username string) (*Zone, error)

AddRecordForZone is used to add a record to a zone

func (*ZoneManager) CheckIfRecordExistsInZone added in v1.0.6

func (zm *ZoneManager) CheckIfRecordExistsInZone(zoneName, recordName, username string) (bool, error)

CheckIfRecordExistsInZone is used to check if a record exists in a particular zone

func (*ZoneManager) FindZoneByNameAndUser added in v1.0.6

func (zm *ZoneManager) FindZoneByNameAndUser(name, username string) (*Zone, error)

FindZoneByNameAndUser is used to lookup a zone by name and user

func (*ZoneManager) NewZone added in v1.0.6

func (zm *ZoneManager) NewZone(username, name, managerPK, zonePK, latestIPFSHash string) (*Zone, error)

NewZone is used to create a new zone in the database

func (*ZoneManager) UpdateLatestIPFSHashForZone added in v1.0.6

func (zm *ZoneManager) UpdateLatestIPFSHashForZone(name, username, hash string) (*Zone, error)

UpdateLatestIPFSHashForZone is used to update the latest IPFS hash for a zone file

Jump to

Keyboard shortcuts

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