provision

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2019 License: Apache-2.0 Imports: 8 Imported by: 8

README

Provision

Provision is a user and account micro-platform, a highly opinionated building block for TXN2 components. Provision defines basic object models that represent the foundation for an account and user. Provision is intended as a fundamental dependency of current and future TXN2 platform services.

Configuration

Configuration is inherited from txn2/ack. The following configuration is specific to provision:

Flag Environment Variable Description
-esServer ELASTIC_SERVER Elasticsearch Server (default "http://elasticsearch:9200")
-systemPrefix SYSTEM_PREFIX Prefix for system indices. (default "system_")

Development

Testing using Elasticsearch and Kibana in docker compose:

docker-compose up

Run for source:

go run ./cmd/provisison.go --esServer="http://localhost:9200"

Examples

Account

Upsert Account
curl -X POST \
  http://localhost:8080/account \
  -d '{
	"id": "xorg",
	"description": "Organization X is an IOT data collection agency.",
	"display_name": "Organization X",
	"active": true,
    "modules": [
        "telematics",
        "wx",
        "data_science",
        "gpu"
    ]
}'
Get Account
curl http://localhost:8080/account/xorg

User

Upsert User
curl -X POST \
  http://localhost:8080/user \
  -d '{
	"id": "sysop",
	"description": "Global system operator",
	"display_name": "System Operator",
	"active": true,
	"sysop": true,
	"password": "JntGihgkGRvFKmb74XgUwn7bcYpb3bPtWE8gEVTpvChEqpsFwq",
	"sections_all": false,
	"sections": [],
	"accounts": [],
	"admin_accounts": []
}'
Get User
curl http://localhost:8080/user/sysop

Documentation

Overview

Copyright 2019 txn2

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.

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.

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 EncCost = 12
View Source
const IdxAccount = "account"
View Source
const IdxUser = "user"

Variables

This section is empty.

Functions

func GetAccountMapping

func GetAccountMapping(prefix string) es.IndexTemplate

GetAccountMapping

func GetUserMapping

func GetUserMapping(prefix string) es.IndexTemplate

GetUserMapping

Types

type AccessCheck

type AccessCheck struct {
	Sections []string `json:"sections"`
	Accounts []string `json:"accounts"`
}

AccessCheck is used to configure an access check

type AccessKey

type AccessKey struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Key         string `json:"key"`
	Active      bool   `json:"active"`
}

AccessKey

type Account

type Account struct {
	Id          string      `json:"id"`
	Description string      `json:"description"`
	DisplayName string      `json:"display_name"`
	Active      bool        `json:"active"`
	Modules     []string    `json:"modules"`
	OrgId       int         `json:"org_id"`
	AccessKeys  []AccessKey `json:"access_keys"`
}

User defines a DCP user object

type AccountResult

type AccountResult struct {
	es.Result
	Source Account `json:"_source"`
}

AccountResult returned from Elastic

type Api

type Api struct {
	*Config
}

Api

func NewApi

func NewApi(cfg *Config) (*Api, error)

NewApi

func (*Api) AuthUser

func (a *Api) AuthUser(auth Auth) (bool, bool, error)

AuthUser authenticates a user with bt id and password

func (*Api) AuthUserHandler

func (a *Api) AuthUserHandler(c *gin.Context)

func (*Api) GetAccount

func (a *Api) GetAccount(id string) (int, *AccountResult, error)

GetAccount

func (*Api) GetAccountHandler

func (a *Api) GetAccountHandler(c *gin.Context)

GetAccountHandler gets an account by ID

func (*Api) GetUser

func (a *Api) GetUser(id string) (int, *UserResult, error)

GetUser

func (*Api) GetUserHandler

func (a *Api) GetUserHandler(c *gin.Context)

GetUserHandler gets a user by ID

func (*Api) SendEsMapping

func (a *Api) SendEsMapping(mapping es.IndexTemplate) error

SetupUserIndexTemplate

func (*Api) UpsertAccount

func (a *Api) UpsertAccount(account *Account) (int, es.Result, error)

UpsertAccount inserts or updates an account. Elasticsearch treats documents as immutable.

func (*Api) UpsertAccountHandler

func (a *Api) UpsertAccountHandler(c *gin.Context)

UpsertAccountHandler

func (*Api) UpsertUser

func (a *Api) UpsertUser(user *User) (int, es.Result, error)

UpsertUser inserts or updates a user record. Elasticsearch treats documents as immutable.

func (*Api) UpsertUserHandler

func (a *Api) UpsertUserHandler(c *gin.Context)

UpsertUserHandler

type Auth

type Auth struct {
	Id       string `json:"id"`
	Password string `json:"password"`
}

Auth for authenticating users

type Config

type Config struct {
	Logger     *zap.Logger
	HttpClient *ack.Client

	// used for communication with Elasticsearch
	// if nil, one will be created
	Elastic       *es.Client
	ElasticServer string

	// used to prefix the user and account indexes IdxPrefix_user, IdxPrefix_account
	// defaults to system.
	IdxPrefix string
}

Config

type User

type User struct {
	Id            string   `json:"id"`
	Description   string   `json:"description"`
	DisplayName   string   `json:"display_name"`
	Active        bool     `json:"active"`
	Sysop         bool     `json:"sysop"`
	Password      string   `json:"password"`
	Sections      []string `json:"sections"`
	SectionsAll   bool     `json:"sections_all"`
	Accounts      []string `json:"accounts"`
	AdminAccounts []string `json:"admin_accounts"`
}

User defines a user object User defines a user object

func (*User) CheckEncryptPassword

func (u *User) CheckEncryptPassword(api *Api) error

CheckEncryptPassword checks and encrypts the password inthe user object.

func (*User) HasAccess

func (u *User) HasAccess(ac *AccessCheck) bool

BasicAccess returns true is user is active and not locked

func (*User) HasAdminAccess

func (u *User) HasAdminAccess(ac *AccessCheck) bool

HasAdminAccess

func (*User) HasBasicAccess

func (u *User) HasBasicAccess() bool

BasicAccess returns true is user is active and not locked

type UserResult

type UserResult struct {
	es.Result
	Source User `json:"_source"`
}

UserResult returned from Elastic

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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