addauthority.in 1.48 KB
Newer Older
Leigh B. Stoller's avatar
Leigh B. Stoller committed
1
2
#!/usr/bin/perl -w
#
3
# GENIPUBLIC-COPYRIGHT
4
# Copyright (c) 2008-2010 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5
6
7
8
9
10
11
12
13
14
15
16
# All rights reserved.
#
use strict;
use English;
use Data::Dumper;
use Getopt::Std;

#
# Add an authority to the DB. Mostly for bootstrapping.
# 
sub usage()
{
17
    print "Usage: addauthority [-c] [-a] <certfile> <type>\n";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
18
19
    exit(1);
}
20
my $optlist    = "ac";
Leigh B. Stoller's avatar
Leigh B. Stoller committed
21
my $asch       = 0;
22
my $asam       = 0;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
23
24
25
26
27
28
29
30
31
32
33

#
# Check args.
#
my %options = ();
if (! getopts($optlist, \%options)) {
    usage();
}
if (defined($options{"c"})) {
    $asch = 1;
}
34
35
36
if (defined($options{"a"})) {
    $asam = 1;
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
37
usage()
Leigh B. Stoller's avatar
Leigh B. Stoller committed
38
    if (@ARGV != 2);
Leigh B. Stoller's avatar
Leigh B. Stoller committed
39
40
41

my $certfile = $ARGV[0];
my $type     = $ARGV[1];
Leigh B. Stoller's avatar
Leigh B. Stoller committed
42
43
44
45
46

use vars qw($GENI_DBNAME);
if ($asch) {
    $GENI_DBNAME = "geni-ch";
}
47
48
49
elsif ($asam) {
    $GENI_DBNAME = "geni-cm";
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
50
51
52
53
54
55

# Now we can load the libraries after setting the proper DB.
use lib '@prefix@/lib';
require GeniDB;
require GeniCertificate;
require GeniAuthority;
Leigh B. Stoller's avatar
Leigh B. Stoller committed
56
57
58
59
60

my $certificate = GeniCertificate->LoadFromFile($certfile);
if (!defined($certificate)) {
    die("Could not get certificate from $certfile\n");
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
61
if (! ($certificate->uuid() =~ /\w*-(\w*)$/)) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
62
63
    die("Could not get prefix from uuid\n");
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
64
65
66
67
my $url = $certificate->URL();
if (!defined($url)) {
    die("Certificate does not have a URI extension");
}
68
if (GeniAuthority->CheckExisting($certificate)) {
Leigh B. Stoller's avatar
Leigh B. Stoller committed
69
70
    die("$certfile is already registered in the DB\n");
}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
71
GeniAuthority->Create($certificate, $url, lc($type))
Leigh B. Stoller's avatar
Leigh B. Stoller committed
72
73
74
    or die("Could not add new authority\n");

exit(0);