csv-to-fog 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eccc05de75d2e2941abaddebd94a9919ae6dcbb0
4
+ data.tar.gz: a2219810c5347ad46847c542d6b50719142a5e8b
5
+ SHA512:
6
+ metadata.gz: cde52370a92331978a4023e1bf5311876f2219450f49cb3766e30d59c3e0fe5da2070cff7a31ccb5220de5e0c509e940011c50b981abca347646eddfc8908b06
7
+ data.tar.gz: c0ee1e796eb351cafdf323011d1e958369eac5a992669758ede750b32e2b3f4e028c52ad57e0f2ff6cff3eb293e4afb5860071a1e7017dc67b8cf49a2a832f15
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
@@ -0,0 +1,7 @@
1
+ Change Log
2
+ ==========
3
+
4
+ v1.0.0
5
+ ------
6
+
7
+ - First release - outputs to STDOUT
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in csv-to-fog.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Dr Nic Williams
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,63 @@
1
+ CSV to .fog
2
+ ===========
3
+
4
+ Converts a CSV file of credentials into a `.fog` file format.
5
+
6
+ Given a CSV file (say exported from Google Spreadsheets or Excel) in `spec/fixtures/aws.csv`:
7
+
8
+ ```csv
9
+ Student #,Email,AWS Password,Master Key,Master Secret
10
+ student1,training+student1@starkandwayne.com,PASSWORD1,STUDENT1KEY,STUDENT1SECRET
11
+ student2,training+student2@starkandwayne.com,PASSWORD2,STUDENT2KEY,STUDENT2SECRET
12
+ ```
13
+
14
+ Run the following:
15
+
16
+ ```
17
+ csv-to-fog --key "Student #" --map "aws_access_key_id:Master Key" --map "aws_secret_access_key:Master Secret" spec/fixtures/aws.csv
18
+ ```
19
+
20
+ Outputs:
21
+
22
+ ```yaml
23
+ :student1:
24
+ :aws_access_key_id: STUDENT1KEY
25
+ :aws_secret_access_key: STUDENT1SECRET
26
+ :student2:
27
+ :aws_access_key_id: STUDENT2KEY
28
+ :aws_secret_access_key: STUDENT2SECRET
29
+ ```
30
+
31
+ By storing the output into a `yml` file, you can then load it into the `fog` CLI or a Ruby program that uses fog:
32
+
33
+ ```
34
+ $ csv-to-fog --key "Student #" --map "aws_access_key_id:Master Key" --map "aws_secret_access_key:Master Secret" spec/fixtures/aws.csv > aws.yml
35
+
36
+ $ fog -C aws.yml student1
37
+ Welcome to fog interactive!
38
+ :student1 provides AWS
39
+ ```
40
+
41
+ Requires
42
+ --------
43
+
44
+ - Ruby 1.9+
45
+ - RubyGems
46
+
47
+ Installation
48
+ ------------
49
+
50
+ Install using RubyGems:
51
+
52
+ ```
53
+ $ gem install csv-to-fog
54
+ ```
55
+
56
+ Contributing
57
+ ------------
58
+
59
+ 1. Fork it ( https://github.com/[my-github-username]/csv-to-fog/fork )
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`\)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`\)
62
+ 4. Push to the branch (`git push origin my-new-feature`\)
63
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.expand_path("../../lib", __FILE__))
4
+ require 'csv-to-fog'
5
+
6
+ CsvToFog::App.run(ARGV)
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'csv-to-fog/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "csv-to-fog"
8
+ spec.version = CsvToFog::VERSION
9
+ spec.authors = ["Dr Nic Williams"]
10
+ spec.email = ["drnicwilliams@gmail.com"]
11
+ spec.summary = %q{Converts a CSV file of credentials into a `.fog` file format}
12
+ spec.description = %q{Converts a CSV file of credentials into a `.fog` file format}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,4 @@
1
+ require "csv-to-fog/version"
2
+ require "csv-to-fog/app"
3
+ module CsvToFog
4
+ end
@@ -0,0 +1,88 @@
1
+ require "optparse"
2
+ require "csv"
3
+ require "yaml"
4
+
5
+ class CsvToFog::App
6
+ def self.run(args)
7
+ key = nil
8
+ unparsed_mappings = []
9
+ args = OptionParser.new do |opts|
10
+ opts.banner = "csv-to-fog {options} path/to/file.csv"
11
+ opts.separator ""
12
+ opts.separator "Options are ..."
13
+
14
+ opts.on_tail("-h", "--help", "-H", "Display this help message.") do
15
+ puts opts
16
+ exit
17
+ end
18
+
19
+ opts.on '--key="Student #"', '-k',
20
+ 'CSV Header Key to become the Fog key',
21
+ lambda { |value| key = value }
22
+ opts.on '--map="aws_access_key_id:Master Key"', '-m',
23
+ 'Map "Fog key:CSV Header Key"',
24
+ lambda { |value| unparsed_mappings << value }
25
+ opts.environment('RAKEOPT')
26
+ end.parse(args)
27
+
28
+ file_path = args.shift
29
+ app = self.new(file_path, key, unparsed_mappings)
30
+ app.load_file_and_validate!
31
+ app.run
32
+ end
33
+
34
+ def initialize(file_path, key, unparsed_mappings)
35
+ @file_path = file_path
36
+ @key = key
37
+ @mappings = parse_mappings(unparsed_mappings)
38
+ end
39
+
40
+ def parse_mappings(unparsed_mappings)
41
+ unparsed_mappings.inject([]) do |mappings, mapping|
42
+ fog, csv = mapping.split(":")
43
+ if !csv || csv == ""
44
+ $stderr.puts "Skipping --map \"#{mapping}\""
45
+ else
46
+ mappings << [fog, csv]
47
+ end
48
+ mappings
49
+ end
50
+ end
51
+
52
+ def load_file_and_validate!
53
+ errors = false
54
+ unless @key
55
+ $stderr.puts "--key is required"
56
+ errors = true
57
+ end
58
+ if @mappings.size == 0
59
+ $stderr.puts "--map is required"
60
+ errors = true
61
+ end
62
+ if !@file_path
63
+ $stderr.puts "Must pass path to CSV file"
64
+ errors = true
65
+ elsif !File.exists?(@file_path)
66
+ $stderr.puts "File #{@file_path} doesn't exist"
67
+ errors = true
68
+ end
69
+ exit 1 if errors
70
+
71
+ @rows = []
72
+ CSV.foreach(@file_path, headers: true) do |row|
73
+ @rows << row
74
+ end
75
+ end
76
+
77
+ def run
78
+ @fog_file = {}
79
+ @rows.each do |row|
80
+ fog_key = row[@key].to_sym
81
+ credentials = @fog_file[fog_key] = {}
82
+ @mappings.each do |fog, csv|
83
+ credentials[fog.to_sym] = row[csv]
84
+ end
85
+ end
86
+ puts @fog_file.to_yaml
87
+ end
88
+ end
@@ -0,0 +1,3 @@
1
+ module CsvToFog
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,3 @@
1
+ Student #,Email,AWS Password,Master Key,Master Secret
2
+ student1,training+student1@starkandwayne.com,PASSWORD1,STUDENT1KEY,STUDENT1SECRET
3
+ student2,training+student2@starkandwayne.com,PASSWORD2,STUDENT2KEY,STUDENT2SECRET
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: csv-to-fog
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dr Nic Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Converts a CSV file of credentials into a `.fog` file format
42
+ email:
43
+ - drnicwilliams@gmail.com
44
+ executables:
45
+ - csv-to-fog
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ChangeLog.md
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/csv-to-fog
56
+ - csv-to-fog.gemspec
57
+ - lib/csv-to-fog.rb
58
+ - lib/csv-to-fog/app.rb
59
+ - lib/csv-to-fog/version.rb
60
+ - spec/fixtures/aws.csv
61
+ homepage: ''
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.4.3
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Converts a CSV file of credentials into a `.fog` file format
85
+ test_files:
86
+ - spec/fixtures/aws.csv