userdb

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2017 License: Apache-2.0 Imports: 18 Imported by: 5

Documentation

Overview

Copyright 2017 Applatix, Inc.

Copyright 2017 Applatix, Inc.

Copyright 2017 Applatix, Inc.

Index

Constants

View Source
const SchemaVersion = 1

SchemaVersion is the user database schema version of this version of the app

Variables

This section is empty.

Functions

This section is empty.

Types

type AWSAccountInfo

type AWSAccountInfo struct {
	AWSAccountID string `db:"aws_account_id" json:"aws_account_id"`
	Name         string `db:"name" json:"name"`
	ReportID     string `db:"report_id" json:"-"`
}

AWSAccountInfo represents an AWS account mapping of ID to name in a cost & usage report

type AWSProductInfo

type AWSProductInfo struct {
	ProductCode string `db:"product_code" json:"product_code"`
	Name        string `db:"name" json:"name"`
	Description string `db:"description" json:"description"`
}

AWSProductInfo represents information about a AWS Marketplace product

type Bucket

type Bucket struct {
	ID                 string    `db:"id" json:"id"`
	ReportID           string    `db:"report_id" json:"report_id"`
	CTime              time.Time `db:"ctime" json:"ctime"`
	Bucketname         string    `db:"bucketname" json:"bucketname"`
	Region             string    `db:"region" json:"region"`
	ReportPath         string    `db:"report_path" json:"report_path"`
	AWSAccessKeyID     string    `db:"aws_access_key_id" json:"aws_access_key_id"`
	AWSSecretAccessKey string    `db:"aws_secret_access_key" json:"aws_secret_access_key,omitempty"`
}

Bucket represents a billing bucket associated with a cost & usage report

type Configuration

type Configuration struct {
	ID                int    `db:"id" json:"-"`
	SchemaVersion     int    `db:"schema_version" json:"-"`
	SessionAuthKey    []byte `db:"session_auth_key" json:"-"`
	SessionCryptKey   []byte `db:"session_crypt_key" json:"-"`
	PrivateKey        string `db:"private_key" json:"private_key,omitempty"`
	PublicCertificate string `db:"public_certificate" json:"public_certificate"`
	EULAAccepted      bool   `db:"eula_accepted" json:"eula_accepted"`
}

Configuration is the global configuration for this app. Maps to the 'configuration' table

type Report

type Report struct {
	ID            string               `db:"id" json:"id"`
	CTime         time.Time            `db:"ctime" json:"ctime"`
	MTime         time.Time            `db:"mtime" json:"mtime"`
	Status        claudia.ReportStatus `db:"status" json:"status"`
	StatusDetail  string               `db:"status_detail" json:"status_detail"`
	OwnerUserID   string               `db:"owner_user_id" json:"owner_user_id"`
	ReportName    string               `db:"report_name" json:"report_name"`
	RetentionDays int                  `db:"retention_days" json:"retention_days"`
	Buckets       []*Bucket            `json:"buckets"`
	Accounts      []*AWSAccountInfo    `json:"accounts"`
}

Report is the struct representing a cost & usage report. Maps to the 'report' table

func (*Report) ETag

func (r *Report) ETag() string

ETag returns an HTTP ETag string to enable client side caching of report results

func (*Report) GetBucket

func (r *Report) GetBucket(bucketname, reportPath string) *Bucket

GetBucket returns the bucket in this report's bucket list with the given name and report path

type SessionInfo

type SessionInfo struct {
	UserID   string
	Username string
}

SessionInfo is the object stored in the client's encrypted session cookie

type SessionManager

type SessionManager struct {
	Store *sessions.CookieStore
	// contains filtered or unexported fields
}

SessionManager manages session state for API clients

func (*SessionManager) DeleteSession

func (s *SessionManager) DeleteSession(w http.ResponseWriter, r *http.Request)

DeleteSession will delete the user's session

func (*SessionManager) SetSession

