Skip to content

Repository files navigation

ProvisionProvision ReleaseGo Report CardGoDocDocker Container Image SizeDocker Container Layers

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, user and asset. Provision is intended as a fundamental dependency of current and future TXN2 platform services.

  • Elasticsearch is used as a database for Account, User and Asset objects.
  • Intended for basic storage, retrieval and searching.

Provision is intended as in internal service to be accessed by other services. Use a secure reverse proxy for direct access by system operators.

Configuration

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

FlagEnvironment VariableDescription
-esServerELASTIC_SERVERElasticsearch Server (default "http://elasticsearch:9200")
-systemPrefixSYSTEM_PREFIXPrefix for system indices. (default "system_")

Routes

MethodRoute PatternDescription
GET/prefixGet the prefix used for Elasticsearch indexes.
POST/accountUpsert an Account object.
GET/account/:idGet an Account ojbect by id.
POST/keyCheck/:idCheck if an AccessKey is associated with an account.
POST/searchAccountsSearch for Accounts with a Lucene query.
POST/userUpsert a User object.
GET/user/:idGet a User object by id.
POST/searchUsersSearch for Users with a Lucene query.
POST/userHasAccessPost an AccessCheck object with Token to determine basic access.
POST/userHasAdminAccessPost an AccessCheck object with Token to determine admin access.
POST/authUserPost Credentials and if valid receive a Token.
POST/assetUpsert an Asset.
GET/asset/:idGet an asset by id.
POST/searchAssetsSearch for Assets with a Lucene query.
GET/adm/:parentAccount/account/:accountGet a child account.
POST/adm/:parentAccount/accountUpsert a child account.
GET/adm/:parentAccount/childrenGet children of parent account.
GET/adm/:parentAccount/assets/:accountGet assets with associations to account.
GET/adm/:parrentId/assetAssoc/:asset/:accountFrom/:accountToRe-associate any routes from specified account to another (child or self)

Development

Testing using Elasticsearch and Kibana in docker compose:

docker-compose up

Run for source:

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

Examples

Util

Get Prefix

curl http://localhost:8080/prefix

Account

Upsert Account

curl -X POST \
http://localhost:8080/account \
-H 'Content-Type: application/json' \
-d '{ "id": "test_account", "description": "This is a test account", "display_name": "Test Organization", "active": true, "access_keys": [ { "name": "test-data", "key": "sRqhFPdudA9s8qtVqgixHXyU8ubbYhrCBttC8amLdMwkxeZHskseNXyCRe4eXRxP", "description": "Generic access key", "active": true }, { "name": "test", "key": "PDWgYr3bQGNoLptBRDkLTGQcRmCMqLGRFpXoXJ8xMPsMLMg3LHvWpJgDu2v3LYBA", "description": "Generic access key 2", "active": true } ], "modules": [ "telematics", "wx", "data_science", "gpu" ]}'

Get Account

curl http://localhost:8080/account/test_account

Search Accounts

curl -X POST \
http://localhost:8080/searchAccounts \
-d '{ "query": { "match_all": {} }}'

Check Key

curl -X POST \
http://localhost:8080/keyCheck/test_account \
-H 'Content-Type: application/json' \
-d '{ 	"name": "test_data", 	"key": "sRqhFPdudA9s8qtVqgixHXyU8ubbYhrCBttC8amLdMwkxeZHskseNXyCRe4eXRxP"}'

User

Upsert User

curl -X POST \
http://localhost:8080/user \
-H 'Content-Type: application/json' \
-d '{	"id": "test_user",	"description": "Test User non-admin",	"display_name": "Test User",	"active": true,	"sysop": false,	"password": "eWidL7UtiWJABHgn8WAv8MWbqNKjHUqhNC7ZaWotEFKYNrLvzAwwCXC9eskPFJoY",	"sections_all": false,	"sections": ["api", "config", "data"],	"accounts": ["test"],	"admin_accounts": []}'

Get User

curl -X GET http://localhost:8080/user/test_user

Search Users

curl -X POST \
http://localhost:8080/searchUsers \
-d '{ "query": { "match_all": {} }}'

Authenticate User

curl -X POST \
http://localhost:8080/authUser \
-H 'Content-Type: application/json' \
-d '{	"id": "test_user",	"password": "eWidL7UtiWJABHgn8WAv8MWbqNKjHUqhNC7ZaWotEFKYNrLvzAwwCXC9eskPFJoY"}'

Access Check

# first get a token
TOKEN=$(curl -s -X POST \ http://localhost:8080/authUser?raw=true \ -d '{ "id": "test_user", "password": "eWidL7UtiWJABHgn8WAv8MWbqNKjHUqhNC7ZaWotEFKYNrLvzAwwCXC9eskPFJoY" }')&&echo$TOKEN# check for basic access
curl -X POST \
http://localhost:8080/userHasAccess \
-H "Authorization: Bearer $TOKEN" \
-d '{	"sections": ["api"],	"accounts": ["test"]}'# check for admin access
curl -X POST \
http://localhost:8080/userHasAdminAccess \
-H "Authorization: Bearer $TOKEN" \
-d '{	"sections": ["api"],	"accounts": ["test"]}'

Asset

Upsert Asset

curl -X POST \
http://localhost:8080/asset \
-H 'Content-Type: application/json' \
-d '{	"id": "test-unique-asset-id-12345",	"description": "A unique asset in the system.",	"display_name": "Asset 12345",	"active": true,	"asset_class": "iot_device",	"routes": [ { "account_id": "test", "model_id": "device_details", type: "system" }, { "account_id": "test", "model_id": "device_location", type: "account" }	]}'

Get Asset

curl -X GET http://localhost:8080/asset/test-unique-asset-id-12345

Search Assets

curl -X POST \
http://localhost:8080/searchAssets \
-H 'Content-Type: application/json' \
-d '{ "query": { "match_all": {} }}'

Release Packaging

Build test release:

goreleaser --skip-publish --rm-dist --skip-validate

Build and release:

GITHUB_TOKEN=$GITHUB_TOKEN goreleaser --rm-dist

About

WIP: User and Account micro-platform.

Resources

Stars

8 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages