1
# Copyright 2008 Amazon.com, Inc. or its affiliates. All Rights
2
# Reserved. Licensed under the Amazon Software License (the
3
# "License"). You may not use this file except in compliance with the
4
# License. A copy of the License is located at
5
# http://aws.amazon.com/asl or in the "license" file accompanying this
6
# file. This file is distributed on an "AS IS" BASIS, WITHOUT
7
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
8
# the License for the specific language governing permissions and
9
# limitations under the License.
12
require 'ec2/amitools/version'
14
#------------------------------------------------------------------------------#
16
class DeleteBundleParameters < OptionParser
18
BUCKET_DESCRIPTION = "The bucket containing the bundled AMI."
19
MANIFEST_DESCRIPTION = "The path to the unencrypted manifest file."
20
PREFIX_DESCRIPTION = "The bundled AMI part filename prefix."
21
USER_DESCRIPTION = "The user's AWS access key ID."
22
PASS_DESCRIPTION = "The user's AWS secret access key."
23
DEBUG_DESCRIPTION = "Print debug messages."
24
HELP_DESCRIPTION = "Display the help message and exit."
25
MANUAL_DESCRIPTION = "Display the manual and exit."
26
RETRY_DESCRIPTION = "Automatically retry failed deletes. Use with caution."
27
URL_DESCRIPTION = "The S3 service URL. Defaults to https://s3.amazonaws.com."
28
YES_DESCRIPTION = "Automatically answer 'y' without asking."
29
CLEAR_DESCRIPTION = "Delete the bucket if empty. Not done by default"
30
VERSION_DESCRIPTION = "Display the version and copyright notice and then exit."
32
attr_accessor :bucket,
46
#----------------------------------------------------------------------------#
48
class Error < RuntimeError
50
class MissingMandatory < Error
51
def initialize( name )
52
super( "missing mandatory parameter: #{name}" )
56
class InvalidValue < Error
57
def initialize( name, value )
58
super( "#{name} value invalid: #{value.to_s}" )
64
#----------------------------------------------------------------------------#
66
def initialize( argv, name )
71
self.banner = "Usage: #{name} PARAMETERS"
74
# Mandatory parameters.
77
separator( "MANDATORY PARAMETERS" )
79
on( '-b', '--bucket BUCKET', String, BUCKET_DESCRIPTION ) do |bucket|
83
on( '-a', '--access-key USER', String, USER_DESCRIPTION ) do |user|
87
on( '-s', '--secret-key PASSWORD', String, PASS_DESCRIPTION ) do |pass|
92
# Optional parameters.
95
self.separator( "OPTIONAL PARAMETERS" )
97
on( '-m', '--manifest PATH', String, MANIFEST_DESCRIPTION ) do |manifest|
98
raise Error::InvalidValue.new( "--manifest", manifest ) unless ( File::exist?( manifest ) and File::file?( manifest ) )
102
on( '-p', '--prefix PREFIX', String, PREFIX_DESCRIPTION ) do |prefix|
106
on( '--clear', CLEAR_DESCRIPTION ) do
110
on( '--debug', DEBUG_DESCRIPTION ) do
114
on( '--retry', RETRY_DESCRIPTION ) do
118
on( '--url URL', String, URL_DESCRIPTION ) do |url|
122
on( '-h', '--help', HELP_DESCRIPTION ) do
126
on( '--manual', MANUAL_DESCRIPTION ) do
130
on( '-y', '--yes', YES_DESCRIPTION ) do
134
on( '--version', VERSION_DESCRIPTION ) do
135
puts version_copyright_string()
140
# Parse the command line parameters.
145
unless @show_help or @manual
147
# Verify mandatory parameters.
149
raise Error::MissingMandatory.new( '--bucket' ) unless @bucket
150
raise Error::MissingMandatory.new( '--manifest or --prefix' ) unless @manifest or @prefix
151
raise Error::MissingMandatory.new( '--access-key' ) unless @user
152
raise Error::MissingMandatory.new( '--secret-key' ) unless @pass
155
# Set defaults for optional parameters.
157
@url = 'https://s3.amazonaws.com' unless @url