func (s *SessionManager) SetSession(user *User, w http.ResponseWriter, r *http.Request) error

SetSession will write the session in the http response writter

func (*SessionManager) UpdateSessionKeys

func (s *SessionManager) UpdateSessionKeys(authKey, cryptKey []byte)

UpdateSessionKeys updates the session keys used by the session manager. Calling this invalidates all previously issued session tokens site-wide

func (*SessionManager) ValidateSession

func (s *SessionManager) ValidateSession(w http.ResponseWriter, r *http.Request) (*SessionInfo, error)

ValidateSession will validate the session supplied by the cookie store and return session information about the current profile

type Tx

type Tx struct {
	*sqlx.Tx
}

Tx is a wrapper around Tx to provide querying interfaces against the user database

func (*Tx) AddBucket

func (tx *Tx) AddBucket(reportID string, b *Bucket) (string, error)

AddBucket creates a new S3 billing bucket to be monitored and processed

func (*Tx) AddReportAccount

func (tx *Tx) AddReportAccount(reportID string, accountID string) error

AddReportAccount creates an account. This will only be called by ingestd, not by user. If account already exists, this is a noop

func (*Tx) CreateUser

func (tx *Tx) CreateUser(username, password string) (*User, error)

CreateUser creates a new user. Returns an error if user is invalid or the tx fails.

func (*Tx) CreateUserReport

func (tx *Tx) CreateUserReport(userID string, r *Report) (string, error)

CreateUserReport create the report owned by the user

func (*Tx) DeleteBucket

func (tx *Tx) DeleteBucket(bucket Bucket) error

DeleteBucket deletes a bucket from a report

func (*Tx) DeleteReportAccount

func (tx *Tx) DeleteReportAccount(reportID, accountID string) error

DeleteReportAccount deletes an AWS account associated with a report. This will only be called by ingestd, not by user

func (*Tx) DeleteUserReport

func (tx *Tx) DeleteUserReport(userID string, reportID string) error

DeleteUserReport deletes the report owned by the user

func (*Tx) GetAWSAccounts

func (tx *Tx) GetAWSAccounts(reportID string) ([]*AWSAccountInfo, error)

GetAWSAccounts retrieves all AWS accounts associated with a report

func (*Tx) GetBucket

func (tx *Tx) GetBucket(bucketID string) (*Bucket, error)

GetBucket updates an existing bucket credentials

func (*Tx) GetConfiguration

func (tx *Tx) GetConfiguration() (*Configuration, error)

GetConfiguration returns system configuration. If system is not configured returns nil without error

func (*Tx) GetProduct

func (tx *Tx) GetProduct(productCode string) (*AWSProductInfo, error)

GetProduct returns the product with the given code

func (*Tx) GetProducts

func (tx *Tx) GetProducts() ([]*AWSProductInfo, error)

GetProducts returns all aws marketplace products

func (*Tx) GetReportBuckets

func (tx *Tx) GetReportBuckets(reportID string) ([]*Bucket, error)

GetReportBuckets returns all buckets associated with a report

func (*Tx) GetReports

func (tx *Tx) GetReports() ([]*Report, error)

GetReports retrieves the report owned by the user

func (*Tx) GetUserByID

func (tx *Tx) GetUserByID(userID string) (*User, error)

GetUserByID retrieves a User by ID

func (*Tx) GetUserByUsername

func (tx *Tx) GetUserByUsername(username string) (*User, error)

GetUserByUsername retrieves a User by username

func (*Tx) GetUserDefaultReport

func (tx *Tx) GetUserDefaultReport(userID string) (*Report, error)

GetUserDefaultReport retrieves the default report owned by the user. Returns nil if no reports are configured Since the database currently has a constraint of one report per user, this simply returns the first row (for now).

func (*Tx) GetUserReport

func (tx *Tx) GetUserReport(userID string, reportID string) (*Report, error)

