Documentation ¶
Overview ¶
Copyright 2017 Applatix, Inc.
Copyright 2017 Applatix, Inc.
Copyright 2017 Applatix, Inc.
Index ¶
- Constants
- type AWSAccountInfo
- type AWSProductInfo
- type Bucket
- type Configuration
- type Report
- type SessionInfo
- type SessionManager
- func (s *SessionManager) DeleteSession(w http.ResponseWriter, r *http.Request)
- func (s *SessionManager) SetSession(user *User, w http.ResponseWriter, r *http.Request) error
- func (s *SessionManager) UpdateSessionKeys(authKey, cryptKey []byte)
- func (s *SessionManager) ValidateSession(w http.ResponseWriter, r *http.Request) (*SessionInfo, error)
- type Tx
- func (tx *Tx) AddBucket(reportID string, b *Bucket) (string, error)
- func (tx *Tx) AddReportAccount(reportID string, accountID string) error
- func (tx *Tx) CreateUser(username, password string) (*User, error)
- func (tx *Tx) CreateUserReport(userID string, r *Report) (string, error)
- func (tx *Tx) DeleteBucket(bucket Bucket) error
- func (tx *Tx) DeleteReportAccount(reportID, accountID string) error
- func (tx *Tx) DeleteUserReport(userID string, reportID string) error
- func (tx *Tx) GetAWSAccounts(reportID string) ([]*AWSAccountInfo, error)
- func (tx *Tx) GetBucket(bucketID string) (*Bucket, error)
- func (tx *Tx) GetConfiguration() (*Configuration, error)
- func (tx *Tx) GetProduct(productCode string) (*AWSProductInfo, error)
- func (tx *Tx) GetProducts() ([]*AWSProductInfo, error)
- func (tx *Tx) GetReportBuckets(reportID string) ([]*Bucket, error)
- func (tx *Tx) GetReports() ([]*Report, error)
- func (tx *Tx) GetUserByID(userID string) (*User, error)
- func (tx *Tx) GetUserByUsername(username string) (*User, error)
- func (tx *Tx) GetUserDefaultReport(userID string) (*Report, error)
- func (tx *Tx) GetUserReport(userID string, reportID string) (*Report, error)
- func (tx *Tx) GetUserReports(userID string) ([]*Report, error)
- func (tx *Tx) RotateSessionKey() (*Configuration, error)
- func (tx *Tx) UpdateBucket(bucket Bucket) error
- func (tx *Tx) UpdateConfiguration(configUpdates *Configuration) (*Configuration, bool, error)
- func (tx *Tx) UpdateReportAcccount(account *AWSAccountInfo) (*AWSAccountInfo, error)
- func (tx *Tx) UpdateUser(u *User) (*User, error)
- func (tx *Tx) UpdateUserReport(r *Report) error
- func (tx *Tx) UpdateUserReportMtime(reportID string) error
- func (tx *Tx) UpdateUserReportStatus(reportID string, status claudia.ReportStatus, statusDetail string) error
- func (tx *Tx) UpsertProduct(product *AWSProductInfo) error
- type User
- type UserDatabase
- func (db *UserDatabase) AuthenticateUser(username, password string) (*User, error)
- func (db *UserDatabase) Begin() (*Tx, error)
- func (db *UserDatabase) Drop() error
- func (db *UserDatabase) GetProductAliases() (map[string]*AWSProductInfo, error)
- func (db *UserDatabase) Init() error
- func (db *UserDatabase) NewSessionManager(authKey, cryptKey []byte) *SessionManager
- func (db *UserDatabase) Wait()
Constants ¶
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
type SessionInfo ¶
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 ¶
Tx is a wrapper around Tx to provide querying interfaces against the user database
func (*Tx) AddReportAccount ¶
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 ¶
CreateUser creates a new user. Returns an error if user is invalid or the tx fails.
func (*Tx) CreateUserReport ¶
CreateUserReport create the report owned by the user
func (*Tx) DeleteBucket ¶
DeleteBucket deletes a bucket from a report
func (*Tx) DeleteReportAccount ¶
DeleteReportAccount deletes an AWS account associated with a report. This will only be called by ingestd, not by user
func (*Tx) DeleteUserReport ¶
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) 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 ¶
GetReportBuckets returns all buckets associated with a report
func (*Tx) GetReports ¶
GetReports retrieves the report owned by the user
func (*Tx) GetUserByID ¶
GetUserByID retrieves a User by ID
func (*Tx) GetUserByUsername ¶
GetUserByUsername retrieves a User by username
func (*Tx) GetUserDefaultReport ¶
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 ¶
GetUserReport retrieves the specified report owned by the user
func (*Tx) GetUserReports ¶
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 ¶
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 ¶
UpdateUser updates user information. Returns an error if user is invalid or the tx fails.
func (*Tx) UpdateUserReport ¶
UpdateUserReport applies updates to a report
func (*Tx) UpdateUserReportMtime ¶
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 ¶
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) 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