Skip to content

Instantly share code, notes, and snippets.

@pkarman
Created August 15, 2018 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkarman/98dbe5999b7f6f507cc51ed74b953a7b to your computer and use it in GitHub Desktop.
Save pkarman/98dbe5999b7f6f507cc51ed74b953a7b to your computer and use it in GitHub Desktop.
bootstrap PRX ID/Exchange/Metrics/Publish in dev
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dump qw( dump );
sub run {
my $c = shift;
my $cmd = "docker-compose -f my-docker-compose.yml run id -- $c";
print $cmd, $/;
my @out = `$cmd`;
if ( $? != 0 ) {
die "$cmd failed: $!";
}
return \@out;
}
my %clients = (
'http://exchange.prx.docker' => 'http://exchange.prx.docker/sessions/callback',
'http://metrics.prx.docker' =>
'http://metrics.prx.docker/assets/callback.html',
'http://publish.prx.docker' =>
'http://publish.prx.docker/assets/callback.html',
);
my $id_out = run("rake db:seed");
my $user1_out = run('rake users:create EMAIL=you@example.org PW=sekrit');
my $user2_out = run('rake users:create EMAIL=another@example.org PW=sekrit');
#print dump $id_out;
#print dump $user1_out;
#print dump $user2_out;
my ($id_id) = ( grep {/Created client/} @$id_out )[1];
$id_id =~ s/Created client_application (\w+) .+/$1/;
$id_id =~ s/\s+//g;
print "id.prx.docker => $id_id\n";
run("rake clients:associate CLIENT_ID=$id_id ACCOUNT_ID=2 USER_ID=2");
system("echo 'CLIENT_ID=$id_id' >> .env");
for my $url ( sort keys %clients ) {
my $callback = $clients{$url};
my $out = run(
"rake clients:create CLIENT_URL=$url CLIENT_CALLBACK=$callback");
#print dump $out;
my ($client_id) = grep {/Created client/} @$out;
$client_id =~ s/Created client_application //;
$client_id =~ s/\s+//g;
print "$url => $client_id\n";
my $assoc_out = run(
"rake clients:associate CLIENT_ID=$client_id ACCOUNT_ID=2 USER_ID=2");
#print dump $assoc_out;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment