model

package
v0.0.0-...-e2863eb Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Index

Constants

View Source
const (
	MinPasswordLength = 8
)

Variables

View Source
var (
	PlanList       = []Plan{}
	PlanNameToPlan = map[string]*Plan{}
)
View Source
var (
	ErrPasswordTooShort = errors.Errorf(
		"password: must be minimum %d characters long",
		MinPasswordLength,
	)
	ErrEmptyUpdate = errors.New("no update information provided")
)

Functions

func LoadPlans

func LoadPlans(filepath string) error

LoadPlans loads Plan definitions from filePath. This function also checks for the validity of the definitions.

func ValidateKeys

func ValidateKeys(value interface{}) error

func ValidatePlanName

func ValidatePlanName(name string) error

Types

type ETag

type ETag [12]byte
var (
	ETagNil ETag
)

func (*ETag) Increment

func (t *ETag) Increment()

func (ETag) MarshalText

func (t ETag) MarshalText() (b []byte, err error)

func (ETag) String

func (t ETag) String() string

func (*ETag) UnmarshalText

func (t *ETag) UnmarshalText(b []byte) error

type Email

type Email string

func (*Email) UnmarshalJSON

func (email *Email) UnmarshalJSON(b []byte) error

func (Email) Validate

func (email Email) Validate() error

type Features

type Features struct {
	// RBAC
	RBAC bool `json:"rbac" bson:"rbac"`

	// audit logs
	AuditLogs bool `json:"audit_logs" bson:"audit_logs"`

	// dynamic groups
	DynamicGroups bool `json:"dynamic_groups" bson:"dynamic_groups"`

	// remote terminal
	Terminal bool `json:"terminal" bson:"terminal"`

	// file transfer
	FileTransfer bool `json:"file_transfer" bson:"file_transfer"`

	// configuration
	Configuration bool `json:"configuration" bson:"configuration"`

	// monitoring
	Monitoring bool `json:"monitoring" bson:"monitoring"`

	// reporting
	Reporting bool `json:"reporting" bson:"reporting"`
}

type NewTenant

type NewTenant struct {
	ID string `json:"tenant_id"`
}

func (NewTenant) Validate

func (nt NewTenant) Validate() error

type PersonalAccessToken

type PersonalAccessToken struct {
	// system-generated user ID
	ID oid.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
	// token name
	Name *string `json:"name,omitempty" on:"name,omitempty"`
	// timestamp of the last usage
	LastUsed *time.Time `json:"last_used,omitempty" bson:"last_used,omitempty"`
	// the absolute time when the token expires.
	ExpirationDate *jwt.Time `json:"expiration_date,omitempty" bson:"exp,omitempty"`
	// CreatedTs is the absolute time the token was created.
	CreatedTs jwt.Time `json:"created_ts,omitempty" bson:"iat,omitempty"`
}

func (PersonalAccessToken) MarshalJSON

func (t PersonalAccessToken) MarshalJSON() ([]byte, error)

type Plan

type Plan struct {
	// unique name used as identifier
	Name string `json:"name" bson:"_id"`

	// name to display
	DisplayName string `json:"display_name" bson:"display_name"`

	// feature set
	Features *Features `json:"features" bson:"features"`
}

func (*Plan) Validate

func (p *Plan) Validate() error

type PlanBinding

type PlanBinding struct {
	// tenant can only have single plan binding
	TenantID string `json:"-" bson:"_id"`

	// plan name
	PlanName string `json:"plan_name" bson:"plan_name"`

	// limits
	Limits *PlanLimits `json:"limits,omitempty" bson:"limits,omitempty"`
}

type PlanBindingDetails

type PlanBindingDetails struct {
	// tenant can only have single plan binding
	TenantID string `json:"-" bson:"_id"`

	// plan name
	Plan Plan `json:"plan" bson:"plan"`

	// limits
	Limits *PlanLimits `json:"limits,omitempty" bson:"limits,omitempty"`
}

type PlanLimits

type PlanLimits struct {
	// maximum number of devices
	Devices int `json:"devices" bson:"devices"`

	// maximum number of users
	Users int `json:"users" bson:"users"`

	// audit logs history in days
	AuditLogsDays int `json:"audit_logs_days" bson:"audit_logs_days"`
}

