Skip to content

Commit

Permalink
Replace UUIDTools with SecureRandom.uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
wvanbergen committed Feb 6, 2014
1 parent fa46f5c commit c199fcd
Show file tree
Hide file tree
Showing 20 changed files with 26 additions and 29 deletions.
2 changes: 1 addition & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@

class Book < AWS::Record::HashModel
string_attr :isbn, :default_value => lambda {
UUIDTools::UUID.random_create }
SecureRandom.uuid }
end

* lib/aws/record/abstract_base.rb, lib/aws/record/hash_model.rb,
Expand Down
1 change: 0 additions & 1 deletion aws-sdk.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Gem::Specification.new do |s|
s.author = 'Amazon Web Services'
s.homepage = 'http://aws.amazon.com/sdkforruby'

s.add_dependency('uuidtools', '~> 2.1')
s.add_dependency('nokogiri', '>= 1.4.4')
s.add_dependency('json', '~> 1.4')

Expand Down
2 changes: 1 addition & 1 deletion bin/aws-rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ unless options[:repl] == 'irb'
# we require them up front to squelch warnings from pry
require 'nokogiri'
require 'json'
require 'uuidtools'
require 'securerandom'
end

class PryNotAvailable < StandardError; end
Expand Down
2 changes: 1 addition & 1 deletion features/route_53/step_definitions/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
When /^I call \#create_hosted_zone$/ do

@name = "ruby-integration-test-#{Time.now.to_i}-#{rand(1000)}.com"
@caller_reference = UUIDTools::UUID.random_create.to_s
@caller_reference = SecureRandom.uuid

