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

Commit

Permalink
Merge pull request #1070 from joyent/ether/v3.1-minor-fixes
Browse files Browse the repository at this point in the history
minor fixes for v3.1 release
  • Loading branch information
karenetheridge authored Nov 30, 2020
2 parents 9ee8a2c + a981801 commit 2a05333
Show file tree
Hide file tree
Showing 32 changed files with 69 additions and 22 deletions.
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ migrate-db: ## Apply database migrations
.PHONY: db-schema
db-schema: ## create a dump of current db schema
pg_dump --username conch --schema-only \
--exclude-table=legacy_workspace_rack \
--exclude-table=legacy_user_workspace_role \
--exclude-table=legacy_workspace \
--file sql/schema.sql conch

docker_test:
Expand Down
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ requires 'experimental', '0.020';
requires 'JSON::Schema::Draft201909', '0.017';
requires 'Email::Address::XS', '1.01';
requires 'YAML::PP';
requires 'next::XS';

# mojolicious and networking
requires 'Mojolicious', '8.36';
Expand Down
27 changes: 27 additions & 0 deletions cpanfile.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -3353,6 +3353,14 @@ DISTRIBUTIONS
perl 5.008
strict 0
warnings 0
PkgConfig-0.25026
pathname: P/PL/PLICEASE/PkgConfig-0.25026.tar.gz
provides:
PkgConfig 0.25026
requirements:
ExtUtils::MakeMaker 6.56
Test::More 0.94
perl 5.006000
Pod-Coverage-0.23
pathname: R/RC/RCLAMP/Pod-Coverage-0.23.tar.gz
provides:
Expand Down Expand Up @@ -4247,6 +4255,18 @@ DISTRIBUTIONS
Win32::ShellQuote 0.003001
requirements:
perl 5.006
XS-Install-1.3.1
pathname: S/SY/SYBER/XS-Install-1.3.1.tar.gz
provides:
XS::Install 1.003001
XS::Install::Payload undef
XS::Loader undef
requirements:
Exporter 5.58
ExtUtils::MakeMaker 7.12
ExtUtils::ParseXS 3.24
PkgConfig 0.24
perl 5.010000
XString-0.005
pathname: A/AT/ATOOMIC/XString-0.005.tar.gz
provides:
Expand Down Expand Up @@ -4424,6 +4444,13 @@ DISTRIBUTIONS
ExtUtils::MakeMaker 0
Package::Stash 0.23
perl 5.008001
next-XS-1.0.7
pathname: S/SY/SYBER/next-XS-1.0.7.tar.gz
provides:
next::XS 1.000007
requirements:
XS::Install v1.3.1
perl 5.018000
strictures-2.000006
pathname: H/HA/HAARG/strictures-2.000006.tar.gz
provides:
Expand Down
2 changes: 2 additions & 0 deletions docs/json-schema/response.json
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,7 @@
"properties" : {
"absolute_schema_location" : {
"format" : "uri",
"minLength" : 1,
"type" : "string"
},
"data_location" : {
Expand Down Expand Up @@ -1654,6 +1655,7 @@
"properties" : {
"$id" : {
"format" : "uri",
"minLength" : 1,
"type" : "string"
}
},
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/Conch::Controller::DeviceReport.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Controller for processing and managing device reports.
### process

Processes the device report, turning it into the various device\_\* tables as well
as running validations
as running validations.

Response contains no data but returns the resource to fetch the result in the Location header.

Expand Down
2 changes: 2 additions & 0 deletions json-schema/response.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ $defs:
format: json-pointer
absolute_schema_location:
type: string
minLength: 1
format: uri
error:
$ref: common.yaml#/$defs/non_empty_string
Expand Down Expand Up @@ -1789,6 +1790,7 @@ $defs:
properties:
$id:
type: string
minLength: 1
format: uri # never merely a uri-reference

# vim: set sts=2 sw=2 et :
5 changes: 5 additions & 0 deletions lib/Conch/Command/passwd.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ sub run ($self, @opts) {
my $user = $opt->id ? $user_rs->find($opt->id)
: $user_rs->find_by_email($opt->email);

if (not $user) {
say 'user not found';
exit;
};

my $echo_password = !$opt->password;
my $new_password = $opt->password // $self->app->random_string;

Expand Down
10 changes: 5 additions & 5 deletions lib/Conch/Controller/Build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ sub update ($c) {
my $unhealthy_devices =
$build->search_related('devices', {
health => { '!=' => 'pass' },
phase => { '<' => \[ '?::device_phase_enum', 'production' ] },
phase => { '<' => 'production' },
})->count
+ $build
->related_resultset('racks')
->related_resultset('device_locations')
->search_related('device', {
'device.phase' => { '<' => \[ '?::device_phase_enum', 'production' ] },
'device.phase' => { '<' => 'production' },
health => { '!=' => 'pass' }
})
->count;
Expand Down Expand Up @@ -672,7 +672,7 @@ sub find_devices ($c) {
{
'device.build_id' => undef,
'rack.build_id' => $build_id,
$bad_phase ? ('device.phase' => { '<' => \[ '?::device_phase_enum', $bad_phase ] }) : (),
$bad_phase ? ('device.phase' => { '<' => $bad_phase }) : (),
},
] },
{ join => { device_location => 'rack' } },
Expand Down Expand Up @@ -714,7 +714,7 @@ sub get_devices ($c) {
$rs = $rs->search({ health => $params->{health} }) if $params->{health};
$rs = $rs->search({ 'device.phase' => $params->{phase} }) if $params->{phase};

$rs = $rs->search({ last_seen => { '>' => \[ 'now() - ?::interval', $params->{active_minutes}.' minutes' ] } })
$rs = $rs->search({ last_seen => { '>' => \[ q{now() - interval '1 minute' * ?}, $params->{active_minutes} ] } })
if $params->{active_minutes};

if ($params->{ids_only}) {
Expand Down Expand Up @@ -798,7 +798,7 @@ sub create_and_add_devices ($c) {
}

return $c->status(409, { error => 'cannot add devices to a build when in production (or later) phase' })
if $device_rs->search({ 'device.phase' => { '>=' => \[ '?::device_phase_enum', 'production' ] } })->exists;
if $device_rs->search({ 'device.phase' => { '>=' => 'production' } })->exists;

%devices = map +($_->id => $_), $device_rs->all;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Conch/Controller/Device.pm
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ sub lookup_by_other_attribute ($c) {
$device_rs = $device_rs->search(
{
# production devices do not consider interface data to be canonical
$device_rs->current_source_alias.'.phase' => { '<' => \[ '?::device_phase_enum', 'production' ] },
$device_rs->current_source_alias.'.phase' => { '<' => 'production' },
'device_nics.'.$key => $value,
},
{ join => 'device_nics' },
Expand Down
2 changes: 1 addition & 1 deletion lib/Conch/Controller/DeviceReport.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Controller for processing and managing device reports.
=head2 process
Processes the device report, turning it into the various device_* tables as well
as running validations
as running validations.
Response contains no data but returns the resource to fetch the result in the Location header.
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 @@ -84,7 +84,7 @@ sub get ($c) {

# the canonical location of this document -- which should be the same URL used to get here
$bundled_schema->{'$id'} = $c->url_for('/json_schema/'.$type.'/'.$name)->to_abs;
$bundled_schema->{'$schema'} = 'https://json-schema.org/draft/2019-09/schema';
$bundled_schema->{'$schema'} //= 'https://json-schema.org/draft/2019-09/schema';

$c->res->headers->content_type('application/schema+json');
return $c->status(200, $bundled_schema);
Expand Down
2 changes: 1 addition & 1 deletion lib/Conch/Controller/Rack.pm
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ sub set_assignment ($c) {
if $c->stash('rack_rs')->related_resultset('build')->search({ completed => { '!=' => undef } })->exists;

return $c->status(409, { error => 'cannot add devices to a rack in production (or later) phase' })
if $c->stash('rack_rs')->search({ phase => { '>=' => \[ '?::device_phase_enum', 'production' ] } })->exists;
if $c->stash('rack_rs')->search({ phase => { '>=' => 'production' } })->exists;

# in order to determine if we have duplicate devices, we need to look up all ids for device
# serial numbers...
Expand Down
2 changes: 1 addition & 1 deletion lib/Conch/DB/Helper/ResultSet/WithRole.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ sub with_role ($self, $role) {
if !$ENV{MOJO_MODE} and not $self->result_source->has_column('role');

return $self->search if $role eq 'ro';
$self->search({ $self->current_source_alias.'.role' => { '>=' => \[ '?::role_enum', $role ] } });
$self->search({ $self->current_source_alias.'.role' => { '>=' => $role } });
}

1;
Expand Down
1 change: 1 addition & 0 deletions lib/Conch/DB/InflateColumn/Time.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use experimental 'signatures';
use parent 'DBIx::Class::InflateColumn::TimeMoment';

use Conch::Time;
use next::XS;

=pod
Expand Down
1 change: 1 addition & 0 deletions lib/Conch/DB/Result/Build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ __PACKAGE__->add_columns(
);

use experimental 'signatures';
use next::XS;

=head1 METHODS
Expand Down
1 change: 1 addition & 0 deletions lib/Conch/DB/Result/Device.pm
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ __PACKAGE__->many_to_many("relays", "device_relay_connections", "relay");
__PACKAGE__->load_components('+Conch::DB::Helper::Row::WithPhase');

use experimental 'signatures';
use next::XS;

=head1 METHODS
Expand Down
1 change: 1 addition & 0 deletions lib/Conch/DB/Result/DeviceReport.pm
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ __PACKAGE__->add_columns(

use experimental 'signatures';
use Mojo::JSON 'from_json';
use next::XS;

=head1 METHODS
Expand Down
1 change: 1 addition & 0 deletions lib/Conch/DB/Result/HardwareProduct.pm
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ __PACKAGE__->has_many(

use experimental 'signatures';
use Mojo::JSON 'from_json';
use next::XS;

__PACKAGE__->add_columns(
'+deactivated' => { is_serializable => 0 },
Expand Down
1 change: 1 addition & 0 deletions lib/Conch/DB/Result/Organization.pm
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ __PACKAGE__->add_columns(
);

use experimental 'signatures';
use next::XS;

=head1 METHODS
Expand Down
1 change: 1 addition & 0 deletions lib/Conch/DB/Result/Rack.pm
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ __PACKAGE__->add_columns(
);

use experimental 'signatures';
use next::XS;

=head1 METHODS
Expand Down
1 change: 1 addition & 0 deletions lib/Conch/DB/Result/RackLayout.pm
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ __PACKAGE__->belongs_to(
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:JPGX9CQzIOxaAK8cxoNY5Q

use experimental 'signatures';
use next::XS;

=head1 METHODS
Expand Down
1 change: 1 addition & 0 deletions lib/Conch/DB/Result/UserAccount.pm
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ __PACKAGE__->add_columns(

use experimental 'signatures';
use List::Util 'reduce';
use next::XS;

=head1 METHODS
Expand Down
1 change: 1 addition & 0 deletions lib/Conch/DB/Result/ValidationResult.pm
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ __PACKAGE__->add_columns(
);

use experimental 'signatures';
use next::XS;

=head2 TO_JSON
Expand Down
1 change: 1 addition & 0 deletions lib/Conch/DB/Result/ValidationState.pm
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ __PACKAGE__->add_columns(
);

use experimental 'signatures';
use next::XS;

=head1 METHODS
Expand Down
4 changes: 2 additions & 2 deletions lib/Conch/DB/ResultSet/Build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ sub with_user_role ($self, $user_id, $role) {

my $via_user_rs = $self->search(
{
$role ne 'ro' ? ('user_build_roles.role' => { '>=' => \[ '?::role_enum', $role ] } ) : (),
$role ne 'ro' ? ('user_build_roles.role' => { '>=' => $role } ) : (),
'user_build_roles.user_id' => $user_id,
},
{ join => 'user_build_roles' },
);

my $via_org_rs = $self->search(
{
$role ne 'ro' ? ('organization_build_roles.role' => { '>=' => \[ '?::role_enum', $role ] }) : (),
$role ne 'ro' ? ('organization_build_roles.role' => { '>=' => $role }) : (),
'user_organization_roles.user_id' => $user_id,
},
{ join => { organization_build_roles => { organization => 'user_organization_roles' } } } );
Expand Down
4 changes: 2 additions & 2 deletions lib/Conch/DB/ResultSet/Device.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sub with_user_role ($self, $user_id, $role) {
my $devices_in_rack_builds = $self->search(
{
# production devices do not consider location data to be canonical
$me.'.phase' => { '<' => \[ '?::device_phase_enum', 'production' ] },
$me.'.phase' => { '<' => 'production' },
'rack.build_id' => { -in => $build_ids_rs->as_query },
},
{ join => { device_location => 'rack' } },
Expand Down Expand Up @@ -93,7 +93,7 @@ sub user_has_role ($self, $user_id, $role) {
# device -> rack -> build -> organization_build_role -> organization -> user
$self
# production devices do not consider location data to be canonical
->search({ $self->current_source_alias.'.phase' => { '<' => \[ '?::device_phase_enum', 'production' ] } })
->search({ $self->current_source_alias.'.phase' => { '<' => 'production' } })
->related_resultset('device_location')
->related_resultset('rack')
->user_has_role($user_id, $role);
Expand Down
1 change: 1 addition & 0 deletions lib/Conch/Log.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use Mojo::JSON 'to_json';
use Mojo::Path;
use Mojo::Home;
use Conch::Time;
use next::XS;

=head1 Conch::Log
Expand Down
2 changes: 1 addition & 1 deletion lib/Conch/Plugin/DeprecatedAction.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ sub register ($self, $app, $config) {
$c->on(finish => sub ($c) {
$c->send_message_to_rollbar(
'info',
'endpoint '.$c->req->url->path.' '.$substr.' removed in api '.$deprecated,
'endpoint '.$c->req->method.' '.$c->req->url->path.' '.$substr.' removed in api '.$deprecated,
{ context => ($c->stash('controller')//'').'#'.($c->stash('action')//'') },
);
})
Expand Down
1 change: 1 addition & 0 deletions lib/Test/Conch.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use Mojo::URL;
use Scalar::Util 'weaken';
use List::Util 'any';
use Data::Dumper ();
use next::XS;

=pod
Expand Down
2 changes: 1 addition & 1 deletion t/integration/crud/build.t
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ $t->post_ok('/build', json => {
})
->status_is(400)
->json_schema_is('RequestValidationError')
->json_cmp_deeply('/details', superbagof(superhashof({ error => 'multiple subschemas are valid: 0, 1' })));
->json_cmp_deeply('/details', [ superhashof({ error => 'multiple subschemas are valid: 0, 1' }) ]);

$t->post_ok('/build', json => { name => 'my first build', admins => [ { user_id => create_uuid_str() } ] })
->status_is(409)
Expand Down
2 changes: 1 addition & 1 deletion t/integration/crud/organization.t
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ $t->post_ok('/organization', json => {
})
->status_is(400)
->json_schema_is('RequestValidationError')
->json_cmp_deeply('/details', superbagof(superhashof({ error => 'multiple subschemas are valid: 0, 1' })));
->json_cmp_deeply('/details', [ superhashof({ error => 'multiple subschemas are valid: 0, 1' }) ]);

$t->post_ok('/organization', json => { name => 'my first organization', admins => [ { user_id => create_uuid_str() } ] })
->status_is(409)
Expand Down
2 changes: 1 addition & 1 deletion t/integration/users.t
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ $build2->create_related('organization_build_roles', { organization_id => $organi
$t->post_ok('/login', json => { email => 'a', password => 'b' })
->status_is(400)
->json_schema_is('RequestValidationError')
->json_cmp_deeply('/details', superbagof(superhashof({ error => 'not an email' })));
->json_cmp_deeply('/details', [ superhashof({ error => 'not an email' }) ]);

$t->post_ok('/login', json => { email => 'foo@bar.com' })
->status_is(400)
Expand Down

0 comments on commit 2a05333

Please sign in to comment.