aws_role_creds 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/aws_role_creds.rb +44 -33
 - data/lib/aws_role_creds/version.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 753860b6d50a59c85f94b10065c06927d14b2a97
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 815dbe6bd48b3160d5d65c23b65729dce665a60d
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 6711dbe34131e618a6a3bf96de2f8b70cf7f4cea25a63eb3971a9f158ab68d56bf9d15dc10ac21fa7cf7f9985b05723843962f35d020e2b91d87befc4c92e8f4
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: c787a65c55190a64c174f5cd08ce51471a207a03e59fd0b332aefad5fd3b940f950e0a977f956d052b8e584962ff141ad79d46666ecb446967aba9b2dc988365
         
     | 
    
        data/lib/aws_role_creds.rb
    CHANGED
    
    | 
         @@ -9,7 +9,8 @@ module AwsRoleCreds 
     | 
|
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
                IN_FILE = "#{ENV['HOME']}/.aws/config.yaml"
         
     | 
| 
       11 
11 
     | 
    
         
             
                # The config file we write out
         
     | 
| 
       12 
     | 
    
         
            -
                 
     | 
| 
      
 12 
     | 
    
         
            +
                CONFIG_OUT_FILE = "#{ENV['HOME']}/.aws/config"
         
     | 
| 
      
 13 
     | 
    
         
            +
                CREDENTIALS_OUT_FILE = "#{ENV['HOME']}/.aws/credentials"
         
     | 
| 
       13 
14 
     | 
    
         
             
                SESSION_CREDS_FILE = "#{ENV['HOME']}/.aws/session.yaml"
         
     | 
| 
       14 
15 
     | 
    
         
             
                SESSION_DURATION = 86400
         
     | 
| 
       15 
16 
     | 
    
         
             
                ROLE_DURATION = 3600
         
     | 
| 
         @@ -36,9 +37,8 @@ module AwsRoleCreds 
     | 
|
| 
       36 
37 
     | 
    
         
             
                    region = p['region'] || REGION
         
     | 
| 
       37 
38 
     | 
    
         
             
                    duration = p['duration'] || SESSION_DURATION
         
     | 
| 
       38 
39 
     | 
    
         
             
                    if @session_credentials.key?(name)
         
     | 
| 
       39 
     | 
    
         
            -
                         
     | 
| 
      
 40 
     | 
    
         
            +
                        next if @session_credentials[name]['expiration'] > Time.now 
         
     | 
| 
       40 
41 
     | 
    
         
             
                    end
         
     | 
| 
       41 
     | 
    
         
            -
                    puts "#{name}"
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
43 
     | 
    
         
             
                    if p['id'] and p['key']
         
     | 
| 
       44 
