Debian Codegraph @

bin/metabase-profile

raw
1 #!/usr/bin/perl
2 use 5.006;
3 use strict;
4 use warnings;
5
6 package metabase_profile; # dzil needs this
7 # PODNAME: metabase-profile
8 # ABSTRACT: create a metabase profile
9
10 our $VERSION = '0.025';
11
12 use Getopt::Long;
13 use JSON::MaybeXS ();
14 use Metabase::User::Profile;
15 use Metabase::User::Secret;
16 use Pod::Usage;
17 use IO::Prompt::Tiny qw(prompt);
18
19 my ( %profile, $help, $output, $full_name, $email_address, $password );
20 my $result = GetOptions(
21 'help|h' => \$help,
22 'output|o:s' => \$output,
23 'name:s' => \$full_name,
24 'email:s' => \$email_address,
25 'secret:s' => \$password,
26 );
27
28 pod2usage( { -verbose => 2 } ) if !$result || $help;
29
30 # setup output file and confirm it doesn't exist
31 if ( !defined $output ) {
32 $output = "metabase_id.json";
33 }
34 if ( -f $output ) {
35 die "Won't over-write existing '$output' file. Aborting.\n";
36 }
37
38 # get profile information
39 $profile{full_name} = $full_name if defined $full_name;
40 $profile{email_address} = $email_address if defined $email_address;
41 $profile{password} = $password if defined $password;
42
43 my @prompts = (
44 full_name => 'full name',
45 email_address => 'email address',
46 password => 'password/secret',
47 );
48
49 while (@prompts) {
50 my ( $key, $phrase ) = splice( @prompts, 0, 2 );
51 next if $profile{$key};
52 chomp( my $answer = prompt("Enter $phrase\: ") );
53 $profile{$key} = $answer;
54 }
55
56 # create profile and secret objects
57 $password = delete $profile{password};
58 my $profile = Metabase::User::Profile->create(%profile);
59 my $secret = Metabase::User::Secret->new(
60 resource => $profile->resource,
61 content => $password,
62 );
63
64 # write output
65 print "Writing profile to '$output'\n";
66 open my $fh, ">", $output;
67 print {$fh}
68 JSON::MaybeXS->new(ascii => 1, pretty => 1)->encode( [ $profile->as_struct, $secret->as_struct, ] );
69 close $fh;
70 chmod 0600, $output;
71
72 __END__
73
74 =pod
75
76 =encoding UTF-8
77
78 =head1 NAME
79
80 metabase-profile - create a metabase profile
81
82 =head1 VERSION
83
84 version 0.025
85
86 =head1 SYNOPSIS
87
88 $ metabase-profile
89 Enter full name: John Doe
90 Enter email address: [email protected]
91 Enter password/secret: zqxjkh
92 Writing profile to 'metabase_id.json'
93
94 =head1 USAGE
95
96 The metabase-profile program makes it easy to create a user profile for
97 submitting facts and reports to a Metabase server.
98
99 Valid options include:
100
101 --email ADDRESS user email address eg "[email protected]"
102 --name FULLNAME full user name, eg "John Doe"
103 -o, --output FILENAME output filename
104 --secret PASSWORD password for authentication
105 -h, --help print man page
106
107 If no output file name is given, the default name 'metabase_id.json' will be
108 used. If the output filename (or default) exists, the program will abort
109 rather than overwrite the file. The output file will be in JSON and contain
110 the user profile and the user's shared secret.
111
112 Typically, when a Metabase server first receives a report from a new user
113 profile, the shared secret is recorded and will be used to authenticate
114 subsequent submissions. The output should not be shared publicly or
115 made group or world readable.
116
117 Use the resulting file according to the instructions of your Metabase
118 client program. You may wish to copy it across computers if you would like
119 to be identified consistently when submitting reports from different
120 locations.
121
122 =head1 AUTHORS
123
124 =over 4
125
126 =item *
127
128 David Golden <[email protected]>
129
130 =item *
131
132 Ricardo Signes <[email protected]>
133
134 =item *
135
136 H.Merijn Brand <[email protected]>
137
138 =back
139
140 =head1 COPYRIGHT AND LICENSE
141
142 This software is Copyright (c) 2016 by David Golden.
143
144 This is free software, licensed under:
145
146 The Apache License, Version 2.0, January 2004
147
148 =cut