license

package
v0.0.0-...-8047851 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BlankUUID is the erronous return from _help_make_uuid
	BlankUUID = "00000000-0000-0000-0000-000000000000"
)
View Source
const (
	// DefaultConfigPath is the global default location to find a config for our service
	DefaultConfigPath = "config.toml"
)
View Source
const SchemaSqlite3 = `` /* 252-byte string literal not displayed */

SchemaSqlite3 is the default schema for our Sqlite3 impl

View Source
const (
	// Version for the application
	Version = "0.0.1"
)

Variables

This section is empty.

Functions

func NewUUID

func NewUUID() (string, error)

NewUUID will return a new UUID struct

Types

type AssignRequest

type AssignRequest struct {
	UUID      string `db:"uuid"`       // UUID (set internally)
	AccountID string `db:"account_id"` // The ID for the license request
	LicenseID string `db:"license_id"` // The ID for the license being requested
}

AssignRequest is used to serialise the basic license request.

type Config

type Config struct {

	// Database configuration
	Database struct {
		Driver string
		Name   string
	}

	Email struct {
		Method   string
		From     string `toml:"from"`
		SMTPUser string `toml:"smtp_user"`
		SMTPPort int    `toml:"smtp_port"`
		SMTPPass string `toml:"smtp_pass"`
		SMTPHost string `toml:"smtp_host"`
	}
}

Config contains the service-wide configuration

func NewConfig

func NewConfig(path string) (*Config, error)

NewConfig will return a new Config object preseeded from the default configuration path.

func (*Config) ShouldEmail

func (c *Config) ShouldEmail() bool

ShouldEmail will return true if we should email the new licenses

type CreateRequest

type CreateRequest struct {
	LicenseID   string `db:"license_id"`  // The ID of the license
	Description string `db:"description"` // Description of the license
	MaxUsers    int    `db:"max_users"`   // Maximum number of users for the license
}

CreateRequest is used for creating new licenses

type Database

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

Database wraps the underlying database connection and helps with the storage side of things.

func NewDatabase

func NewDatabase(config *Config) (*Database, error)

NewDatabase will attempt to open and initialise the database using the given Config instance.

func (*Database) Assign

func (d *Database) Assign(req *AssignRequest) (string, error)

Assign will attempt to claim the given license request, and return the UUID for the allocation.

func (*Database) Close

func (d *Database) Close()

Close will shutdown any resources associate with the database

func (*Database) GetInfo

func (d *Database) GetInfo(id string) (*Info, error)

GetInfo will return an Info type populated with information on the given license. If the license doesn't exist, then no info will be returned, and the user cannot be assigned the license.

func (*Database) InsertLicense

func (d *Database) InsertLicense(req CreateRequest) error

InsertLicense will insert a new license if possible

type Email

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

Email is used to render and send HTML emails in batch

func NewEmail

func NewEmail(req *AssignRequest, info *Info) (*Email, error)

NewEmail will create a new email for the given assignment

func (*Email) Send

func (e *Email) Send(config *Config, from string, to []string) error

Send will use the configuration to send an email.

type Info

type Info struct {
	Description    string  `json:"description"`     // Description of the license
	CurrentUsers   int     `json:"current_users"`   // Curent number of users for this license
	MaxUsers       int     `json:"max_users"`       // Maximum number of users for this license
	RemainingUsers int     `json:"remaining_users"` // Remaining number of users for this license
	FillRatio      float64 `json:"fill_ratio"`      // How 'full' our sales are
}

Info type is used to validate a License entry and find out various facts about it.

type Manager

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

A Manager instace is responsible for the DB connection, and assigning license users as well as the input of new licenses.

func NewManager

func NewManager(configFilename string) (*Manager, error)

NewManager will create a new manager instance and start the ball rolling

func (*Manager) AssignLicense

func (m *Manager) AssignLicense(accountID, licenseID string) (string, error)

AssignLicense will attempt to assign the license_id to account_id, returning the UUID for the new subscription if successful.

func (*Manager) Close

func (m *Manager) Close()

Close will close any underlying connections and resources

func (*Manager) CreateLicense

func (m *Manager) CreateLicense(id string, maxUsers int, desc string) error

CreateLicense will attempt to create the new named license within the database for subscription by users.

func (*Manager) GetInfo

func (m *Manager) GetInfo(licenseID string) (*Info, error)

GetInfo will return information for the given license ID

Jump to

Keyboard shortcuts

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