deb-s3 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/deb/s3.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Deb
2
2
  module S3
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
data/lib/deb/s3/cli.rb CHANGED
@@ -9,24 +9,40 @@ require "deb/s3/release"
9
9
 
10
10
  class Deb::S3::CLI < Thor
11
11
 
12
- option :bucket,
13
- :required => true,
12
+ class_option :bucket,
14
13
  :type => :string,
15
14
  :aliases => "-b",
16
15
  :desc => "The name of the S3 bucket to upload to."
17
16
 
18
- option :codename,
17
+ class_option :codename,
19
18
  :default => "stable",
20
19
  :type => :string,
21
20
  :aliases => "-c",
22
21
  :desc => "The codename of the APT repository."
23
22
 
24
- option :section,
23
+ class_option :section,
25
24
  :default => "main",
26
25
  :type => :string,
27
26
  :aliases => "-s",
28
27
  :desc => "The section of the APT repository."
29
28
 
29
+ class_option :access_key,
30
+ :default => "$AMAZON_ACCESS_KEY_ID",
31
+ :type => :string,
32
+ :desc => "The access key for connecting to S3."
33
+
34
+ class_option :secret_key,
35
+ :default => "$AMAZON_SECRET_ACCESS_KEY",
36
+ :type => :string,
37
+ :desc => "The secret key for connecting to S3."
38
+
39
+ class_option :endpoint,
40
+ :type => :string,
41
+ :desc => "The region endpoint for connecting to S3."
42
+
43
+ desc "upload FILE",
44
+ "Uploads the given FILE to a S3 bucket as an APT repository."
45
+
30
46
  option :arch,
31
47
  :type => :string,
32
48
  :aliases => "-a",
@@ -39,20 +55,6 @@ class Deb::S3::CLI < Thor
39
55
  :desc => "The access policy for the uploaded files. " +
40
56
  "Can be public, private, or authenticated."
41
57
 
42
- option :access_key,
43
- :default => "$AMAZON_ACCESS_KEY_ID",
44
- :type => :string,
45
- :desc => "The access key for connecting to S3."
46
-
47
- option :secret_key,
48
- :default => "$AMAZON_SECRET_ACCESS_KEY",
49
- :type => :string,
50
- :desc => "The secret key for connecting to S3."
51
-
52
- option :endpoint,
53
- :type => :string,
54
- :desc => "The region endpoint for connecting to S3."
55
-
56
58
  option :sign,
57
59
  :type => :string,
58
60
  :desc => "Sign the Release file. Use --sign with your key ID to use " +
@@ -62,14 +64,16 @@ class Deb::S3::CLI < Thor
62
64
  :default => false,
63
65
  :type => :boolean,
64
66
  :aliases => "-p",
65
- :desc => "Whether to preserve other versions of a package " +
67
+ :desc => "Whether to preserve other versions of a package " +
66
68
  "in the repository when uploading one."
67
69
 
68
- desc "upload FILE",
69
- "Uploads the given FILE to a S3 bucket as an APT repository."
70
70
  def upload(file)
71
71
  # make sure the file exists
72
72
  error("File doesn't exist") unless File.exists?(file)
73
+
74
+ # configure AWS::S3
75
+ configure_s3_client
76
+
73
77
  Deb::S3::Utils.signing_key = options[:sign]
74
78
 
75
79
  # make sure we have a valid visibility setting
@@ -83,7 +87,6 @@ class Deb::S3::CLI < Thor
83
87
  else
84
88
  error("Invalid visibility setting given. Can be public, private, or authenticated.")
85
89
  end
86
- Deb::S3::Utils.bucket = options[:bucket]
87
90
 
88
91
  log("Examining package file #{File.basename(file)}")
89
92
  pkg = Deb::S3::Package.parse_file(file)
@@ -95,27 +98,6 @@ class Deb::S3::CLI < Thor
95
98
  error("No architcture given and unable to determine one from the file. " +
96
99
  "Please specify one with --arch [i386,amd64].") unless arch
97
100
 
98
- # configure AWS::S3
99
- access_key = if options[:access_key] == "$AMAZON_ACCESS_KEY_ID"
100
- ENV["AMAZON_ACCESS_KEY_ID"]
101
- else
102
- options[:access_key]
103
- end
104
- secret_key = if options[:secret_key] == "$AMAZON_SECRET_ACCESS_KEY"
105
- ENV["AMAZON_SECRET_ACCESS_KEY"]
106
- else
107
- options[:secret_key]
108
- end
109
- error("No access key given for S3. Please specify one.") unless access_key
110
- error("No secret access key given for S3. Please specify one.") unless secret_key
111
- AWS::S3::Base.establish_connection!(
112
- :access_key_id => access_key,
113
- :secret_access_key => secret_key
114
- )
115
- if options[:endpoint]
116
- AWS::S3::DEFAULT_HOST.replace options[:endpoint]
117
- end
118
-
119
101
  log("Retrieving existing manifests")
