Skip to content
This repository has been archived by the owner on Jul 24, 2021. It is now read-only.

Commit

Permalink
use a separate json schema for each action in the route chain
Browse files Browse the repository at this point in the history
  • Loading branch information
karenetheridge committed Nov 12, 2020
1 parent 7661949 commit ff3797d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
30 changes: 18 additions & 12 deletions docs/json-schema/query_params.json
Expand Up @@ -3,7 +3,7 @@
"$schema" : "http://json-schema.org/draft-07/schema#",
"definitions" : {
"BuildDevices" : {
"additionalProperties" : false,
"additionalProperties" : true,
"allOf" : [
{
"not" : {
Expand Down Expand Up @@ -69,16 +69,6 @@
}
]
},
"phase_earlier_than" : {
"oneOf" : [
{
"const" : ""
},
{
"$ref" : "common.json#/definitions/device_phase"
}
]
},
"serials_only" : {
"$ref" : "#/definitions/boolean_integer_default_false"
}
Expand Down Expand Up @@ -127,6 +117,22 @@
"DeactivateUser" : {
"$ref" : "#/definitions/ChangePassword"
},
"FindDevice" : {
"additionalProperties" : true,
"properties" : {
"phase_earlier_than" : {
"oneOf" : [
{
"const" : ""
},
{
"$ref" : "common.json#/definitions/device_phase"
}
]
}
},
"type" : "object"
},
"GetBuilds" : {
"not" : {
"properties" : {
Expand Down Expand Up @@ -179,7 +185,7 @@
"type" : "object"
},
"GetValidationState" : {
"additionalProperties" : false,
"additionalProperties" : true,
"properties" : {
"status" : {
"oneOf" : [
Expand Down
10 changes: 7 additions & 3 deletions json-schema/query_params.yaml
Expand Up @@ -98,7 +98,7 @@ definitions:
type: string
GetValidationState:
type: object
additionalProperties: false
additionalProperties: true # may be used at the same time as other schemas
properties:
status:
oneOf:
Expand Down Expand Up @@ -173,14 +173,18 @@ definitions:
$ref: '#/definitions/boolean_integer_or_flag'
with_rack_phases:
$ref: '#/definitions/boolean_integer_or_flag'
BuildDevices:
FindDevice:
type: object
additionalProperties: false
additionalProperties: true # may be used at the same time as other schemas
properties:
phase_earlier_than:
oneOf:
- const: ''
- $ref: common.yaml#/definitions/device_phase
BuildDevices:
type: object
additionalProperties: true # may be used at the same time as other schemas
properties:
health:
oneOf:
- $ref: common.yaml#/definitions/device_health
Expand Down
2 changes: 1 addition & 1 deletion lib/Conch/Controller/Build.pm
Expand Up @@ -673,7 +673,7 @@ devices for such phases).
=cut

sub find_devices ($c) {
my $params = $c->validate_query_params('BuildDevices');
my $params = $c->validate_query_params('FindDevice');
return if not $params;

# production devices do not consider location, interface data to be canonical
Expand Down
6 changes: 4 additions & 2 deletions lib/Conch/Controller/Device.pm
Expand Up @@ -32,6 +32,9 @@ the provided phase (or later).
=cut

sub find_device ($c) {
my $params = $c->validate_query_params('FindDevice');
return if not $params;

my $rs = $c->db_devices;
my $identifier;
if ($identifier = $c->stash('device_id')) {
Expand Down Expand Up @@ -108,8 +111,7 @@ sub find_device ($c) {
$c->stash('device_id', $device_id);
$c->stash('device_rs', $c->db_devices->search_rs({ 'device.id' => $device_id }));

if (my $bad_phase = $c->req->query_params->param('phase_earlier_than')
// $c->stash('phase_earlier_than')) {
if (my $bad_phase = $params->{phase_earlier_than} // $c->stash('phase_earlier_than')) {
my $phase = $c->stash('device_rs')->get_column('phase')->single;
if (Conch::DB::Result::Device->phase_cmp($phase, $bad_phase) >= 0) {
$c->res->headers->location($c->url_for('/device/'.$device_id.'/links'));
Expand Down

0 comments on commit ff3797d

Please sign in to comment.