-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement GET /registration_requests and /registration_requests…
…/{id} Signed-off-by: James Ramirez <[email protected]>
- Loading branch information
Showing
10 changed files
with
283 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Table: kolide_registration_request | ||
|
||
Lists the registration requests made when attempting to register a device with Kolide. These can be approved or denied by admins. | ||
|
||
## Examples | ||
|
||
### Basic info | ||
|
||
```sql | ||
select | ||
id, | ||
status, | ||
requested_at, | ||
requester_message, | ||
requester_id, | ||
device_id | ||
from | ||
kolide_registration_request; | ||
``` | ||
|
||
### List all unresolved requests | ||
|
||
```sql | ||
select | ||
id, | ||
status, | ||
requested_at, | ||
requester_message, | ||
requester_id, | ||
device_id | ||
from | ||
kolide_registration_request | ||
where | ||
status != 'approved'; | ||
``` | ||
|
||
### List all recent requests | ||
|
||
```sql | ||
select | ||
id, | ||
status, | ||
requested_at, | ||
requester_message, | ||
requester_id, | ||
device_id | ||
from | ||
kolide_registration_request | ||
where | ||
requested_at > date_trunc('day', current_date) - interval '4 weeks'; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package kolide_client | ||
|
||
import "time" | ||
|
||
type RegistrationRequestListResponse struct { | ||
RegistrationRequests []RegistrationRequest `json:"data"` | ||
Pagination Pagination `json:"pagination"` | ||
} | ||
type RegistrationRequest struct { | ||
Id string `json:"id"` | ||
Status string `json:"status"` | ||
RequesterMessage string `json:"requester_message,omitempty"` | ||
InternalDenialNote string `json:"internal_denial_note,omitempty"` | ||
RequestedAt time.Time `json:"requested_at,omitempty"` | ||
EndUserDenialNote string `json:"end_user_denial_note,omitempty"` | ||
RequesterInformation RequesterInformation `json:"requester_information,omitempty"` | ||
DeviceInformation DeviceInformation `json:"device_information,omitempty"` | ||
} | ||
|
||
type RequesterInformation struct { | ||
// Whilst the Kolide API readme entry references this as a "string", the returned value encountered during implementation MAY BE an "int" | ||
Identifier int32 `json:"identifier,omitempty"` | ||
} | ||
|
||
func (c *Client) GetRegistrationRequests(cursor string, limit int32, searches ...Search) (interface{}, error) { | ||
return c.fetchCollection("/registration_request/", cursor, limit, searches, new(RegistrationRequestListResponse)) | ||
} | ||
|
||
func (c *Client) GetRegistrationRequestById(id string) (interface{}, error) { | ||
return c.fetchResource("/registration_request/", id, new(RegistrationRequest)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package kolide | ||
|
||
import ( | ||
"context" | ||
|
||
kolide "github.com/grendel-consulting/steampipe-plugin-kolide/kolide/client" | ||
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto" | ||
"github.com/turbot/steampipe-plugin-sdk/v5/plugin" | ||
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform" | ||
) | ||
|
||
//// TABLE DEFINITION | ||
|
||
func tableKolideRegistrationRequest(_ context.Context) *plugin.Table { | ||
return &plugin.Table{ | ||
Name: "kolide_registration_request", | ||
Description: "Created when someone requests admin approval to register a device with Kolide. Registration requests can be approved or denied by admins", | ||
Columns: []*plugin.Column{ | ||
// Filterable "top" columns | ||
{Name: "id", Description: "Canonical identifier for this registration request.", Type: proto.ColumnType_STRING}, | ||
{Name: "status", Description: "Current status of this registration request; one of: pending, approved or denied", Type: proto.ColumnType_STRING}, | ||
{Name: "requester_message", Description: "Any message the person provided when requesting approval for this registration.", Type: proto.ColumnType_STRING}, | ||
{Name: "requested_at", Description: "When this registration approval was requested.", Type: proto.ColumnType_TIMESTAMP}, | ||
// Other columns | ||
{Name: "end_user_denial_note", Description: "Any explanation the admin provided for the requester when denying this request, for internal documentation. It is meant to be shown to the requester. It will be blank if the registration has not been denied.", Type: proto.ColumnType_STRING}, | ||
{Name: "internal_denial_note", Description: "Any internal explanation the admin provided when denying this request, for internal documentation. It is not shown to the requester. It will be blank if the registration has not been denied.", Type: proto.ColumnType_STRING}, | ||
{Name: "requester_id", Description: "Canonical identifier for the person who requested this registration.", Type: proto.ColumnType_STRING, Transform: transform.FromField("RequesterInformation.Identifier")}, | ||
{Name: "device_id", Description: "Canonical identifier for the device the person is trying to register.", Type: proto.ColumnType_STRING, Transform: transform.FromField("DeviceInformation.Identifier")}, | ||
// Steampipe standard columns | ||
{Name: "title", Description: "Display name for this registration request.", Type: proto.ColumnType_STRING, Transform: transform.FromField("DeviceInformation.Identifier")}, | ||
}, | ||
List: &plugin.ListConfig{ | ||
KeyColumns: []*plugin.KeyColumn{ | ||
// Using Kolide API query feature, can be combined with AND (and OR) | ||
{Name: "status", Require: plugin.Optional, Operators: []string{"=", "~~"}}, | ||
{Name: "requested_at", Require: plugin.Optional, Operators: []string{"=", ">", "<"}}, | ||
{Name: "requester_message", Require: plugin.Optional, Operators: []string{"=", "~~"}}, | ||
}, | ||
Hydrate: listRegistrationRequests, | ||
}, | ||
Get: &plugin.GetConfig{ | ||
KeyColumns: plugin.SingleColumn("id"), | ||
Hydrate: getRegistrationRequest, | ||
}, | ||
} | ||
} | ||
|
||
//// LIST FUNCTION | ||
|
||
func listRegistrationRequests(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
var visitor ListPredicate = func(client *kolide.Client, cursor string, limit int32, searches ...kolide.Search) (interface{}, error) { | ||
return client.GetRegistrationRequests(cursor, limit, searches...) | ||
} | ||
|
||
return listAnything(ctx, d, h, "kolide_registration_request.listRegistrationRequests", visitor, "RegistrationRequests") | ||
} | ||
|
||
//// GET FUNCTION | ||
|
||
func getRegistrationRequest(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { | ||
var visitor GetPredicate = func(client *kolide.Client, id string) (interface{}, error) { | ||
return client.GetRegistrationRequestById(id) | ||
} | ||
|
||
return getAnything(ctx, d, h, "kolide_registration_request.getRegistrationRequest", "id", visitor) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
select | ||
id, | ||
status, | ||
requested_at, | ||
requester_message, | ||
requester_id, | ||
device_id | ||
from | ||
kolide_registration_request | ||
order by | ||
id asc; |
11 changes: 11 additions & 0 deletions
11
test/end-to-end/_query/kolide_registration_request_by_id.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
select | ||
id, | ||
status, | ||
requested_at, | ||
requester_message, | ||
requester_id, | ||
device_id | ||
from | ||
kolide_registration_request | ||
where | ||
id = '12345'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
define_test_results(){ | ||
export EXPECTED_COUNT="0" | ||
# export ID="" | ||
# export STATUS="" | ||
# export REQUESTED_AT="" | ||
# export REQUESTER_MESSAGE="" | ||
# export REQUESTER_ID="" | ||
# export DEVICE_ID="" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# bats file_tags=table:kolide_registration_request, output:registration_request | ||
|
||
setup_file() { | ||
load "${BATS_TEST_DIRNAME}/_support/globals.bash" | ||
define_file_globals | ||
|
||
define_common_test_results | ||
|
||
if [[ -f $EXPECTED_RESULTS ]]; then | ||
load $EXPECTED_RESULTS | ||
fi | ||
} | ||
|
||
setup() { | ||
load "${BATS_TEST_DIRNAME}/_support/extensions.bash" | ||
load_helpers | ||
} | ||
|
||
#bats test_tags=scope:smoke | ||
@test "can_execute_query_via_steampipe" { | ||
steampipe query $QUERY_UNDER_TEST --output json > $QUERY_RESULTS | ||
assert_exists $QUERY_RESULTS | ||
} | ||
|
||
@test "has_expected_number_of_results" { | ||
run bash -c "cat $QUERY_RESULTS | jq -r '.rows | length'" | ||
|
||
if [[ -z "$EXPECTED_COUNT" ]]; then assert_output $EXPECTED_COUNT ; else assert [ "$output" -ge "1" ] ; fi | ||
} | ||
|
||
@test "has_expected_id" { | ||
run bash -c "cat $QUERY_RESULTS | jq -r '.rows.[0].id'" | ||
if [[ -z "$ID" ]]; then assert_output $ID ; else assert_success ; fi | ||
} | ||
|
||
@test "has_expected_status" { | ||
run bash -c "cat $QUERY_RESULTS | jq -r '.rows.[0].status'" | ||
if [[ -z "$STATUS" ]]; then assert_output --partial $STATUS ; else assert_success ; fi | ||
} | ||
|
||
#bats test_tags=exactness:fuzzy | ||
@test "has_expected_requested_at" { | ||
run bash -c "cat $QUERY_RESULTS | jq -r '.rows.[0].requested_at'" | ||
if [[ -z "$REQUESTED_AT" ]]; then assert_output $REQUESTED_AT ; else assert_success ; fi | ||
} | ||
|
||
#bats test_tags=exactness:fuzzy | ||
@test "has_expected_requester_message" { | ||
run bash -c "cat $QUERY_RESULTS | jq -r '.rows.[0].requester_message'" | ||
if [[ -z "$REQUESTER_MESSAGE" ]]; then assert_output --partial $REQUESTER_MESSAGE ; else assert_success ; fi | ||
} | ||
|
||
#bats test_tags=exactness:fuzzy | ||
@test "has_expected_requester_id" { | ||
run bash -c "cat $QUERY_RESULTS | jq -r '.rows.[0].requester_id'" | ||
if [[ -z "$REQUESTER_ID" ]]; then assert_output --partial $REQUESTER_ID ; else assert_success ; fi | ||
} | ||
|
||
#bats test_tags=exactness:fuzzy | ||
@test "has_expected_device_id" { | ||
run bash -c "cat $QUERY_RESULTS | jq -r '.rows.[0].device_id'" | ||
if [[ -z "$DEVICE_ID" ]]; then assert_output --partial $DEVICE_ID ; else assert_success ; fi | ||
} | ||
|
||
teardown_file(){ | ||
if [[ -f $QUERY_RESULTS ]]; then | ||
rm -f $QUERY_RESULTS | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# bats file_tags=table:kolide_registration_request, output:registration_request | ||
|
||
setup_file() { | ||
load "${BATS_TEST_DIRNAME}/_support/globals.bash" | ||
define_file_globals | ||
} | ||
|
||
setup() { | ||
load "${BATS_TEST_DIRNAME}/_support/extensions.bash" | ||
load_helpers | ||
} | ||
|
||
#bats test_tags=scope:smoke | ||
@test "can_execute_query_via_steampipe" { | ||
steampipe query $QUERY_UNDER_TEST --output json > $QUERY_RESULTS | ||
assert_exists $QUERY_RESULTS | ||
} | ||
|
||
@test "has_no_more_than_one_result" { | ||
run bash -c "cat $QUERY_RESULTS | jq -r '.rows | length'" | ||
assert [ "$output" -le "1" ] | ||
} | ||
|
||
# Remaining functionality covered in kolide_registration_request.bats | ||
|
||
teardown_file(){ | ||
if [[ -f $QUERY_RESULTS ]]; then | ||
rm -f $QUERY_RESULTS | ||
fi | ||
} |