Skip to content

Instantly share code, notes, and snippets.

@toddc-unity3d
Forked from petethepig/mfa-delete.rb
Last active August 29, 2015 14:06

Revisions

  1. toddc-unity3d revised this gist Sep 26, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mfa-delete.rb
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #!/usr/bin/env ruby
    require 'aws'
    require 'aws-sdk'

    if ARGV.length < 5
    print <<-EOF
  2. @invalid-email-address Anonymous created this gist Jan 29, 2013.
    27 changes: 27 additions & 0 deletions mfa-delete.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/usr/bin/env ruby
    require 'aws'

    if ARGV.length < 5
    print <<-EOF
    Usage: mfa-delete.rb <bucket_name> <aws_id> <aws_secret> <mfa_serial> <mfa_token> <s3_endpoint>
    <s3_endpoint> is optional
    EOF
    exit
    end

    bucket_name = ARGV[0]
    aws_id = ARGV[1]
    aws_key = ARGV[2]
    mfa_serial = ARGV[3]
    mfa_token = ARGV[4]
    s3_endpoint = ARGV[5] || "s3.amazonaws.com"

    s3 = AWS::S3.new({
    :s3_endpoint => s3_endpoint,
    :access_key_id => aws_id,
    :secret_access_key => aws_key
    })

    bucket = s3.buckets[bucket_name]
    bucket.enable_versioning :mfa_delete=>'Enabled', :mfa=>"#{mfa_serial} #{mfa_token}"