120
102
  release = Deb::S3::Release.retrieve(options[:codename])
121
103
  manifest = Deb::S3::Manifest.retrieve(options[:codename], options[:section], arch)
@@ -131,6 +113,47 @@ class Deb::S3::CLI < Thor
131
113
  log("Update complete.")
132
114
  end
133
115
 
116
+ desc "verify", "Verifies that the files in the package manifests exist"
117
+
118
+ option :fix_manifests,
119
+ :default => false,
120
+ :type => :boolean,
121
+ :aliases => "-f",
122
+ :desc => "Whether to fix problems in manifests when verifying."
123
+
124
+ def verify
125
+ configure_s3_client
126
+
127
+ log("Retrieving existing manifests")
128
+ release = Deb::S3::Release.retrieve(options[:codename])
129
+
130
+ %w[i386 amd64 all].each do |arch|
131
+ log("Checking for missing packages in: #{options[:codename]}/#{options[:section]} #{arch}")
132
+ manifest = Deb::S3::Manifest.retrieve(options[:codename], options[:section], arch)
133
+ missing_packages = []
134
+
135
+ manifest.packages.each do |p|
136
+ unless Deb::S3::Utils.s3_exists? p.url_filename_encoded
137
+ sublog("The following packages are missing:\n\n") if missing_packages.empty?
138
+ puts(p.generate)
139
+ puts("")
140
+
141
+ missing_packages << p
142
+ end
143
+ end
144
+
145
+ if options[:fix_manifests] && !missing_packages.empty?
146
+ log("Removing #{missing_packages.length} package(s) from the manifest...")
147
+ missing_packages.each { |p| manifest.packages.delete(p) }
148
+ manifest.write_to_s3 { |f| sublog("Transferring #{f}") }
149
+ release.update_manifest(manifest)
150
+ release.write_to_s3 { |f| sublog("Transferring #{f}") }
151
+
152
+ log("Update complete.")
153
+ end
154
+ end
155
+ end
156
+
134
157
  private
135
158
 
136
159
  def log(message)
@@ -146,4 +169,35 @@ class Deb::S3::CLI < Thor
146
169
  exit 1
147
170
  end
148
171
 
172
+ def access_key
173
+ if options[:access_key] == "$AMAZON_ACCESS_KEY_ID"
174
+ ENV["AMAZON_ACCESS_KEY_ID"]
175
+ else
176
+ options[:access_key]
177
+ end
178
+ end
179
+
180
+ def secret_key
181
+ if options[:secret_key] == "$AMAZON_SECRET_ACCESS_KEY"
182
+ ENV["AMAZON_SECRET_ACCESS_KEY"]
183
+ else
184
+ options[:secret_key]
185
+ end
186
+ end
187
+
188
+ def configure_s3_client
189
+ error("No access key given for S3. Please specify one.") unless access_key
190
+ error("No secret access key given for S3. Please specify one.") unless secret_key
191
+ error("No value provided for required options '--bucket'") unless options[:bucket]
192
+
193
+ AWS::S3::Base.establish_connection!(
194
+ :access_key_id => access_key,
195
+ :secret_access_key => secret_key
196
+ )
197
+
198
+ AWS::S3::DEFAULT_HOST.replace options[:endpoint] if options[:endpoint]
199
+
200
+ Deb::S3::Utils.bucket = options[:bucket]
201
+ end
202
+
149
203
  end
data/lib/deb/s3/utils.rb CHANGED
@@ -59,6 +59,6 @@ module Deb::S3::Utils
59
59
  end
60
60
 
61
61
  def s3_remove(path)
62
- AWS::S3::S3Object.delete(Deb::S3::Utils.bucket, path) if s3_exists?(path)
62
+ AWS::S3::S3Object.delete(path, Deb::S3::Utils.bucket) if s3_exists?(path)
63
63
  end
64
64
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deb-s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-13 00:00:00.000000000 Z
12
+ date: 2013-06-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.17.0
21
+ version: 0.18.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 0.17.0
29
+ version: 0.18.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: aws-s3
32
32
  requirement: !ruby/object:Gem::Requirement