Debian Codegraph @

script/ecaccess-association-get

raw
1 #!/usr/bin/perl -w
2 #
3 # ecaccess-association-get: Get the Association Descriptive File
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
12 my %opt = ( gateway => undef, template => 0, version => 0, help => 0, manual => 0, retry => 0, debug => 0 );
13
14 pod2usage( -noperldoc => 1, -exit => 1, verbose => 1 ) if !GetOptions(
15 \%opt,
16 qw(
17 gateway=s
18 template
19 version
20 help|?
21 manual
22 retry=i
23 debug
24 )
25 );
26
27 # Display version if requested
28 die ECMWF::ECaccess->VERSION . "\n" if ( $opt{version} );
29
30 my $associationName = $ARGV[0];
31 my $targetFile = $ARGV[1];
32
33 pod2usage( -noperldoc => 1, -exit => 1, verbose => 1 ) if ( $opt{help} );
34 pod2usage( -noperldoc => 1, -exit => 1, verbose => 2 ) if ( $opt{manual} );
35 pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "No association-name specified!\n" ) if not($associationName);
36 pod2usage( -noperldoc => 1, -exit => 1, verbose => 0, -msg => "No target-file specified!\n" ) if not($targetFile);
37
38 # Create the ECaccess Controler
39 my $ecaccess = ECMWF::ECaccess->new( $opt{retry}, $opt{debug});
40
41 # Get the Token (using the Certificate in $HOME)
42 my $token = $ecaccess->getToken();
43
44 # Get the Control Channel
45 my $controlChannel = $ecaccess->getControlChannel();
46
47 # If no Gateway is specified then use the default Gateway
48 $opt{gateway} = $controlChannel->getGatewayName()->result if ( not $opt{gateway} );
49
50 # Open the target file
51 open FILE, ">", $targetFile or die "Error creating file: " . $targetFile . "\n";
52 chmod 0600, $targetFile;
53
54 # Get the detail for the specified associationName
55 my $association =
56 $controlChannel->getAssociation( $token, $opt{gateway}, $associationName, $opt{template} ? 'true' : 'false' )->valueof('//getAssociationResponse/return');
57
58 # Print the parameters
59 print FILE "##############################################################\n";
60 print FILE "# Main Parameters\n";
61 print FILE "##############################################################\n";
62 print FILE "\$name='" . ( $association->{name} ) . "';\n";
63 print FILE "\$active='" . ( $association->{active} eq 'true' ? 'yes' : 'no' ) . "';\n";
64 print FILE "\$comment='" . $association->{comment} . "';\n";
65 print FILE "\$grantedUserList='" . $association->{grantedUserList} . "';\n";
66 print FILE "\$directory='" . $association->{directory} . "';\n";
67 print FILE "\$hostName='" . $association->{hostName} . "';\n";
68 print FILE "\$login='" . $association->{login} . "';\n";
69 print FILE "\$protocol='" . $association->{protocol} . "';\n";
70 print FILE "\n";
71 print FILE "##############################################################\n";
72 print FILE "# Data\n";
73 print FILE "##############################################################\n";
74 print FILE "\$data='\n" . $association->{data} . "';\n";
75
76 # Close file
77 close FILE;
78
79 # Logout
80 END {
81 $ecaccess->releaseToken($token) if ($token);
82 }
83
84 __END__
85
86 =head1 NAME
87
88 ecaccess-association-get - Get the Association Descriptive File
89
90 =head1 SYNOPSIS
91
92 B<ecaccess-association-get -version|-help|-manual>
93
94 B<ecaccess-association-get [-debug] [-gateway> I<name>B<] [-template]> I<association-name> I<target-file>
95
96 =head1 DESCRIPTION
97
98 Get the Descriptive File for the ECtrans Association specified by the I<association-name> parameter.
99 Once downloaded, the I<target-file> can be modified and processed through the B<ecaccess-association-put>
100 command.
101
102 When using the B<-template> option, if the Association already exists in the ECaccess Gateway Database,
103 then the command return with an error. In order to create a new Association similar to an existing one
104 the B<ecaccess-association-get> command can be used to retrieve the Descriptive File of the existing
105 Association. The file can then be updated and pushed to the ECaccess Gateway Database with the
106 B<ecaccess-association-put> command.
107
108 An ECtrans Association Descriptive File contains parameters for ECtrans of the general form $name='value'.
109 Each ECtrans Association has their own Descriptive File, and parameters in any given Descriptive File will be
110 passed to the ECtrans container whenever a transfer is requested to the corresponding Association.
111
112 Blank lines and leading spaces and tabs are ignored when they do not occur in single quoted strings. Lines
113 whose first non-space character is a pound-sign (#) are comments, and are ignored. Note that comments are
114 not allowed on the same line as parameters and don't persist when the Descriptive File is retrieved from
115 the Gateway (they might however be used when Descriptive Files are archived on your system).
116
117 The parameters are the following:
118
119 =over 8
120
121 =item I<active>
122
123 This is a boolean which indicate if the Association can be used by ECtrans or not (e.g. 'yes' or 'no'). You might
124 want to deactivate an Association but still keep it in the ECaccess Gateway Database for later.
125
126 =item I<comment>
127
128 This is a comment about your Association (e.g. 'Access to the archive system').
129
130 =item I<grantedUserList>
131
132 This is the list of ECMWF user identifiers which are allowed (other that you) to use this Association. Multiple users
133 should be separated by a column (e.g. 'abc,def,ghi').
134
135 =item I<directory>
136
137 This is the directory where to download/upload the files from/to (e.g. '/tmp/data').
138
139 =item I<hostName>
140
141 This is the name of the host to connect to (e.g. 'hostname.example.ms').
142
143 =item I<login>
144
145 This is the login to use to connect to the host specified in the I<hostName> parameter (e.g. 'anonymous').
146
147 =item I<protocol>
148
149 This is the protocol ECtrans will use to connect to the host specified in the I<hostName> parameter. The list of available
150 protocols for a Gateway can be displayed with the B<ecaccess-protocol-list> command (e.g. 'genericFtp').
151
152 =item I<data>
153
154 This parameter can be split over multiple lines and contains various options for the I<protocol> which have been selected
155 for the Association (these options are passed verbatim to the Module which implement the I<protocol>). In order to get the
156 list of available options for a protocol please use the command B<ecaccess-association-protocol> with the name of the B<protocol>.
157 The availabe options depends of the version of the ECaccess Gateway which is used to host the Association so it might be
158 that some options are available for some Gateways and not available for others. An unknown option will be silently ignored
159 by ECtrans. The format of an option is {protocol-shortname}.{option}={value} (e.g. ftp.port="21" would set the port option
160 of the genericFtp module to "21"). An example of this parameter is given in the EXAMPLES section below.
161
162 =back
163
164 =head1 ARGUMENTS
165
166 =over 8
167
168 =item I<association-name>
169
170 The name of the Association to retrieve the corresponding Descriptive File.
171
172 =item I<target-file>
173
174 The name of the file where to download the Descriptive File.
175
176 =back
177
178 =head1 OPTIONS
179
180 =over 8
181
182 =item B<-gateway> I<name>
183
184 This is the name of the ECaccess Gateway where the Association is installed.
185 It is by default the Gateway you are connected to. In order to get the name
186 of your current Gateway you can use the B<ecaccess-gateway-name> command. When
187 using the commands at ECMWF the default Gateway is always "boaccess.ecmwf.int".
188
189 =item B<-template>
190
191 Allow creating a new Association Descriptive File for the B<ecaccess-association-put> command.
192 If the Association already exists then the command fails.
193
194 =item B<-version>
195
196 Display version number and exits.
197
198 =item B<-help>
199
200 Print a brief help message and exits.
201
202 =item B<-manual>
203
204 Prints the manual page and exits.
205
206 =item B<-retry> I<count>
207
208 Number of SSL connection retries per 5s to ECMWF. This parameter only apply to the
209 initial SSL connection initiated by the command to the ECMWF server. It does not
210 apply to all the subsequent requests made afteward as it is mainly targeting errors
211 that can happen from time to time during the SSL handshake. Default is no retry.
212
213 =item B<-debug>
214
215 Display the SOAP and SSL messages exchanged.
216
217 =back
218
219 =head1 EXAMPLES
220
221 B<ecaccess-association-get -template> I<test> I<./test>
222
223 Create a new Association Descriptive File for an Association named I<test> and store it in your
224 current directory (file I<./test>). The file can then be edited and updated accordingly to your
225 requirements.
226
227 B<ecaccess-association-put -password> I<./test>
228
229 Create the Association with the previously updated I<./test> Association Descriptive File.
230
231 B<ecaccess-association-get -gateway> I<boaccess.ecmwf.int> I<ginko> I<./ginko>
232
233 Get the Descriptive File for the existing I<ginko> Association on the I<boaccess.ecmwf.int>
234 Gateway.
235
236 B<ecaccess-association-put -gateway> I<boaccess.ecmwf.int> I<./ginko>
237
238 Push the Association back (once updated).
239
240 This is an example of an Association Descriptive File:
241
242 ##############################################################
243 # Main Parameters
244 ##############################################################
245 $active='yes'
246 $comment='Access to the archive system'
247 $grantedUserList='abc,def,jhi'
248 $directory='/tmp/data'
249 $hostName='hostname.example.ms'
250 $login='anonymous'
251 $protocol='genericFtp'
252
253 ##############################################################
254 # Data
255 ##############################################################
256 $data='
257 ftp.mkdirs="yes"
258 ftp.passive="no"
259 ftp.port="21"
260 ftp.suffix=".tmp"
261 ftp.usetmp="yes"'
262
263 Please note the multiple lines in the I<data> parameter.
264
265 =head1 SEE ALSO
266
267 B<ecaccess-association-delete>, B<ecaccess-association-list>, B<ecaccess-association-protocol>,
268 B<ecaccess-association-put> and B<ecaccess>.
269
270 =cut