/[packages]/cauldron/openqa/current/SOURCES/0001-add-a-script-to-create-admin-user-and-API-key.patch
ViewVC logotype

Contents of /cauldron/openqa/current/SOURCES/0001-add-a-script-to-create-admin-user-and-API-key.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 913541 - (show annotations) (download)
Tue Dec 22 15:52:18 2015 UTC (4 years, 6 months ago) by doktor5000
File size: 3504 byte(s)
- imported package for openQA
1 From 3678b8599f5fc269b24b62eb2efecc0169a64264 Mon Sep 17 00:00:00 2001
2 From: Adam Williamson <awilliam@redhat.com>
3 Date: Mon, 12 Oct 2015 17:20:13 -0700
4 Subject: [PATCH] add a script to create admin user and API key
5
6 This is to aid automated deployments, to avoid the need to use
7 the web UI to create the initial admin account and an API key
8 for worker deployment. Instead you can run this script to create
9 an initial user account and an API key.
10 ---
11 script/create_admin | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++
12 1 file changed, 87 insertions(+)
13 create mode 100755 script/create_admin
14
15 diff --git a/script/create_admin b/script/create_admin
16 new file mode 100755
17 index 0000000..ce117bc
18 --- /dev/null
19 +++ b/script/create_admin
20 @@ -0,0 +1,87 @@
21 +#!/usr/bin/env perl
22 +
23 +# Copyright (C) 2015 Red Hat
24 +#
25 +# This program is free software; you can redistribute it and/or modify
26 +# it under the terms of the GNU General Public License as published by
27 +# the Free Software Foundation; either version 2 of the License, or
28 +# (at your option) any later version.
29 +#
30 +# This program is distributed in the hope that it will be useful,
31 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
32 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 +# GNU General Public License for more details.
34 +#
35 +# You should have received a copy of the GNU General Public License along
36 +# with this program; if not, write to the Free Software Foundation, Inc.,
37 +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
38 +
39 +BEGIN {
40 + use FindBin qw($Bin);
41 + use lib "$Bin/../lib";
42 +}
43 +
44 +use strict;
45 +use warnings;
46 +use OpenQA::Schema::Result::ApiKeys;
47 +use OpenQA::Schema::Result::Users;
48 +use OpenQA::Schema::Schema;
49 +use Getopt::Long;
50 +
51 +my $email = 'admin@example.com';
52 +my $nickname = 'admin';
53 +my $fullname = 'Administrator';
54 +my $key = "";
55 +my $secret = "";
56 +my $help = 0;
57 +
58 +my $result = GetOptions(
59 + "email=s" => \$email,
60 + "nickname=s" => \$nickname,
61 + "fullname=s" => \$fullname,
62 + "key=s" => \$key,
63 + "secret=s" => \$secret,
64 + "help" => \$help,
65 +);
66 +
67 +my $user = $ARGV[0];
68 +
69 +if (!$user || (scalar @ARGV > 1)) {
70 + $help = 1;
71 +}
72 +
73 +if ($help) {
74 + print "Usage: $0 [options] user \n\n";
75 + print " --email : Email address.\n";
76 + print " --nickname : Nickname.\n";
77 + print " --fullname : Full name.\n";
78 + print " --key : API key (will be randomly generated if not set).\n";
79 + print " --secret : API secret (will be randomly generated if not set).\n";
80 + print " user : User ID (e.g. OpenID URL).\n";
81 + exit;
82 +}
83 +
84 +if (($key || $secret) &&
85 + !($key =~ /^[[:xdigit:]]{16}$/ && $secret =~ /^[[:xdigit:]]{16}$/)) {
86 + warn "--key and --secret must both be 16 digit hexadecimals.\n";
87 + exit 1;
88 +}
89 +
90 +unless ($key) {
91 + $key = db_helpers::rndhexU;
92 + $secret = db_helpers::rndhexU;
93 + print "Key: $key\n";
94 + print "Secret: $secret\n";
95 +}
96 +
97 +my $schema = OpenQA::Schema::connect_db();
98 +my $users = $schema->resultset('Users');
99 +if ($users != 0) {
100 + warn "A user already exists! Use client or web UI to create further users.\n";
101 + exit 1;
102 +}
103 +my $account = OpenQA::Schema::Result::Users->create_user($user, $schema, email => $email, nickname => $nickname, fullname => $fullname);
104 +
105 +$schema->resultset("ApiKeys")->create({user_id => $account->id, key => $key, secret => $secret});
106 +
107 +# vim: set sw=4 sts=4 et:
108 --
109 2.5.0
110

  ViewVC Help
Powered by ViewVC 1.1.28