diff --git a/docs/3-Contribution/2-Testing.md b/docs/3-Contribution/2-Testing.md index b334213da..5582ba482 100644 --- a/docs/3-Contribution/2-Testing.md +++ b/docs/3-Contribution/2-Testing.md @@ -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. diff --git a/tools/api/README.md b/tools/api/README.md index 723150922..9517c4fb3 100644 --- a/tools/api/README.md +++ b/tools/api/README.md @@ -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}' ``` + diff --git a/tools/api/kolide/me b/tools/api/fleet/me similarity index 100% rename from tools/api/kolide/me rename to tools/api/fleet/me diff --git a/tools/api/kolide/packs/create b/tools/api/fleet/packs/create similarity index 100% rename from tools/api/kolide/packs/create rename to tools/api/fleet/packs/create diff --git a/tools/api/kolide/packs/list b/tools/api/fleet/packs/list similarity index 100% rename from tools/api/kolide/packs/list rename to tools/api/fleet/packs/list diff --git a/tools/api/kolide/packs/scheduled b/tools/api/fleet/packs/scheduled similarity index 100% rename from tools/api/kolide/packs/scheduled rename to tools/api/fleet/packs/scheduled diff --git a/tools/api/kolide/queries/create b/tools/api/fleet/queries/create similarity index 100% rename from tools/api/kolide/queries/create rename to tools/api/fleet/queries/create diff --git a/tools/api/kolide/queries/list b/tools/api/fleet/queries/list similarity index 100% rename from tools/api/kolide/queries/list rename to tools/api/fleet/queries/list diff --git a/tools/api/kolide/schedule/add_query_to_pack b/tools/api/fleet/schedule/add_query_to_pack similarity index 100% rename from tools/api/kolide/schedule/add_query_to_pack rename to tools/api/fleet/schedule/add_query_to_pack diff --git a/tools/api/kolide/schedule/delete_scheduled_query b/tools/api/fleet/schedule/delete_scheduled_query similarity index 100% rename from tools/api/kolide/schedule/delete_scheduled_query rename to tools/api/fleet/schedule/delete_scheduled_query diff --git a/tools/api/fleet/teams/create b/tools/api/fleet/teams/create new file mode 100644 index 000000000..e0d6dbd00 --- /dev/null +++ b/tools/api/fleet/teams/create @@ -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