2016-08-18 21:16:44 +00:00
|
|
|
package datastore
|
|
|
|
|
|
|
|
import (
|
2016-10-04 20:34:36 +00:00
|
|
|
"reflect"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
2016-08-18 21:16:44 +00:00
|
|
|
"testing"
|
|
|
|
|
2017-02-01 17:20:50 +00:00
|
|
|
"github.com/kolide/kolide/server/kolide"
|
2016-08-18 21:16:44 +00:00
|
|
|
)
|
|
|
|
|
2016-10-04 20:34:36 +00:00
|
|
|
func functionName(f func(*testing.T, kolide.Datastore)) string {
|
|
|
|
fullName := runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
|
|
|
|
elements := strings.Split(fullName, ".")
|
|
|
|
return elements[len(elements)-1]
|
|
|
|
}
|
|
|
|
|
|
|
|
var testFunctions = [...]func(*testing.T, kolide.Datastore){
|
|
|
|
testOrgInfo,
|
|
|
|
testCreateInvite,
|
2016-12-20 21:31:09 +00:00
|
|
|
testInviteByEmail,
|
2016-12-30 01:58:12 +00:00
|
|
|
testInviteByToken,
|
2016-11-16 13:47:49 +00:00
|
|
|
testListInvites,
|
|
|
|
testDeleteInvite,
|
|
|
|
testSaveInvite,
|
2016-10-04 20:34:36 +00:00
|
|
|
testDeleteQuery,
|
2016-12-09 17:12:45 +00:00
|
|
|
testDeleteQueries,
|
2016-10-04 20:34:36 +00:00
|
|
|
testSaveQuery,
|
2016-11-16 13:47:49 +00:00
|
|
|
testListQuery,
|
2016-10-04 20:34:36 +00:00
|
|
|
testDeletePack,
|
|
|
|
testEnrollHost,
|
|
|
|
testAuthenticateHost,
|
|
|
|
testLabels,
|
|
|
|
testManagingLabelsOnPacks,
|
|
|
|
testPasswordResetRequests,
|
|
|
|
testCreateUser,
|
|
|
|
testSaveUser,
|
|
|
|
testUserByID,
|
|
|
|
testPasswordResetRequests,
|
2016-11-02 14:59:53 +00:00
|
|
|
testSearchHosts,
|
|
|
|
testSearchHostsLimit,
|
|
|
|
testSearchLabels,
|
|
|
|
testSearchLabelsLimit,
|
|
|
|
testListHostsInLabel,
|
|
|
|
testListUniqueHostsInLabels,
|
2016-11-09 23:33:16 +00:00
|
|
|
testDistributedQueriesForHost,
|
2016-11-16 13:47:49 +00:00
|
|
|
testSaveHosts,
|
|
|
|
testDeleteHost,
|
|
|
|
testListHost,
|
2016-11-22 21:56:05 +00:00
|
|
|
testGetHostsInPack,
|
2016-11-23 00:35:43 +00:00
|
|
|
testDistributedQueryCampaign,
|
2016-12-01 18:31:16 +00:00
|
|
|
testCleanupDistributedQueryCampaigns,
|
2016-11-25 18:08:22 +00:00
|
|
|
testBuiltInLabels,
|
2016-12-06 18:22:28 +00:00
|
|
|
testLoadPacksForQueries,
|
2016-12-13 22:22:05 +00:00
|
|
|
testScheduledQuery,
|
|
|
|
testDeleteScheduledQuery,
|
|
|
|
testListScheduledQueriesInPack,
|
|
|
|
testSaveScheduledQuery,
|
2016-12-29 18:32:28 +00:00
|
|
|
testOptions,
|
2016-12-22 19:29:29 +00:00
|
|
|
testNewScheduledQuery,
|
2016-12-31 17:56:54 +00:00
|
|
|
testOptionsToConfig,
|
2017-01-13 18:35:25 +00:00
|
|
|
testGetPackByName,
|
|
|
|
testGetQueryByName,
|
|
|
|
testDecorators,
|
|
|
|
testFileIntegrityMonitoring,
|
|
|
|
testYARAStore,
|
Add host_ids and label_ids fields to the packs API (#737)
This PR adds the `host_ids` and `label_ids` field to the packs HTTP API so that one can operate on the hosts/labels which a pack is scheduled to be executed on. This replaces (and deletes) the `/api/v1/kolide/packs/123/labels/456` API in favor of `PATCH /api/v1/packs/123` and specifying the `label_ids` field. This also allows for bulk operations.
Consider the following API examples:
## Creating a pack with a known set of hosts and labels
The key addition is the `host_ids` and `label_ids` field in both the request and the response.
### Request
```
POST /api/v1/kolide/packs
```
```json
{
"name": "My new pack",
"description": "The newest of the packs",
"host_ids": [1, 2, 3],
"label_ids": [1, 3, 5]
}
```
### Response
```json
{
"pack": {
"id": 123,
"name": "My new pack",
"description": "The newest of the packs",
"platform": "",
"created_by": 1,
"disabled": false,
"query_count": 0,
"total_hosts_count": 5,
"host_ids": [1, 2, 3],
"label_ids": [1, 3, 5]
}
}
```
## Modifying the hosts and/or labels that a pack is scheduled to execute on
### Request
```
PATCH /api/v1/kolide/packs/123
```
```json
{
"host_ids": [1, 2, 3, 4, 5],
"label_ids": [1, 3, 5, 7]
}
```
### Response
```json
{
"pack": {
"id": 123,
"name": "My new pack",
"description": "The newest of the packs",
"platform": "",
"created_by": 1,
"disabled": false,
"query_count": 0,
"total_hosts_count": 5,
"host_ids": [1, 2, 3, 4, 5],
"label_ids": [1, 3, 5, 7]
}
}
```
close #633
2017-01-03 17:32:06 +00:00
|
|
|
testAddLabelToPackTwice,
|
2017-01-04 21:16:17 +00:00
|
|
|
testGenerateHostStatusStatistics,
|
|
|
|
testMarkHostSeen,
|
2017-01-16 22:20:15 +00:00
|
|
|
testDuplicateNewQuery,
|
2017-01-20 17:22:33 +00:00
|
|
|
testIdempotentDeleteHost,
|
2017-01-27 13:35:58 +00:00
|
|
|
testChangeEmail,
|
2017-02-02 20:30:59 +00:00
|
|
|
testLicense,
|
2017-02-12 04:27:43 +00:00
|
|
|
testSaveLabel,
|
2017-02-24 22:37:47 +00:00
|
|
|
testFlappingNetworkInterfaces,
|
2017-02-25 01:47:30 +00:00
|
|
|
testReplaceDeletedLabel,
|
2017-03-08 17:17:07 +00:00
|
|
|
testMigrationStatus,
|
2017-03-08 17:29:25 +00:00
|
|
|
testUnicode,
|
2017-03-30 15:31:28 +00:00
|
|
|
testCountHostsInTargets,
|
2017-03-30 23:56:11 +00:00
|
|
|
testResetOptions,
|
2016-10-03 03:14:35 +00:00
|
|
|
}
|