awssession 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/changelog.md +5 -0
- data/exe/awssession +20 -0
- data/lib/awssession.rb +13 -11
- data/lib/awssession/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 125bfaca0503b5a1a54324e048fb3bc0bd954493
|
4
|
+
data.tar.gz: 233d3a2af38c75b0fda959437fc1819141e247b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66743d294271c79eed0acc09e79818536789cf71a09d51f82adafa37da31a9b621946a87658ba14cee78d2e42fe55d576e8c8bf3f920c6da5cb4d68858ba47ae
|
7
|
+
data.tar.gz: be068b2a3ae0e6d7dec57f82656cbaa914e25890d40e643f15b1dedb20657375db616039406db7880253fc2475cece8d67ec66d9a347a68219922fda2cbbba2f
|
data/.gitignore
CHANGED
data/changelog.md
CHANGED
@@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file.
|
|
3
3
|
|
4
4
|
## [Unreleased]
|
5
5
|
|
6
|
+
## [0.3.0] - 2017-10-11
|
7
|
+
### Added
|
8
|
+
- CLI script `awssession` to wrap commands needing AWS sessions.
|
9
|
+
- Create symlink in 'current' directory to role session file.
|
10
|
+
|
6
11
|
## [0.2.5] - 2017-10-06
|
7
12
|
### Changed
|
8
13
|
- Cleanup + session naming improvement
|
data/exe/awssession
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'awssession'
|
4
|
+
require 'aws_config'
|
5
|
+
|
6
|
+
profile_name = ARGV.shift
|
7
|
+
profile = AWSConfig[profile_name]
|
8
|
+
begin
|
9
|
+
profile['name'] = profile_name
|
10
|
+
rescue NoMethodError
|
11
|
+
puts "Requested role '#{profile_name}' not found."
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
|
15
|
+
awssession = AwsSession.new(profile: profile)
|
16
|
+
awssession.start
|
17
|
+
|
18
|
+
exec(ARGV.join(' '))
|
19
|
+
|
20
|
+
# vim:set fileencoding=utf8 fileformat=unix filetype=ruby tabstop=2 expandtab:
|
data/lib/awssession.rb
CHANGED
@@ -4,6 +4,7 @@ require 'aws-sdk-core'
|
|
4
4
|
require 'yaml'
|
5
5
|
require 'io/console'
|
6
6
|
require 'time'
|
7
|
+
require 'fileutils'
|
7
8
|
|
8
9
|
# AWS Session creation with profile
|
9
10
|
# Structure of options[:profile]
|
@@ -21,9 +22,9 @@ class AwsSession
|
|
21
22
|
def initialize(options)
|
22
23
|
@profile = options[:profile]
|
23
24
|
@sts_lifetime = options[:sts_lifetime] || 129_600
|
24
|
-
@sts_filename = options[:sts_filename] ||
|
25
|
+
@sts_filename = options[:sts_filename] || 'aws-sts-session.yaml'
|
25
26
|
@role_lifetime = options[:role_lifetime] || 3_600
|
26
|
-
@role_filename = options[:role_filename] ||
|
27
|
+
@role_filename = options[:role_filename] || 'aws-role-session.yaml'
|
27
28
|
@session_save_path = options[:session_save_path] || "#{Dir.home}/.aws/cache"
|
28
29
|
@debug = options[:debug] || 0
|
29
30
|
end
|
@@ -34,29 +35,30 @@ class AwsSession
|
|
34
35
|
end
|
35
36
|
|
36
37
|
def load_session
|
37
|
-
load_role_session if File.file?("#{@session_save_path}/#{@role_filename}")
|
38
|
-
load_sts_session if @role_session.nil? && File.file?("#{@session_save_path}/#{@sts_filename}")
|
38
|
+
load_role_session if File.file?("#{@session_save_path}/#{@profile.name}_#{@role_filename}")
|
39
|
+
load_sts_session if @role_session.nil? && File.file?("#{@session_save_path}/#{@profile.name}_#{@sts_filename}")
|
39
40
|
end
|
40
41
|
|
41
42
|
def load_role_session
|
42
|
-
@role_session = YAML.load_file("#{@session_save_path}/#{@role_filename}") # Load
|
43
|
+
@role_session = YAML.load_file("#{@session_save_path}/#{@profile.name}_#{@role_filename}") # Load
|
43
44
|
if Time.now > @role_session.credentials.expiration
|
44
45
|
# or soooooooon !
|
45
46
|
puts 'Role session credentials expired. Removing obsolete role session file' if @debug > 0
|
46
47
|
@role_session = nil
|
47
|
-
File.delete("#{@session_save_path}/#{@role_filename}")
|
48
|
-
|
49
|
-
|
48
|
+
File.delete("#{@session_save_path}/#{@profile.name}_#{@role_filename}")
|
49
|
+
else
|
50
|
+
FileUtils.ln_s("#{@session_save_path}/#{@profile.name}_#{@role_filename}", "./.#{@role_filename}", force: true)
|
51
|
+
puts 'Found valid role session credentials.' if @debug > 0
|
50
52
|
end
|
51
53
|
end
|
52
54
|
|
53
55
|
def load_sts_session
|
54
|
-
@sts_session = YAML.load_file("#{@session_save_path}/#{@sts_filename}") # Load
|
56
|
+
@sts_session = YAML.load_file("#{@session_save_path}/#{@profile.name}_#{@sts_filename}") # Load
|
55
57
|
if Time.now > @sts_session.credentials.expiration
|
56
58
|
# or soooooooon !
|
57
59
|
puts 'STS session credentials expired. Removing obsolete sts session file' if @debug > 0
|
58
60
|
@sts_session = nil
|
59
|
-
File.delete("#{@session_save_path}/#{@sts_filename}")
|
61
|
+
File.delete("#{@session_save_path}/#{@profile.name}_#{@sts_filename}")
|
60
62
|
elsif @debug > 0
|
61
63
|
puts 'Found valid sts session credentials.'
|
62
64
|
end
|
@@ -107,7 +109,7 @@ class AwsSession
|
|
107
109
|
|
108
110
|
def save_session(file, session)
|
109
111
|
FileUtils.mkdir_p(@session_save_path)
|
110
|
-
File.open("#{@session_save_path}/#{file}", 'w') { |f| f.write session.to_yaml }
|
112
|
+
File.open("#{@session_save_path}/#{@profile.name}_#{file}", 'w') { |f| f.write session.to_yaml }
|
111
113
|
end
|
112
114
|
|
113
115
|
def credentials
|
data/lib/awssession/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: awssession
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan - Zipkid - Goethals
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,7 +97,8 @@ dependencies:
|
|
97
97
|
description: AwsSession creates an AWS session
|
98
98
|
email:
|
99
99
|
- stefan.goethals@vrt.be
|
100
|
-
executables:
|
100
|
+
executables:
|
101
|
+
- awssession
|
101
102
|
extensions: []
|
102
103
|
extra_rdoc_files: []
|
103
104
|
files:
|
@@ -112,6 +113,7 @@ files:
|
|
112
113
|
- bin/console
|
113
114
|
- bin/setup
|
114
115
|
- changelog.md
|
116
|
+
- exe/awssession
|
115
117
|
- lib/awssession.rb
|
116
118
|
- lib/awssession/version.rb
|
117
119
|
- license.txt
|