type Settings

type Settings struct {
	ID     string         `json:"id"`
	ETag   string         `json:"etag"`
	UserID string         `json:"-"`
	Values SettingsValues `json:"-"`
}

func (Settings) MarshalBSON

func (s Settings) MarshalBSON() ([]byte, error)

func (Settings) MarshalJSON

func (s Settings) MarshalJSON() ([]byte, error)

func (*Settings) UnmarshalBSON

func (s *Settings) UnmarshalBSON(b []byte) error

func (*Settings) UnmarshalJSON

func (s *Settings) UnmarshalJSON(b []byte) error

func (Settings) Validate

func (s Settings) Validate() error

type SettingsValues

type SettingsValues map[string]interface{}

type TokenRequest

type TokenRequest struct {
	Name      *string `json:"name"`
	ExpiresIn int64   `json:"expires_in"`
}

func (TokenRequest) Validate

func (tr TokenRequest) Validate(maxExpiration int) error

type User

type User struct {
	// system-generated user ID
	ID string `json:"id" bson:"_id"`

	// ETag is the entity tag that together with ID uniquely identifies
	// the User document.
	// NOTE: The v1 API does not support ETags, so this is only used
	// internally for checking pre-conditions before performing updates.
	ETag *ETag `json:"-" bson:"etag,omitempty"`

	// user email address
	Email Email `json:"email" bson:"email"`

	// user password
	Password string `json:"password,omitempty" bson:"password"`

	// timestamp of the user creation
	CreatedTs *time.Time `json:"created_ts,omitempty" bson:"created_ts,omitempty"`

	// timestamp of the last user information update
	UpdatedTs *time.Time `json:"updated_ts,omitempty" bson:"updated_ts,omitempty"`

	// LoginTs is the timestamp of the last login for this user.
	LoginTs *time.Time `json:"login_ts,omitempty" bson:"login_ts,omitempty"`
}

func (User) NextETag

func (u User) NextETag() (ret ETag)

func (User) Validate

func (u User) Validate() error

type UserFilter

type UserFilter struct {
	ID    []string `json:"id,omitempty"`
	Email []Email  `json:"email,omitempty"`

	CreatedAfter  *time.Time `json:"created_after,omitempty"`
	CreatedBefore *time.Time `json:"created_before,omitempty"`

	UpdatedAfter  *time.Time `json:"updated_after,omitempty"`
	UpdatedBefore *time.Time `json:"updated_before,omitempty"`
}

func (*UserFilter) ParseForm

func (fltr *UserFilter) ParseForm(form url.Values) error

type UserInternal

type UserInternal struct {
	User
	PasswordHash string `json:"password_hash,omitempty" bson:"-"`
	Propagate    *bool  `json:"propagate,omitempty" bson:"-"`
}

func (UserInternal) ShouldPropagate

func (u UserInternal) ShouldPropagate() bool

func (UserInternal) Validate

func (u UserInternal) Validate() error

type UserUpdate

type UserUpdate struct {
	// ETag selects user ETag for the user to update
	// NOTE: This is the only parameter that goes into the query condition if set.
	// NOTE: If set to ETagNil, it will match users without an ETag.
	ETag *ETag `json:"-" bson:"-"`

	// ETagUpdate sets the updated ETag value. If not set, it is incremented from the
	// ETag field if that field is set.
	ETagUpdate *ETag `json:"-" bson:"etag,omitempty"`

	// user email address
	Email Email `json:"email,omitempty" bson:",omitempty" valid:"email"`

	// user password
	Password string `json:"password,omitempty" bson:"password,omitempty"`

	// user password
	CurrentPassword string `json:"current_password,omitempty" bson:"-"`

	// timestamp of the last user information update
	UpdatedTs *time.Time `json:"-" bson:"updated_ts,omitempty"`

	// token used to update the user, optional
	Token *jwt.Token `json:"-" bson:"-"`

	LoginTs *time.Time `json:"-" bson:"login_ts,omitempty"`
}

func (UserUpdate) Validate

func (u UserUpdate) Validate() error

Jump to

Keyboard shortcuts

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