44 
     | 
    
         
             
                        client = Aws::STS::Client.new(
         
     | 
| 
         @@ -114,38 +114,49 @@ module AwsRoleCreds 
     | 
|
| 
       114 
114 
     | 
    
         | 
| 
       115 
115 
     | 
    
         
             
                # Write out config file
         
     | 
| 
       116 
116 
     | 
    
         
             
                # first make a backup
         
     | 
| 
       117 
     | 
    
         
            -
                OUT_FILE.each do |o|
         
     | 
| 
       118 
     | 
    
         
            -
                    FileUtils.cp( o, "#{o}.backup" )
         
     | 
| 
       119 
     | 
    
         
            -
             
     | 
| 
       120 
     | 
    
         
            -
                    # create a new ini file object
         
     | 
| 
       121 
     | 
    
         
            -
                    config = IniFile.new
         
     | 
| 
       122 
     | 
    
         
            -
                    config.filename = o
         
     | 
| 
       123 
     | 
    
         
            -
             
     | 
| 
       124 
     | 
    
         
            -
                    config['default'] = { "region" => REGION }
         
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
                    # set properties
         
     | 
| 
       127 
     | 
    
         
            -
                    @session_credentials.each do |k, c|
         
     | 
| 
       128 
     | 
    
         
            -
                        config["profile #{k}"] = {
         
     | 
| 
       129 
     | 
    
         
            -
                            "aws_access_key_id" => "#{c['access_key_id']}",
         
     | 
| 
       130 
     | 
    
         
            -
                            "aws_secret_access_key" => "#{c['secret_access_key']}",
         
     | 
| 
       131 
     | 
    
         
            -
                            "aws_security_token" => "#{c['session_token']}",
         
     | 
| 
       132 
     | 
    
         
            -
                            "region" => "#{c['region']}",
         
     | 
| 
       133 
     | 
    
         
            -
                        }
         
     | 
| 
       134 
     | 
    
         
            -
                        puts "Profile #{k} created"
         
     | 
| 
       135 
     | 
    
         
            -
                    end
         
     | 
| 
       136 
117 
     | 
    
         | 
| 
       137 
     | 
    
         
            -
             
     | 
| 
       138 
     | 
    
         
            -
             
     | 
| 
       139 
     | 
    
         
            -
             
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
      
 118 
     | 
    
         
            +
                FileUtils.cp( CONFIG_OUT_FILE, "#{CONFIG_OUT_FILE}.backup" )
         
     | 
| 
      
 119 
     | 
    
         
            +
                FileUtils.cp( CREDENTIALS_OUT_FILE, "#{CREDENTIALS_OUT_FILE}.backup" )
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
                # create a new ini file object
         
     | 
| 
      
 122 
     | 
    
         
            +
                config = IniFile.new
         
     | 
| 
      
 123 
     | 
    
         
            +
                config.filename = CONFIG_OUT_FILE
         
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
      
 125 
     | 
    
         
            +
                credentials = IniFile.new
         
     | 
| 
      
 126 
     | 
    
         
            +
                credentials.filename = CREDENTIALS_OUT_FILE
         
     | 
| 
       146 
127 
     | 
    
         | 
| 
       147 
     | 
    
         
            -
             
     | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
      
 128 
     | 
    
         
            +
                config['default'] = { "region" => REGION }
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
                # set properties
         
     | 
| 
      
 131 
     | 
    
         
            +
                @session_credentials.each do |k, c|
         
     | 
| 
      
 132 
     | 
    
         
            +
                    profile = {
         
     | 
| 
      
 133 
     | 
    
         
            +
                        "aws_access_key_id" => "#{c['access_key_id']}",
         
     | 
| 
      
 134 
     | 
    
         
            +
                        "aws_secret_access_key" => "#{c['secret_access_key']}",
         
     | 
| 
      
 135 
     | 
    
         
            +
                        "aws_security_token" => "#{c['session_token']}",
         
     | 
| 
      
 136 
     | 
    
         
            +
                        "region" => "#{c['region']}",
         
     | 
| 
      
 137 
     | 
    
         
            +
                    }
         
     | 
| 
      
 138 
     | 
    
         
            +
                    
         
     | 
| 
      
 139 
     | 
    
         
            +
                    config["profile #{k}"] = profile
         
     | 
| 
      
 140 
     | 
    
         
            +
                    credentials["#{k}"] = profile
         
     | 
| 
       149 
141 
     | 
    
         
             
                end
         
     | 
| 
       150 
142 
     | 
    
         | 
| 
      
 143 
     | 
    
         
            +
                @role_credentials.each do |k, c|
         
     | 
| 
      
 144 
     | 
    
         
            +
                    profile = {
         
     | 
| 
      
 145 
     | 
    
         
            +
                        "aws_access_key_id" => "#{c['access_key_id']}",
         
     | 
| 
      
 146 
     | 
    
         
            +
                        "aws_secret_access_key" => "#{c['secret_access_key']}",
         
     | 
| 
      
 147 
     | 
    
         
            +
                        "aws_security_token" => "#{c['session_token']}",
         
     | 
| 
      
 148 
     | 
    
         
            +
                        "region" => "#{c['region']}",
         
     | 
| 
      
 149 
     | 
    
         
            +
                    }
         
     | 
| 
      
 150 
     | 
    
         
            +
                    
         
     | 
| 
      
 151 
     | 
    
         
            +
                    config["profile #{k}"] = profile
         
     | 
| 
      
 152 
     | 
    
         
            +
                    credentials["#{k}"] = profile
         
     | 
| 
      
 153 
     | 
    
         
            +
                end
         
     | 
| 
      
 154 
     | 
    
         
            +
             
     | 
| 
      
 155 
     | 
    
         
            +
                # save file
         
     | 
| 
      
 156 
     | 
    
         
            +
                config.write()
         
     | 
| 
      
 157 
     | 
    
         
            +
                puts "#{CONFIG_OUT_FILE} updated"
         
     | 
| 
      
 158 
     | 
    
         
            +
                credentials.write()
         
     | 
| 
      
 159 
     | 
    
         
            +
                puts "#{CREDENTIALS_OUT_FILE} updated"
         
     | 
| 
      
 160 
     | 
    
         
            +
             
     | 
| 
      
 161 
     | 
    
         
            +
             
     | 
| 
       151 
162 
     | 
    
         
             
            end
         
     |