Add bash script that creates 3 teams and 12 users to /tools/api (#779)

- Add a bash script that populates the Fleet UI with 3 teams and 12 users. 
- Rename the `/tools/api/kolide` directory to `/tools/api/fleet`
This commit is contained in:
noahtalerman 2021-05-17 19:11:11 -04:00 committed by GitHub
parent 85d9d00096
commit e18ab29906
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 235 additions and 6 deletions

View File

@ -3,6 +3,7 @@
- [End-to-end tests](#end-to-end-tests)
- [Email](#email)
- [Database backup/restore](#database-backuprestore)
- [Teams seed data](#teams-seed-data)
- [MySQL shell](#mysql-shell)
- [Testing SSO](#testing-sso)
@ -170,6 +171,29 @@ Restore:
Note that a "restore" will replace the state of the development database with the state from the backup.
## Teams seed data
When developing on both the `master` and `teams` branches, it may be useful to create seed data that includes users and teams. This can be achieved with the following steps:
First, create a `env` file with the following contents:
```
export SERVER_URL=https://localhost:8080 # your fleet server url and port
export CURL_FLAGS='-k -s' # set insecure flag
export TOKEN=eyJhbGciOi... # your login token
```
Next, set the `FLEET_ENV_PATH` to point to the `env` file. This will let the scripts in the `fleet/` folder source the env file.
```
export FLEET_ENV_PATH=/Users/victor/fleet_env
```
Finally run the `teams/create` bash script located in the [/tools/api](../../tools/api/README.md) directory. This script will create 3 teams and 12 users with various roles.
```
./tools/api/fleet/teams/create
```
## MySQL shell
Connect to the MySQL shell to view and interact directly with the contents of the development database.

View File

@ -7,7 +7,7 @@ export CURL_FLAGS='-k -s' # set insecure flag
export TOKEN=eyJhbGciOi... # your login token
```
Next set the `FLEET_ENV_PATH` to point to the `env` file. This will let the scripts in the `kolide/` folder source the env file.
Next set the `FLEET_ENV_PATH` to point to the `env` file. This will let the scripts in the `fleet/` folder source the env file.
# Examples
@ -15,7 +15,7 @@ Next set the `FLEET_ENV_PATH` to point to the `env` file. This will let the scri
export FLEET_ENV_PATH=/Users/victor/fleet_env
# get my user info
./tools/api/kolide/me
./tools/api/fleet/me
{
"user": {
"created_at": "2018-04-10T02:07:46Z",
@ -33,7 +33,7 @@ export FLEET_ENV_PATH=/Users/victor/fleet_env
}
# list queries
./tools/api/kolide/queries/list
./tools/api/fleet/queries/list
{
"queries": []
}
@ -43,7 +43,7 @@ export FLEET_ENV_PATH=/Users/victor/fleet_env
2
# create a query
./tools/api/kolide/queries/create 'system_info' 'select * from system_info;'
./tools/api/fleet/queries/create 'system_info' 'select * from system_info;'
{
"query": {
"created_at": "0001-01-01T00:00:00Z",
@ -60,8 +60,9 @@ export FLEET_ENV_PATH=/Users/victor/fleet_env
}
# add query with id=4 to pack with id=2
./tools/api/kolide/schedule/add_query_to_pack 2 4
./tools/api/fleet/schedule/add_query_to_pack 2 4
# get scheduled queries in a pack
./tools/api/kolide/packs/scheduled 2 | jq '.scheduled[]|{"name": .name, "schedule_id": .id, "query_id": .query_id}'
./tools/api/fleet/packs/scheduled 2 | jq '.scheduled[]|{"name": .name, "schedule_id": .id, "query_id": .query_id}'
```

View File

@ -0,0 +1,204 @@
#!/bin/bash
# This script creates 3 teams and 12 users with various roles.
source $FLEET_ENV_PATH
# Create teams
create_team_endpoint="api/v1/fleet/teams"
# Create Client Platform Engineering
data='{
"name": "Client Platform Engineering"
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_team_endpoint" -d "$data" --insecure
# Security Engineering
data='{
"name": "Security Engineering"
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_team_endpoint" -d "$data" --insecure
# Site Reliability Engineering
data='{
"name": "Site Reliability Engineering"
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_team_endpoint" -d "$data" --insecure
# Create users
create_user_endpoint="api/v1/fleet/users/admin"
# Create Andre Verot
data='{
"name": "Andre Verot",
"username": "Andre Verot",
"email": "andre@thecompany.com",
"password": "user123#",
"invited_by": 1,
"global_role": null,
"teams": [
{
"id": 1,
"role": "observer"
}
]
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_user_endpoint" -d "$data" --insecure
# Create Joanne Jackson
data='{
"name": "Joanne Jackson",
"username": "Joanne Jackson",
"email": "jo@thecompany.com",
"password": "user123#",
"invited_by": 1,
"global_role": null,
"teams": [
{
"id": 2,
"role": "maintainer"
}
]
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_user_endpoint" -d "$data" --insecure
# Create Cheryl Gardner
data='{
"name": "Cheryl Gardner",
"username": "Cheryl Gardner",
"email": "cheryl87@domain.tld",
"password": "user123#",
"invited_by": 1,
"global_role": null,
"teams": [
{
"id": 3,
"role": "observer"
}
]
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_user_endpoint" -d "$data" --insecure
# Create Lisa Walsh
data='{
"name": "Lisa Walsh",
"username": "Lisa Walsh",
"email": "lisa_walsh@domain.com",
"password": "user123#",
"invited_by": 1,
"global_role": null,
"teams": [
{
"id": 1,
"role": "observer"
},
{
"id": 2,
"role": "maintainer"
},
{
"id": 3,
"role": "maintainer"
}
]
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_user_endpoint" -d "$data" --insecure
# Create Christopher Mitchell
data='{
"name": "Christopher Mitchell",
"username": "Christopher Mitchell",
"email": "christopher98@thecompany.com",
"password": "user123#",
"invited_by": 1,
"global_role": "admin"
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_user_endpoint" -d "$data" --insecure
# Create Kai Boucher
data='{
"name": "Kai Boucher",
"username": "Kai Boucher",
"email": "boucher_@thecompany.com",
"password": "user123#",
"invited_by": 1,
"global_role": null
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_user_endpoint" -d "$data" --insecure
# Create Henry Lewis
data='{
"name": "Henry Lewis",
"username": "Henry Lewis",
"email": "henry.lewis@thecompany.com",
"password": "user123#",
"invited_by": 1,
"global_role": null,
"teams": [
{
"id": 1,
"role": "observer"
}
]
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_user_endpoint" -d "$data" --insecure
# Create Shintaro Sato
data='{
"name": "Shintaro Sato",
"username": "Shintaro Sato",
"email": "shin-sato@thecompany.com",
"password": "user123#",
"invited_by": 1,
"global_role": null,
"teams": [
{
"id": 1,
"role": "observer"
},
{
"id": 3,
"role": "observer"
}
]
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_user_endpoint" -d "$data" --insecure
# Create Rosie Thomas
data='{
"name": "Rosie Thomas",
"username": "Rosie Thomas",
"email": "rosie@thecompany.com",
"password": "user123#",
"invited_by": 1,
"global_role": "maintainer"
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_user_endpoint" -d "$data" --insecure
# Create Pat Moreno
data='{
"name": "Pat Moreno",
"username": "Pat Moreno",
"email": "pat-moreno@thecompany.com",
"password": "user123#",
"invited_by": 1,
"global_role": null,
"teams": [
{
"id": 3,
"role": "maintainer"
}
]
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_user_endpoint" -d "$data" --insecure
# Create Mohammad Patel
data='{
"name": "Mohammad Patel",
"username": "Mohammad Patel",
"email": "mo-patel@thecompany.com",
"password": "user123#",
"invited_by": 1,
"global_role": "observer"
}'
curl -X POST $CURL_FLAGS -H "Authorization: Bearer $TOKEN" "$SERVER_URL/$create_user_endpoint" -d "$data" --insecure