@response = @route_53_client.create_hosted_zone(
:name => @name,
Expand Down
4 changes: 2 additions & 2 deletions features/simple_workflow/step_definitions/domains.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

require 'uuidtools'
require 'securerandom'

When /^I register a simple workflow domain$/ do
name = "ruby-integration-test-#{UUIDTools::UUID.random_create}"
name = "ruby-integration-test-#{SecureRandom.uuid}"
@domain = @swf.domains.create(name, 1)
@registered_domains << @domain
end
Expand Down
6 changes: 3 additions & 3 deletions lib/aws/core/policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

require 'uuidtools'
require 'securerandom'
require 'date'
require 'json'

Expand Down Expand Up @@ -84,7 +84,7 @@ def initialize(opts = {})
if opts.has_key?(:id) or opts.has_key?("Id")
@id = opts[:id] || opts["Id"]
else
@id = UUIDTools::UUID.timestamp_create.to_s.tr('-','')
@id = SecureRandom.uuid.tr('-','')
end
if opts.has_key?(:version) or opts.has_key?("Version")
@version = opts[:version] || opts["Version"]
Expand Down Expand Up @@ -748,7 +748,7 @@ class Statement
# Policy#deny to add conditions to a statement.
# @see S3::Client
def initialize(opts = {})
self.sid = UUIDTools::UUID.timestamp_create.to_s.tr('-','')
self.sid = SecureRandom.uuid.tr('-','')
self.conditions = ConditionBlock.new

parse_options(opts)
Expand Down
4 changes: 2 additions & 2 deletions lib/aws/ec2/instance_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# language governing permissions and limitations under the License.

require 'base64'
require 'uuidtools'
require 'securerandom'

module AWS
class EC2
Expand Down Expand Up @@ -289,7 +289,7 @@ def create options = {}

security_group_opts(options)

options[:client_token] = UUIDTools::UUID.timestamp_create.to_s
options[:client_token] = SecureRandom.uuid

resp = client.run_instances(options)

Expand Down
2 changes: 1 addition & 1 deletion lib/aws/record/abstract_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

require 'uuidtools'
require 'securerandom'
require 'set'

module AWS
Expand Down
2 changes: 1 addition & 1 deletion lib/aws/record/hash_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def add_attribute(attribute)
def populate_id
hash_key = self.class.hash_key_attribute
if hash_key.options[:default_hash_key_attribute]
self[hash_key.name] = UUIDTools::UUID.random_create.to_s.downcase
self[hash_key.name] = SecureRandom.uuid
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/aws/record/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def hydrate(id, data)

# @api private
def populate_id
@_id = UUIDTools::UUID.random_create.to_s.downcase
@_id = SecureRandom.uuid
end

# @api private
Expand Down
4 changes: 2 additions & 2 deletions lib/aws/s3/bucket_lifecycle_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# language governing permissions and limitations under the License.

require 'nokogiri'
require 'uuidtools'
require 'securerandom'

module AWS
class S3
Expand Down Expand Up @@ -165,7 +165,7 @@ def add_rule prefix, expiration_time = nil, options = {}
options[:expiration_time] = expiration_time
end

id = options[:id] || UUIDTools::UUID.random_create.to_s
id = options[:id] || SecureRandom.uuid
opts = {
:status => options[:disabled] == true ? 'Disabled' : 'Enabled',
:expiration_time => options[:expiration_time],
Expand Down
4 changes: 2 additions & 2 deletions lib/aws/simple_workflow/decision_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def responded?
#
def schedule_activity_task activity_type, options = {}

options[:activity_id] ||= UUIDTools::UUID.random_create.to_s
options[:activity_id] ||= SecureRandom.uuid

options[:activity_type] = case activity_type
when Hash
Expand Down Expand Up @@ -448,7 +448,7 @@ def record_marker marker_name, options = {}
# @return [String] Returns the id of the timer.
#
def start_timer start_to_fire_timeout, options = {}
options[:timer_id] ||= UUIDTools::UUID.random_create.to_s
options[:timer_id] ||= SecureRandom.uuid
options[:start_to_fire_timeout] = start_to_fire_timeout
duration_opts(options, :start_to_fire_timeout)
add_decision :start_timer, options
Expand Down
2 changes: 1 addition & 1 deletion lib/aws/simple_workflow/decision_task_collection.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'uuidtools'
require 'securerandom'

# Copyright 2011-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
Expand Down
2 changes: 1 addition & 1 deletion lib/aws/simple_workflow/option_formatters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def start_execution_opts options, workflow_type = nil

if workflow_type

options[:workflow_id] ||= UUIDTools::UUID.random_create.to_s
options[:workflow_id] ||= SecureRandom.uuid

if workflow_type.is_a?(WorkflowType)
options[:workflow_type] = {}
Expand Down
2 changes: 1 addition & 1 deletion lib/aws/simple_workflow/workflow_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

require 'uuidtools'
require 'securerandom'

module AWS
class SimpleWorkflow
Expand Down
4 changes: 2 additions & 2 deletions spec/aws/core/policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ module AWS::Core
end

it 'should use a UUID to generate an alphanumeric ID' do
UUIDTools::UUID.stub(:timestamp_create).
and_return(UUIDTools::UUID.parse("934257b4-452e-11e0-8f5e-00254bfffeb7"))
SecureRandom.stub(:uuid).
and_return("934257b4-452e-11e0-8f5e-00254bfffeb7")
hash["Id"].should == "934257b4452e11e08f5e00254bfffeb7"
end

Expand Down
3 changes: 1 addition & 2 deletions spec/aws/ec2/instance_collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,7 @@ def stub_two_members(resp)

it 'should provide a UUID client token' do
uuid = "ee819144-6d1f-11e0-bf36-00254bfffeb7"
UUIDTools::UUID.stub(:timestamp_create).
and_return(uuid)
SecureRandom.stub(:uuid).and_return(uuid)
client.should_receive(:run_instances).
with(hash_including(:client_token => uuid)).
and_return(resp)
Expand Down
2 changes: 1 addition & 1 deletion spec/aws/s3/bucket_lifecycle_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class S3
let(:uuid) { 'abc-xyz-123-456' }

before(:each) do
UUIDTools::UUID.stub(:random_create).and_return(uuid)
SecureRandom.stub(:uuid).and_return(uuid)
end

context '#rules' do
Expand Down
2 changes: 1 addition & 1 deletion spec/aws/simple_workflow/decision_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class SimpleWorkflow
context 'decisions' do

before(:each) do
UUIDTools::UUID.stub(:random_create).and_return('uuid')
SecureRandom.stub(:uuid).and_return('uuid')
end

let(:activity_type) { domain.activity_types['name','version'] }
Expand Down
3 changes: 1 addition & 2 deletions spec/shared/policy_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ module Core
context '#to_h' do

it 'should have an Sid generated from a UUID' do
UUIDTools::UUID.stub(:timestamp_create).
and_return(UUIDTools::UUID.parse("934257b4-452e-11e0-8f5e-00254bfffeb7"))
SecureRandom.stub(:uuid).and_return("934257b4-452e-11e0-8f5e-00254bfffeb7")
statement.to_h["Sid"].should == "934257b4452e11e08f5e00254bfffeb7"
end

Expand Down

0 comments on commit c199fcd

Please sign in to comment.