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

small fixes #1082

Merged
merged 6 commits into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions docs/json-schema/request.json
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,9 @@
},
"properties" : {
"password" : {
"$ref" : "common.json#/$defs/non_empty_string"
"$ref" : "common.json#/$defs/non_empty_string",
"title" : "Password",
"writeOnly" : true
},
"set_session" : {
"type" : "boolean"
Expand All @@ -745,7 +747,9 @@
"$ref" : "common.json#/$defs/non_empty_string"
},
"password" : {
"$ref" : "common.json#/$defs/non_empty_string"
"$ref" : "common.json#/$defs/non_empty_string",
"title" : "Password",
"writeOnly" : true
}
},
"required" : [
Expand Down Expand Up @@ -1168,7 +1172,9 @@
"additionalProperties" : false,
"properties" : {
"password" : {
"$ref" : "common.json#/$defs/non_empty_string"
"$ref" : "common.json#/$defs/non_empty_string",
"title" : "Password",
"writeOnly" : true
}
},
"required" : [
Expand Down
4 changes: 4 additions & 0 deletions docs/modules/Conch.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ and therefore other helpers).
Helper method for setting the response status code and json content. Calls
`$c->render` as a side-effect.

### res\_location

Simple helper for setting the `Location` header in the response.

### startup\_time

Stores a [Conch::Time](../modules/Conch%3A%3ATime) instance representing the time the server started accepting requests.
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/Conch::Route::HardwareProduct.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Results in this data in `specification`, changing the data type at node `/foo/ba
- Requires system admin authorization
- Controller/Action: ["set\_specification" in Conch::Controller::HardwareProduct](../modules/Conch%3A%3AController%3A%3AHardwareProduct#set_specification)
- Request: after the update operation, the `specification` property must validate against
[common.json#/$defs/HardwareProductSpecification](../json-schema/common.json#/$defs/HardwareProductSpecification).
the schema available from `GET /json_schema/hardware_product/specification/latest`.
- Response: `204 No Content`

### `DELETE /hardware_product/:hardware_product_id_or_other/specification?path=:path_to_data`
Expand All @@ -93,7 +93,7 @@ parameter `path` as the JSON pointer to the data to be removed. All other proper
blob are left untouched.

After the delete operation, the `specification` property must validate against
[common.json#/$defs/HardwareProductSpecification](../json-schema/common.json#/$defs/HardwareProductSpecification).
the schema available from `GET /json_schema/hardware_product/specification/latest`.

- Requires system admin authorization
- Controller/Action: ["delete\_specification" in Conch::Controller::HardwareProduct](../modules/Conch%3A%3AController%3A%3AHardwareProduct#delete_specification)
Expand Down
14 changes: 3 additions & 11 deletions docs/modules/Conch::Route::JSONSchema.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Fetches the referenced JSON Schema document.

### `DELETE /json_schema/:json_schema_id`

### `DELETE /json_schema/:json_schema_type/:json_schema_name/:json_schema_version`

Deactivates the database entry for a single JSON Schema, rendering it unusable.
This operation is not permitted until all references from other documents have been removed,
exception of references using `.../latest` which will now resolve to a different document
Expand All @@ -70,19 +72,9 @@ If this JSON Schema was the latest of its series (`/json_schema/foo/bar/latest`)

### `GET /json_schema/:json_schema_type`

Gets meta information about all JSON Schemas in a particular type series.

Optionally accepts the following query parameter:

- `active_only` (default `0`): set to `1` to only query for JSON Schemas that have not been
deactivated.

- Controller/Action: ["get\_metadata" in Conch::Controller::JSONSchema](../modules/Conch%3A%3AController%3A%3AJSONSchema#get_metadata)
- Response: [response.json#/$defs/JSONSchemaDescriptions](../json-schema/response.json#/$defs/JSONSchemaDescriptions)

### `GET /json_schema/:json_schema_type/:json_schema_name`

Gets meta information about all JSON Schemas in a particular type and name series.
Gets meta information about all JSON Schemas in a particular type series, or a type and name series.

Optionally accepts the following query parameter:

Expand Down
6 changes: 6 additions & 0 deletions json-schema/request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ $defs:
required: [ password ]
properties:
password:
title: Password
writeOnly: true
$ref: common.yaml#/$defs/non_empty_string
set_session:
type: boolean
Expand All @@ -433,6 +435,8 @@ $defs:
required: [ password ]
properties:
password:
title: Password
writeOnly: true
$ref: common.yaml#/$defs/non_empty_string
NewUser:
type: object
Expand All @@ -444,6 +448,8 @@ $defs:
email:
$ref: common.yaml#/$defs/email_address
password:
title: Password
writeOnly: true
$ref: common.yaml#/$defs/non_empty_string
is_admin:
type: boolean
Expand Down
13 changes: 12 additions & 1 deletion lib/Conch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ C<< $c->render >> as a side-effect.
}

if ($code == 204) {
$c->res->headers->location($payload) if defined $payload;
$c->res_location($payload) if defined $payload;
$c->rendered;
}
elsif (any { $code == $_ } 301, 302, 303, 305, 307, 308) {
Expand All @@ -163,6 +163,17 @@ C<< $c->render >> as a side-effect.
});


=head2 res_location

Simple helper for setting the C<Location> header in the response.

=cut

$self->helper(res_location => sub ($c, @args) {
$c->res->headers->location($c->url_for(@args));
});


$self->hook(before_routes => sub ($c) {
my $headers = $c->req->headers;

Expand Down
2 changes: 1 addition & 1 deletion lib/Conch/Controller/Build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ sub create ($c) {
user_build_roles => [ map +{ user_id => $_->[2], role => 'admin' }, @admins ],
});
$c->log->info('created build '.$build->id.' ('.$build->name.')');
$c->res->headers->location('/build/'.$build->id);
$c->res_location('/build/'.$build->id);
$c->status(201);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Conch/Controller/Datacenter.pm
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ sub create ($c) {

my $dc = $c->db_datacenters->create($input);
$c->log->debug('Created datacenter '.$dc->id);
$c->res->headers->location('/dc/'.$dc->id);
$c->res_location('/dc/'.$dc->id);
$c->status(201);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Conch/Controller/DatacenterRoom.pm
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Response uses the DatacenterRoomDetailed json schema.

sub get_one ($c) {
my $room = $c->stash('datacenter_room_rs')->single;
$c->res->headers->location('/room/'.$room->id);
$c->res_location('/room/'.$room->id);
$c->status(200, $room);
}

Expand All @@ -97,7 +97,7 @@ sub create ($c) {

my $room = $c->db_datacenter_rooms->create($input);
$c->log->debug('Created datacenter room '.$room->id);
$c->res->headers->location('/room/'.$room->id);
$c->res_location('/room/'.$room->id);
$c->status(201);
}

Expand All @@ -124,7 +124,7 @@ sub update ($c) {
if $input->{vendor_name} and $input->{vendor_name} ne $room->vendor_name
and $c->db_datacenter_rooms->search({ vendor_name => $input->{vendor_name} })->exists;

$c->res->headers->location('/room/'.$room->id);
$c->res_location('/room/'.$room->id);

$room->set_columns($input);
return $c->status(204) if not $room->is_changed;
Expand Down
4 changes: 2 additions & 2 deletions lib/Conch/Controller/Device.pm
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ sub find_device ($c) {
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'));
$c->res_location('/device/'.$device_id.'/links');
return $c->status(409, { error => 'device is in the '.$phase.' phase' });
}
}

$c->res->headers->location('/device/'.$device_id);
$c->res_location('/device/'.$device_id);
return 1;
}

Expand Down
7 changes: 3 additions & 4 deletions lib/Conch/Controller/DeviceReport.pm
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ sub process ($c) {
}
}

$c->res->headers->location($c->url_for('/validation_state/'.$validation_state->id));
$c->res_location('/validation_state/'.$validation_state->id);
$c->status(201);
}

Expand Down Expand Up @@ -425,14 +425,13 @@ sub validate_report ($c) {
my ($status, @validation_results);
$c->txn_wrapper(sub ($c) {
if ($device) {
$c->db_devices->update({
$device->update({
serial_number => $unserialized_report->{serial_number},
system_uuid => $unserialized_report->{system_uuid},
uptime_since => $unserialized_report->{uptime_since},
hostname => $unserialized_report->{os}{hostname},
updated => \'now()',
},
{ key => 'device_serial_number_key' });
});
}
else {
$device = $c->db_devices->create({
Expand Down
8 changes: 4 additions & 4 deletions lib/Conch/Controller/HardwareProduct.pm
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Response uses the HardwareProduct json schema.

sub get ($c) {
my $hardware_product = $c->stash('hardware_product_rs')->single;
$c->res->headers->location('/hardware_product/'.$hardware_product->id);
$c->res_location('/hardware_product/'.$hardware_product->id);
$c->status(200, $hardware_product);
}

Expand Down Expand Up @@ -122,7 +122,7 @@ sub create ($c) {
return $c->status(400) if not $hardware_product;

$c->log->debug('Created hardware product id '.$hardware_product->id);
$c->res->headers->location('/hardware_product/'.$hardware_product->id);
$c->res_location('/hardware_product/'.$hardware_product->id);
$c->status(201);
}

Expand Down Expand Up @@ -232,7 +232,7 @@ sub set_specification ($c) {

return $rendered ? () : $c->status(400) if not $result;

$c->res->headers->location('/hardware_product/'.$hardware_product_id);
$c->res_location('/hardware_product/'.$hardware_product_id);
$c->status(204);
}

Expand Down Expand Up @@ -284,7 +284,7 @@ sub delete_specification ($c) {

return $rendered ? () : $c->status(400) if not $result;

$c->res->headers->location('/hardware_product/'.$hardware_product_id);
$c->res_location('/hardware_product/'.$hardware_product_id);
$c->status(204);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Conch/Controller/HardwareVendor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ sub create ($c) {
my $hardware_vendor = $c->db_hardware_vendors->create({ name => $c->stash('hardware_vendor_name') });

$c->log->debug('Created hardware vendor '.$c->stash('hardware_vendor_name'));
$c->res->headers->location('/hardware_vendor/'.$hardware_vendor->id);
$c->res_location('/hardware_vendor/'.$hardware_vendor->id);
$c->status(201);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Conch/Controller/JSONSchema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ sub create ($c) {

my $path = $row->canonical_path;
$c->log->info('created json schema '.$row->id.' at '.$path);
$c->res->headers->location($c->url_for('/json_schema/'.$row->id));
$c->res_location('/json_schema/'.$row->id);
$c->res->headers->content_location($c->url_for($path));
$c->status(201);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Conch/Controller/Login.pm
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ sub _check_authentication ($c) {
$user->user_session_tokens->login_only
->update({ expires => \'least(expires, now() + interval \'10 minutes\')' }) if $session_token;

$c->res->headers->location($c->url_for('/user/me/password?clear_tokens=none'));
$c->res_location('/user/me/password?clear_tokens=none');
return 0;
}

Expand Down Expand Up @@ -203,7 +203,7 @@ sub login ($c) {
$c->_update_session($user->id, $input->{set_session} ? time + 10 * 60 : 0);

# we logged the user in, but he must now change his password (within 10 minutes)
$c->res->headers->location($c->url_for('/user/me/password?clear_tokens=none'));
$c->res_location('/user/me/password?clear_tokens=none');
return $c->_respond_with_jwt($user->id, time + 10 * 60);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Conch/Controller/Organization.pm
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ sub create ($c) {
user_organization_roles => [ map +{ user_id => $_->[2], role => 'admin' }, @admins ],
});
$c->log->info('created organization '.$organization->id.' ('.$organization->name.')');
$c->res->headers->location('/organization/'.$organization->id);
$c->res_location('/organization/'.$organization->id);
$c->status(201);
}

Expand Down
10 changes: 5 additions & 5 deletions lib/Conch/Controller/Rack.pm
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ sub create ($c) {
my $rack = $c->db_racks->create($input);
$c->log->debug('Created rack '.$rack->id);

$c->res->headers->location('/rack/'.$rack->id);
$c->res_location('/rack/'.$rack->id);
$c->status(201);
}

Expand All @@ -131,7 +131,7 @@ Response uses the Rack json schema.
=cut

sub get ($c) {
$c->res->headers->location('/rack/'.$c->stash('rack_id'));
$c->res_location('/rack/'.$c->stash('rack_id'));
my $rs = $c->stash('rack_rs')
->with_build_name
->with_full_rack_name
Expand Down Expand Up @@ -160,7 +160,7 @@ sub get_layouts ($c) {
->all;

$c->log->debug('Found '.scalar(@layouts).' rack layouts');
$c->res->headers->location('/rack/'.$c->stash('rack_id').'/layout');
$c->res_location('/rack/'.$c->stash('rack_id').'/layout');
$c->status(200, \@layouts);
}

Expand Down Expand Up @@ -296,7 +296,7 @@ sub update ($c) {
}
}

$c->res->headers->location('/rack/'.$rack->id);
$c->res_location('/rack/'.$rack->id);

$rack->set_columns($input);
return $c->status(204) if not $rack->is_changed;
Expand Down Expand Up @@ -348,7 +348,7 @@ sub get_assignment ($c) {
->all;

$c->log->debug('Found '.scalar(@assignments).' device-rack assignments');
$c->res->headers->location('/rack/'.$c->stash('rack_id').'/assignment');
$c->res_location('/rack/'.$c->stash('rack_id').'/assignment');
$c->status(200, \@assignments);
}

Expand Down
6 changes: 3 additions & 3 deletions lib/Conch/Controller/RackLayout.pm
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ sub create ($c) {
my $layout = $c->db_rack_layouts->create($input);
$c->log->debug('Created rack layout '.$layout->id);

$c->res->headers->location('/layout/'.$layout->id);
$c->res_location('/layout/'.$layout->id);
$c->status(201);
}

Expand All @@ -130,7 +130,7 @@ sub get ($c) {
->with_sku
->single;

$c->res->headers->location('/layout/'.$layout->id);
$c->res_location('/layout/'.$layout->id);
$c->status(200, $layout);
}

Expand Down Expand Up @@ -237,7 +237,7 @@ sub update ($c) {
return $c->status(409, { error => 'rack_unit_start conflict' });
}

$c->res->headers->location('/layout/'.$layout->id);
$c->res_location('/layout/'.$layout->id);

$layout->set_columns($input);
return $c->status(204) if not $layout->is_changed;
Expand Down