| 1 |
#!/usr/bin/perl -w |
| 2 |
# |
| 3 |
# ecaccess-association-put: Update/Create an Association |
| 4 |
# |
| 5 |
# [email protected] - 2010-10-15 |
| 6 |
|
| 7 |
use ECMWF::ECaccess; |
| 8 |
use Getopt::Long; |
| 9 |
use Pod::Usage; |
| 10 |
use Term::ReadKey; |
| 11 |
use File::Basename; |
| 12 |
use Cwd 'abs_path'; |
| 13 |
|
| 14 |
my %opt = ( |
| 15 |
gateway => undef, |
| 16 |
password => 0, |
| 17 |
version => 0, |
| 18 |
help => 0, |
| 19 |
manual => 0, |
| 20 |
retry => 0, |
| 21 |
debug => 0 |
| 22 |
); |
| 23 |
|
| 24 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 1 ) if !GetOptions( |
| 25 |
\%opt, |
| 26 |
qw( |
| 27 |
gateway=s |
| 28 |
password |
| 29 |
version |
| 30 |
help|? |
| 31 |
manual |
| 32 |
retry=i |
| 33 |
debug |
| 34 |
) |
| 35 |
); |
| 36 |
|
| 37 |
# Display version if requested |
| 38 |
die ECMWF::ECaccess->VERSION . "\n" if ( $opt{version} ); |
| 39 |
|
| 40 |
my $sourceFile = $ARGV[0]; |
| 41 |
|
| 42 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 1 ) if ( $opt{help} ); |
| 43 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 2 ) if ( $opt{manual} ); |
| 44 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "No source-file specified!\n" ) if not($sourceFile); |
| 45 |
pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "Source-file is not a plain text file!\n" ) if not( -f $sourceFile && -T $sourceFile ); |
| 46 |
|
| 47 |
# Prompt for a new password if required |
| 48 |
my $password = ''; |
| 49 |
if ( $opt{password} ) { |
| 50 |
print "New password: "; |
| 51 |
ReadMode('noecho'); |
| 52 |
$password = <STDIN>; |
| 53 |
ReadMode('normal'); |
| 54 |
chomp($password); |
| 55 |
print "\n"; |
| 56 |
} |
| 57 |
|
| 58 |
# Create the ECaccess Controler |
| 59 |
my $ecaccess = ECMWF::ECaccess->new( $opt{retry}, $opt{debug}); |
| 60 |
|
| 61 |
# Get the Token (using the Certificate in $HOME) |
| 62 |
my $token = $ecaccess->getToken(); |
| 63 |
|
| 64 |
# Get the Control Channel |
| 65 |
my $controlChannel = $ecaccess->getControlChannel(); |
| 66 |
|
| 67 |
# If no Gateway is specified then use the default Gateway |
| 68 |
$opt{gateway} = $controlChannel->getGatewayName()->result if ( not $opt{gateway} ); |
| 69 |
|
| 70 |
# Load/check configuration from file |
| 71 |
no warnings qw(once); |
| 72 |
unless ( $return = do( abs_path($sourceFile) ) ) { |
| 73 |
die "Couldn't process $sourceFile: $@\n" if $@; |
| 74 |
die "Couldn't process $sourceFile: $!\n" unless defined $return; |
| 75 |
die "Couldn't process $sourceFile\n" unless $return; |
| 76 |
} |
| 77 |
|
| 78 |
# Update the association |
| 79 |
$controlChannel->putAssociation( |
| 80 |
$token, |
| 81 |
$opt{gateway}, |
| 82 |
SOAP::Data->name( |
| 83 |
"request" => \SOAP::Data->value( |
| 84 |
SOAP::Data->name( 'name' => $name ), |
| 85 |
SOAP::Data->name( 'password' => $password ), |
| 86 |
SOAP::Data->name( 'active' => $active eq 'yes' ? 'true' : 'false' ), |
| 87 |
SOAP::Data->name( 'comment' => $comment ), |
| 88 |
SOAP::Data->name( 'grantedUserList' => $grantedUserList ), |
| 89 |
SOAP::Data->name( 'data' => $data ), |
| 90 |
SOAP::Data->name( 'directory' => $directory ), |
| 91 |
SOAP::Data->name( 'hostName' => $hostName ), |
| 92 |
SOAP::Data->name( 'protocol' => $protocol ), |
| 93 |
SOAP::Data->name( 'login' => $login ) |
| 94 |
) |
| 95 |
) |
| 96 |
); |
| 97 |
|
| 98 |
# Logout |
| 99 |
END { |
| 100 |
$ecaccess->releaseToken($token) if ($token); |
| 101 |
} |
| 102 |
|
| 103 |
__END__ |
| 104 |
|
| 105 |
=head1 NAME |
| 106 |
|
| 107 |
ecaccess-association-put - Update/Create an Association |
| 108 |
|
| 109 |
=head1 SYNOPSIS |
| 110 |
|
| 111 |
B<ecaccess-association-put -version|-help|-manual> |
| 112 |
|
| 113 |
B<ecaccess-association-put [-debug] [-gateway> I<name>B<] [-password]> I<source-file> |
| 114 |
|
| 115 |
=head1 DESCRIPTION |
| 116 |
|
| 117 |
Allow updating or creating an ECtrans Association. If the name exists then the Association is updated. If |
| 118 |
it does not exists then a new Association is created. In order to get a template for a new Association please |
| 119 |
use the following command: |
| 120 |
|
| 121 |
B<ecaccess-association-get -template> I<association-name> I<target-file> |
| 122 |
|
| 123 |
The I<target-file> for the Association Descriptive File does not have to be the name of the Association |
| 124 |
itself. The name for the Association is specified in the I<association-name> parameter. |
| 125 |
|
| 126 |
When creating a new Association the B<-password> option should be used to set the password (it can not be set |
| 127 |
in the Association Descriptive File as this would not be secure). |
| 128 |
|
| 129 |
=head1 ARGUMENTS |
| 130 |
|
| 131 |
=over 8 |
| 132 |
|
| 133 |
=item I<source-file> |
| 134 |
|
| 135 |
The name of the Association Descriptive File to upload. |
| 136 |
|
| 137 |
=back |
| 138 |
|
| 139 |
=head1 OPTIONS |
| 140 |
|
| 141 |
=over 8 |
| 142 |
|
| 143 |
=item B<-gateway> I<name> |
| 144 |
|
| 145 |
This is the name of the ECaccess Gateway where the Association should be installed. |
| 146 |
It is by default the Gateway you are connected to. In order to get the name |
| 147 |
of your current Gateway you can use the B<ecaccess-gateway-name> command. When |
| 148 |
using the commands at ECMWF the default Gateway is always "boaccess.ecmwf.int". |
| 149 |
|
| 150 |
=item B<-password> |
| 151 |
|
| 152 |
Allow prompting for a new password for the Association. |
| 153 |
|
| 154 |
=item B<-version> |
| 155 |
|
| 156 |
Display version number and exits. |
| 157 |
|
| 158 |
=item B<-help> |
| 159 |
|
| 160 |
Print a brief help message and exits. |
| 161 |
|
| 162 |
=item B<-manual> |
| 163 |
|
| 164 |
Prints the manual page and exits. |
| 165 |
|
| 166 |
=item B<-retry> I<count> |
| 167 |
|
| 168 |
Number of SSL connection retries per 5s to ECMWF. This parameter only apply to the |
| 169 |
initial SSL connection initiated by the command to the ECMWF server. It does not |
| 170 |
apply to all the subsequent requests made afteward as it is mainly targeting errors |
| 171 |
that can happen from time to time during the SSL handshake. Default is no retry. |
| 172 |
|
| 173 |
=item B<-debug> |
| 174 |
|
| 175 |
Display the SOAP and SSL messages exchanged. |
| 176 |
|
| 177 |
=back |
| 178 |
|
| 179 |
=head1 EXAMPLES |
| 180 |
|
| 181 |
B<ecaccess-association-put -password> I<./test> |
| 182 |
|
| 183 |
Push the Association described in the I<./test> file of your current directory on your default Gateway. You will |
| 184 |
be also prompted for a new password. |
| 185 |
|
| 186 |
B<ecaccess-association-put -gateway> I<boaccess.ecmwf.int> I<./test> |
| 187 |
|
| 188 |
Push the Association described in the I<./test> file of your current directory on the I<boaccess.ecmwf.int> Gateway. |
| 189 |
|
| 190 |
=head1 SEE ALSO |
| 191 |
|
| 192 |
B<ecaccess-association-delete>, B<ecaccess-association-get>, B<ecaccess-association-list>, |
| 193 |
B<ecaccess-association-protocol> and B<ecaccess>. |
| 194 |
|
| 195 |
=cut |