GetUserReport retrieves the specified report owned by the user

func (*Tx) GetUserReports

func (tx *Tx) GetUserReports(userID string) ([]*Report, error)

GetUserReports retrieves all reports owned by the user

func (*Tx) RotateSessionKey

func (tx *Tx) RotateSessionKey() (*Configuration, error)

RotateSessionKey rotates the system-wide session key and updates the configuration table with the new keys This is called upon a password update to invalidate sessions of all other logins. NOTE: this only works because we have a single user (admin) and need redesign upon a multi-user site

func (*Tx) UpdateBucket

func (tx *Tx) UpdateBucket(bucket Bucket) error

UpdateBucket updates an existing bucket credentials

func (*Tx) UpdateConfiguration

func (tx *Tx) UpdateConfiguration(configUpdates *Configuration) (*Configuration, bool, error)

UpdateConfiguration updates system wide configuration (e.g. EULA, public certificate, private key) Returns the updated configuration, and a boolean indicating if the certificates should be reloaded

func (*Tx) UpdateReportAcccount

func (tx *Tx) UpdateReportAcccount(account *AWSAccountInfo) (*AWSAccountInfo, error)

UpdateReportAcccount updates an existing bucket credentials

func (*Tx) UpdateUser

func (tx *Tx) UpdateUser(u *User) (*User, error)

UpdateUser updates user information. Returns an error if user is invalid or the tx fails.

func (*Tx) UpdateUserReport

func (tx *Tx) UpdateUserReport(r *Report) error

UpdateUserReport applies updates to a report

func (*Tx) UpdateUserReportMtime

func (tx *Tx) UpdateUserReportMtime(reportID string) error

UpdateUserReportMtime updates the report's modification time

func (*Tx) UpdateUserReportStatus

func (tx *Tx) UpdateUserReportStatus(reportID string, status claudia.ReportStatus, statusDetail string) error

UpdateUserReportStatus updates the report's status and mtime

func (*Tx) UpsertProduct

func (tx *Tx) UpsertProduct(product *AWSProductInfo) error

UpsertProduct returns the product with the given code

type User

type User struct {
	ID              string    `db:"id" json:"id"`
	CTime           time.Time `db:"ctime" json:"ctime"`
	MTime           time.Time `db:"mtime" json:"mtime"`
	Username        string    `db:"username" json:"username"`
	CurrentPassword string    `json:"current_password,omitempty"`
	Password        string    `json:"password,omitempty"`
	PasswordHash    []byte    `db:"password_hash" json:"-"`
}

User is an application user. Maps to the 'appuser' table

type UserDatabase

type UserDatabase struct {
	*sqlx.DB
}

UserDatabase is a wrapper around SQL DB instance and provides querying capabilities

func Open

func Open(datasource string) (*UserDatabase, error)

Open returns a DB reference for a data source.

func (*UserDatabase) AuthenticateUser

func (db *UserDatabase) AuthenticateUser(username, password string) (*User, error)

AuthenticateUser check credentials for a user. Returns an error if user is invalid or the tx fails.

func (*UserDatabase) Begin

func (db *UserDatabase) Begin() (*Tx, error)

Begin starts and returns a new transaction.

func (*UserDatabase) Drop

func (db *UserDatabase) Drop() error

Drop database

func (*UserDatabase) GetProductAliases

func (db *UserDatabase) GetProductAliases() (map[string]*AWSProductInfo, error)

GetProductAliases returns a mapping of product codes to its product info

func (*UserDatabase) Init

func (db *UserDatabase) Init() error

Init initializes or upgrade the database schema

func (*UserDatabase) NewSessionManager

func (db *UserDatabase) NewSessionManager(authKey, cryptKey []byte) *SessionManager

NewSessionManager returns a new session manager instance from the user database context

func (*UserDatabase) Wait

func (db *UserDatabase) Wait()

Wait blocks until the database is ready

Jump to

Keyboard shortcuts

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