{"id":28405989,"url":"https://github.com/txn2/provision","last_synced_at":"2025-08-01T10:35:41.330Z","repository":{"id":57552054,"uuid":"181066807","full_name":"txn2/provision","owner":"txn2","description":"WIP: User and Account micro-platform.","archived":false,"fork":false,"pushed_at":"2019-07-19T07:08:44.000Z","size":201,"stargazers_count":8,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-29T07:41:22.180Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/txn2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-12T18:53:04.000Z","updated_at":"2020-07-06T19:48:20.000Z","dependencies_parsed_at":"2022-09-26T18:50:32.724Z","dependency_job_id":null,"html_url":"https://github.com/txn2/provision","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"purl":"pkg:github/txn2/provision","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/txn2%2Fprovision","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/txn2%2Fprovision/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/txn2%2Fprovision/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/txn2%2Fprovision/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/txn2","download_url":"https://codeload.github.com/txn2/provision/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/txn2%2Fprovision/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268207573,"owners_count":24213011,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-01T22:09:45.953Z","updated_at":"2025-08-01T10:35:41.291Z","avatar_url":"https://github.com/txn2.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Provision](https://raw.githubusercontent.com/txn2/provision/master/mast.jpg)\n[![Provision Release](https://img.shields.io/github/release/txn2/provision.svg)](https://github.com/txn2/provision/releases)\n[![Go Report Card](https://goreportcard.com/badge/github.com/txn2/provision)](https://goreportcard.com/report/github.com/txn2/provision)\n[![GoDoc](https://godoc.org/github.com/txn2/provision?status.svg)](https://godoc.org/github.com/txn2/provision)\n[![Docker Container Image Size](https://shields.beevelop.com/docker/image/image-size/txn2/provision/latest.svg)](https://hub.docker.com/r/txn2/provision/)\n[![Docker Container Layers](https://shields.beevelop.com/docker/image/layers/txn2/provision/latest.svg)](https://hub.docker.com/r/txn2/provision/)\n\n**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.\n\n- Elasticsearch is used as a database for **[Account]**, **[User]** and **[Asset]** objects.\n- Intended for basic storage, retrieval and searching.\n\n\n**Provision** is intended as in internal service to be accessed by other services. Use a secure\nreverse proxy for direct access by system operators.\n\n## Configuration\n\nConfiguration is inherited from [txn2/micro](https://github.com/txn2/micro#configuration). The\nfollowing configuration is specific to **provision**:\n\n| Flag          | Environment Variable | Description                                                |\n|:--------------|:---------------------|:-----------------------------------------------------------|\n| -esServer     | ELASTIC_SERVER       | Elasticsearch Server (default \"http://elasticsearch:9200\") |\n| -systemPrefix | SYSTEM_PREFIX        | Prefix for system indices. (default \"system_\")             |\n\n## Routes\n\n| Method | Route Pattern                                             | Description                                                               |\n|:-------|:----------------------------------------------------------|:--------------------------------------------------------------------------|\n| GET    | [/prefix](#get-prefix)                                    | Get the prefix used for Elasticsearch indexes.                            |\n| POST   | [/account](#upsert-account)                               | Upsert an Account object.                                                 |\n| GET    | [/account/:id](#get-account)                              | Get an Account ojbect by id.                                              |\n| POST   | [/keyCheck/:id](#check-key)                               | Check if an AccessKey is associated with an account.                      |\n| POST   | [/searchAccounts](#search-accounts)                       | Search for Accounts with a Lucene query.                                  |\n| POST   | [/user](#upsert-user)                                     | Upsert a User object.                                                     |\n| GET    | [/user/:id](#get-user)                                    | Get a User object by id.                                                  |\n| POST   | [/searchUsers](#search-users)                             | Search for Users with a Lucene query.                                     |\n| POST   | [/userHasAccess](#access-check)                           | Post an AccessCheck object with Token to determine basic access.          |\n| POST   | [/userHasAdminAccess](#access-check)                      | Post an AccessCheck object with Token to determine admin access.          |\n| POST   | [/authUser](#authenticate-user)                           | Post Credentials and if valid receive a Token.                            |\n| POST   | [/asset](#upsert-asset)                                   | Upsert an Asset.                                                          |\n| GET    | [/asset/:id](#get-asset)                                  | Get an asset by id.                                                       |\n| POST   | [/searchAssets](#search-assets)                           | Search for Assets with a Lucene query.                                    |\n| GET    | /adm/:parentAccount/account/:account                      | Get a child account.                                                      |\n| POST   | /adm/:parentAccount/account                               | Upsert a child account.                                                   |\n| GET    | /adm/:parentAccount/children                              | Get children of parent account.                                           |\n| GET    | /adm/:parentAccount/assets/:account                       | Get assets with associations to account.                                  |\n| GET    | /adm/:parrentId/assetAssoc/:asset/:accountFrom/:accountTo | Re-associate any routes from specified account to another (child or self) |\n\n\n## Development\n\nTesting using Elasticsearch and Kibana in docker compose:\n```bash\ndocker-compose up\n```\n\nRun for source:\n```bash\ngo run ./cmd/provision.go --esServer=\"http://localhost:9200\"\n```\n\n## Examples\n\n### Util\n\n#### Get Prefix\n```bash\ncurl http://localhost:8080/prefix\n```\n\n### Account\n\n#### Upsert Account\n```bash\ncurl -X POST \\\n  http://localhost:8080/account \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n    \"id\": \"test_account\",\n    \"description\": \"This is a test account\",\n    \"display_name\": \"Test Organization\",\n    \"active\": true,\n    \"access_keys\": [\n        {\n            \"name\": \"test-data\",\n            \"key\": \"sRqhFPdudA9s8qtVqgixHXyU8ubbYhrCBttC8amLdMwkxeZHskseNXyCRe4eXRxP\",\n            \"description\": \"Generic access key\",\n            \"active\": true\n        },\n        {\n            \"name\": \"test\",\n            \"key\": \"PDWgYr3bQGNoLptBRDkLTGQcRmCMqLGRFpXoXJ8xMPsMLMg3LHvWpJgDu2v3LYBA\",\n            \"description\": \"Generic access key 2\",\n            \"active\": true\n        }\n    ],\n    \"modules\": [\n        \"telematics\",\n        \"wx\",\n        \"data_science\",\n        \"gpu\"\n    ]\n}'\n```\n\n#### Get Account\n```bash\ncurl http://localhost:8080/account/test_account\n```\n\n#### Search Accounts\n```bash\ncurl -X POST \\\n  http://localhost:8080/searchAccounts \\\n  -d '{\n  \"query\": {\n    \"match_all\": {}\n  }\n}'\n```\n\n#### Check Key\n```bash\ncurl -X POST \\\n  http://localhost:8080/keyCheck/test_account \\\n  -H 'Content-Type: application/json' \\\n  -d '{ \n\t\"name\": \"test_data\", \n\t\"key\": \"sRqhFPdudA9s8qtVqgixHXyU8ubbYhrCBttC8amLdMwkxeZHskseNXyCRe4eXRxP\"\n}'\n```\n\n### User\n\n#### Upsert User\n```bash\ncurl -X POST \\\n  http://localhost:8080/user \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n\t\"id\": \"test_user\",\n\t\"description\": \"Test User non-admin\",\n\t\"display_name\": \"Test User\",\n\t\"active\": true,\n\t\"sysop\": false,\n\t\"password\": \"eWidL7UtiWJABHgn8WAv8MWbqNKjHUqhNC7ZaWotEFKYNrLvzAwwCXC9eskPFJoY\",\n\t\"sections_all\": false,\n\t\"sections\": [\"api\", \"config\", \"data\"],\n\t\"accounts\": [\"test\"],\n\t\"admin_accounts\": []\n}'\n```\n\n#### Get User\n```bash\ncurl -X GET http://localhost:8080/user/test_user\n```\n\n#### Search Users\n```bash\ncurl -X POST \\\n  http://localhost:8080/searchUsers \\\n  -d '{\n  \"query\": {\n    \"match_all\": {}\n  }\n}'\n```\n\n#### Authenticate User\n```bash\ncurl -X POST \\\n  http://localhost:8080/authUser \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n\t\"id\": \"test_user\",\n\t\"password\": \"eWidL7UtiWJABHgn8WAv8MWbqNKjHUqhNC7ZaWotEFKYNrLvzAwwCXC9eskPFJoY\"\n}'\n```\n\n#### Access Check\n```bash\n# first get a token\nTOKEN=$(curl -s -X POST \\\n          http://localhost:8080/authUser?raw=true \\\n          -d '{\n        \t\"id\": \"test_user\",\n        \t\"password\": \"eWidL7UtiWJABHgn8WAv8MWbqNKjHUqhNC7ZaWotEFKYNrLvzAwwCXC9eskPFJoY\"\n        }') \u0026\u0026 echo $TOKEN\n        \n# check for basic access\ncurl -X POST \\\n  http://localhost:8080/userHasAccess \\\n  -H \"Authorization: Bearer $TOKEN\" \\\n  -d '{\n\t\"sections\": [\"api\"],\n\t\"accounts\": [\"test\"]\n}'\n\n# check for admin access\ncurl -X POST \\\n  http://localhost:8080/userHasAdminAccess \\\n  -H \"Authorization: Bearer $TOKEN\" \\\n  -d '{\n\t\"sections\": [\"api\"],\n\t\"accounts\": [\"test\"]\n}'\n```\n\n### Asset\n\n#### Upsert Asset\n```bash\ncurl -X POST \\\n  http://localhost:8080/asset \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n\t\"id\": \"test-unique-asset-id-12345\",\n\t\"description\": \"A unique asset in the system.\",\n\t\"display_name\": \"Asset 12345\",\n\t\"active\": true,\n\t\"asset_class\": \"iot_device\",\n\t\"routes\": [\n\t\t{ \"account_id\": \"test\", \"model_id\": \"device_details\", type: \"system\" },\n\t\t{ \"account_id\": \"test\", \"model_id\": \"device_location\", type: \"account\" }\n\t]\n}'\n```\n\n#### Get Asset\n```bash\ncurl -X GET http://localhost:8080/asset/test-unique-asset-id-12345\n```\n\n#### Search Assets\n```bash\ncurl -X POST \\\n  http://localhost:8080/searchAssets \\\n  -H 'Content-Type: application/json' \\\n  -d '{\n  \"query\": {\n    \"match_all\": {}\n  }\n}'\n```\n\n\n\n\n## Release Packaging\n\nBuild test release:\n```bash\ngoreleaser --skip-publish --rm-dist --skip-validate\n```\n\nBuild and release:\n```bash\nGITHUB_TOKEN=$GITHUB_TOKEN goreleaser --rm-dist\n```\n\n[Account]: https://godoc.org/github.com/txn2/provision#Account\n[User]: https://godoc.org/github.com/txn2/provision#User\n[Asset]: https://godoc.org/github.com/txn2/provision#Asset","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftxn2%2Fprovision","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftxn2%2Fprovision","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftxn2%2Fprovision/lists"}