env_compare 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f6417ed28ff6a91297a3ecc58af784d6819d4f59465984720b57cf9e495f553b
4
+ data.tar.gz: a3e325abdeef448d2dac80474a8f51d433ebb2c047f6bea309b9cdde136d0f09
5
+ SHA512:
6
+ metadata.gz: d61b7acab0d9661c8e36e2e3e92f1c53cb263184d0c4dfdbbcbd0dcfbcffdc954700384fa77dd0b1a1adc3106a7a4380125e24f352f341b05c9a871e7506d758
7
+ data.tar.gz: de8a8214ceadb18c47f3abb2ca18e402286ba99ea2b92439a1f375142cd8225be3fe27dab6685912611d36017bc55887b854b5f979e12a6bcb445c5e8a82f573
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ *.html
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,29 @@
1
+ # The behavior of RuboCop can be controlled via the .rubocop.yml
2
+ # configuration file. It makes it possible to enable/disable
3
+ # certain cops (checks) and to alter their behavior if they accept
4
+ # any parameters. The file can be placed either in your home
5
+ # directory or in some project directory.
6
+ #
7
+ # RuboCop will start looking for the configuration file in the directory
8
+ # where the inspected file is and continue its way up to the root directory.
9
+ #
10
+ # See https://github.com/rubocop-hq/rubocop/blob/master/manual/configuration.md
11
+ # https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml
12
+ ---
13
+ require:
14
+ - rubocop-performance
15
+
16
+ Layout/LineLength:
17
+ Max: 120
18
+
19
+ Style/Documentation:
20
+ Enabled: false
21
+
22
+ Metrics/MethodLength:
23
+ Max: 15
24
+
25
+ Layout/DotPosition:
26
+ EnforcedStyle: trailing
27
+
28
+ Layout/MultilineMethodCallIndentation:
29
+ EnforcedStyle: indented
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.6
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in env_compare.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ env_compare (0.1.0)
5
+ launchy
6
+ thor
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
+ ast (2.4.1)
14
+ coderay (1.1.3)
15
+ diff-lcs (1.3)
16
+ launchy (2.5.0)
17
+ addressable (~> 2.7)
18
+ method_source (1.0.0)
19
+ parallel (1.19.1)
20
+ parser (2.7.1.3)
21
+ ast (~> 2.4.0)
22
+ pry (0.13.1)
23
+ coderay (~> 1.1)
24
+ method_source (~> 1.0)
25
+ public_suffix (4.0.5)
26
+ rainbow (3.0.0)
27
+ rake (12.3.3)
28
+ regexp_parser (1.7.1)
29
+ rexml (3.2.4)
30
+ rspec (3.9.0)
31
+ rspec-core (~> 3.9.0)
32
+ rspec-expectations (~> 3.9.0)
33
+ rspec-mocks (~> 3.9.0)
34
+ rspec-core (3.9.2)
35
+ rspec-support (~> 3.9.3)
36
+ rspec-expectations (3.9.2)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.9.0)
39
+ rspec-mocks (3.9.1)
40
+ diff-lcs (>= 1.2.0, < 2.0)
41
+ rspec-support (~> 3.9.0)
42
+ rspec-support (3.9.3)
43
+ rubocop (0.85.1)
44
+ parallel (~> 1.10)
45
+ parser (>= 2.7.0.1)
46
+ rainbow (>= 2.2.2, < 4.0)
47
+ regexp_parser (>= 1.7)
48
+ rexml
49
+ rubocop-ast (>= 0.0.3)
50
+ ruby-progressbar (~> 1.7)
51
+ unicode-display_width (>= 1.4.0, < 2.0)
52
+ rubocop-ast (0.0.3)
53
+ parser (>= 2.7.0.1)
54
+ rubocop-performance (1.6.1)
55
+ rubocop (>= 0.71.0)
56
+ ruby-progressbar (1.10.1)
57
+ thor (1.0.1)
58
+ unicode-display_width (1.7.0)
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ env_compare!
65
+ pry
66
+ rake (~> 12.0)
67
+ rspec (~> 3.0)
68
+ rubocop
69
+ rubocop-performance
70
+
71
+ BUNDLED WITH
72
+ 2.1.4
@@ -0,0 +1,65 @@
1
+ # EnvCompare
2
+
3
+ Compare Heroku ENV variables across environments in an HTML
4
+ table.
5
+
6
+ In a perfect world, you're using a platform or tool for managing your
7
+ environment variables across Heroku environments. However, you may
8
+ find the need to compare review app settings, staging, or even
9
+ production environment variables
10
+
11
+ This gem helps pull down the environment variables and give you
12
+ a little interface to view & compare them with (via a UI)
13
+
14
+ No server; it's all done via a CLI. It's really just a wrapper around
15
+ some commands around the [heroku cli](https://devcenter.heroku.com/articles/heroku-cli) that does some formatting and
16
+ munging of the output so you don't have to copy it all to Excel
17
+
18
+ This gem wraps the heroku CLI tool to generates a small temporary
19
+ HTML file & opens it using [launchy](https://github.com/copiousfreetime/launchy)
20
+
21
+ It automates a few things:
22
+ - Hides environment variables that match across all environments
23
+ - Puts them in alpha order
24
+
25
+ It's primarily intended to compare pre-production ENV variables
26
+
27
+ ## Installation
28
+
29
+ # Install heroku CLI
30
+ brew tap heroku/brew && brew install heroku
31
+
32
+ git clone https://github.com/jaydorsey/env_compare.git && cd env_compare
33
+ bundle
34
+ rake build
35
+ gem install pkg/env_compare-0.1.0.gem
36
+
37
+ After installation you should have access to the `ec` executable wrapper
38
+
39
+ > Note: There's no published gem yet. I'm not really sure how useful this is
40
+ > but you can install via above or use the development commands below if you
41
+ > don't want to build & install the gem locally
42
+
43
+ ## Usage
44
+
45
+ First, you need to login with heroku cli:
46
+
47
+ heroku login
48
+
49
+ Then, you can use the `ec` command
50
+
51
+ Create a file showing differences between 2 or more heroku applications:
52
+
53
+ ec diff heroku-app-name1 heroku-app-name2 heroku-app-name3
54
+
55
+ ## Development
56
+
57
+ To test this on your machine locally, after cloning the repo:
58
+
59
+ git clone https://github.com/jaydorsey/env_compare.git && cd env_compare
60
+ bundle
61
+ bundle exec ec diff heroku-app-name1 heroku-app-name2
62
+
63
+ ## Contributing
64
+
65
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jaydorsey/env_compare.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "env_compare"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/env_compare/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'env_compare'
7
+ spec.version = EnvCompare::VERSION
8
+ spec.authors = ['Jay Dorsey']
9
+ spec.email = ['jaydorsey@fastmail.com']
10
+
11
+ spec.summary = 'Compare ENV variables across Heroku environments'
12
+ spec.description = 'Compare ENV variables across Heroku environments'
13
+ spec.homepage = 'https://jaydorsey.com/'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
15
+
16
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = 'https://github.com/jaydorsey/env_compare'
20
+ spec.metadata['changelog_uri'] = 'https://github.com/jaydorsey/env_compare/CHANGELOG.md'
21
+
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_dependency 'launchy'
31
+ spec.add_dependency 'thor'
32
+
33
+ spec.add_development_dependency 'pry'
34
+ spec.add_development_dependency 'rspec'
35
+ spec.add_development_dependency 'rubocop'
36
+ spec.add_development_dependency 'rubocop-performance'
37
+ end
data/exe/ec ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "env_compare"
4
+
5
+ EnvCompare::CLI.start(ARGV)
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'env_compare/errors'
4
+ require 'env_compare/name_space'
5
+ require 'env_compare/version'
6
+ require 'erb'
7
+ require 'launchy'
8
+ require 'securerandom'
9
+ require 'thor'
10
+ require 'pry'
11
+
12
+ module EnvCompare
13
+ class CLI < Thor
14
+ attr_accessor :envs
15
+
16
+ desc 'version', 'list version'
17
+ def version
18
+ puts EnvCompare::VERSION
19
+ end
20
+
21
+ desc 'list ENVIRONMENT', 'List environment variables for a single environment'
22
+
23
+ def list(environment)
24
+ output = `heroku config -a #{environment}`
25
+ puts output
26
+ end
27
+
28
+ option :theme, type: :string, default: 'dark', desc: 'Theme to use'
29
+ option :all, type: :boolean, default: false, desc: 'Display all ENV variables, including matches'
30
+ desc 'diff ENV1 ENV2', 'Compare environment variables for 2+ environments'
31
+ def diff(*envs)
32
+ return list(envs.first) if envs.size == 1
33
+
34
+ heroku_results(envs)
35
+
36
+ # https://stackoverflow.com/a/5462069/2892779
37
+ html =
38
+ theme(options[:theme]).
39
+ result(
40
+ ::EnvCompare::NameSpace.new(data: calculated_output(envs), headers: ['KEY', envs].flatten).get_binding
41
+ )
42
+
43
+ save_and_open_file(html)
44
+ end
45
+
46
+ private
47
+
48
+ def all_keys
49
+ @all_keys ||= Set.new
50
+ end
51
+
52
+ def calculated_output(envs)
53
+ all_keys.sort.map do |key|
54
+ results = envs.map { |env| heroku_results[env][key] }
55
+ next if results.uniq.size == 1 && !options[:all]
56
+
57
+ [key, *results]
58
+ end.compact
59
+ end
60
+
61
+ def heroku_results(envs = nil)
62
+ @heroku_results ||=
63
+ envs.each_with_object({}) do |env, obj|
64
+ obj[env] = {}
65
+ lines = `heroku config -a #{env}`.split("\n").drop(1)
66
+
67
+ lines.each do |line|
68
+ key, _, value = line.partition(':')
69
+ obj[env][key.strip] = value.strip
70
+
71
+ all_keys << key.strip
72
+ end
73
+ end
74
+ end
75
+
76
+ def save_and_open_file(html)
77
+ filename = "#{SecureRandom.hex(32)}.html"
78
+ output = File.open(filename, 'w')
79
+ output.write(html)
80
+ output.close
81
+
82
+ full_path = File.join(Dir.pwd, output.path)
83
+
84
+ Launchy.open(full_path)
85
+
86
+ sleep(1)
87
+
88
+ File.delete(full_path)
89
+ end
90
+
91
+ def theme(file)
92
+ return ERB.new(File.read(theme_path(file))) if File.exist?(theme_path(file))
93
+
94
+ raise MissingThemeError
95
+ end
96
+
97
+ def theme_path(file)
98
+ @theme_path ||= File.join(File.dirname(__dir__), 'themes', "#{file}.erb")
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EnvCompare
4
+ class MissingThemeError < StandardError
5
+ def message
6
+ <<~MSG
7
+
8
+
9
+ Theme not found. Use one of:
10
+
11
+ --theme light
12
+ --theme dark
13
+ MSG
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EnvCompare
4
+ class NameSpace
5
+ def initialize(hash)
6
+ hash.each do |key, value|
7
+ singleton_class.send(:define_method, key) { value }
8
+ end
9
+ end
10
+
11
+ def get_binding
12
+ binding
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EnvCompare
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,57 @@
1
+ <html>
2
+ <head>
3
+ <style>
4
+ body {
5
+ background: #000;
6
+ font-family: Arial, Helvetica, sans-serif;
7
+ }
8
+ table {
9
+ color: #da8fff;
10
+ table-layout: fixed;
11
+ width: 100%;
12
+ }
13
+
14
+ table, th, td {
15
+ border: 1px solid #636366;
16
+ border-collapse: collapse;
17
+ }
18
+
19
+ th {
20
+ color: #ffb340;
21
+ letter-spacing: 1px;
22
+ }
23
+
24
+ td {
25
+ padding: 10px;
26
+ word-wrap: break-word;
27
+ }
28
+
29
+ td:first-child {
30
+ color: #409cff;
31
+ }
32
+ </style>
33
+ </head>
34
+ <body>
35
+ <table>
36
+ <tr>
37
+ <% headers.each_with_index do |header, idx| %>
38
+ <th>
39
+ <%= header %>&nbsp;
40
+ (<%= data.map { |col| col[idx] }.compact.size - 1 %> keys)
41
+ </th>
42
+ <% end %>
43
+ </tr>
44
+ <% data.each do |row| %>
45
+ <tr>
46
+ <% row.each do |cell| %>
47
+ <td>
48
+ <% unless cell.nil? %>
49
+ <code><%= cell %></code>
50
+ <% end %>
51
+ </td>
52
+ <% end %>
53
+ </tr>
54
+ <% end %>
55
+ </table>
56
+ </body>
57
+ </html>
@@ -0,0 +1,57 @@
1
+ <html>
2
+ <head>
3
+ <style>
4
+ body {
5
+ background: #fff;
6
+ font-family: Arial, Helvetica, sans-serif;
7
+ }
8
+ table {
9
+ color: #000;
10
+ table-layout: fixed;
11
+ width: 100%;
12
+ }
13
+
14
+ table, th, td {
15
+ border: 1px solid #636366;
16
+ border-collapse: collapse;
17
+ }
18
+
19
+ th {
20
+ color: #000;
21
+ letter-spacing: 1px;
22
+ }
23
+
24
+ td {
25
+ padding: 10px;
26
+ word-wrap: break-word;
27
+ }
28
+
29
+ td:first-child {
30
+ color: #409cff;
31
+ }
32
+ </style>
33
+ </head>
34
+ <body>
35
+ <table>
36
+ <tr>
37
+ <% headers.each_with_index do |header, idx| %>
38
+ <th>
39
+ <%= header %>&nbsp;
40
+ (<%= data.map { |col| col[idx] }.compact.size - 1 %> keys)
41
+ </th>
42
+ <% end %>
43
+ </tr>
44
+ <% data.each do |row| %>
45
+ <tr>
46
+ <% row.each do |cell| %>
47
+ <td>
48
+ <% unless cell.nil? %>
49
+ <code><%= cell %></code>
50
+ <% end %>
51
+ </td>
52
+ <% end %>
53
+ </tr>
54
+ <% end %>
55
+ </table>
56
+ </body>
57
+ </html>
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: env_compare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jay Dorsey
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: launchy
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-performance
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Compare ENV variables across Heroku environments
98
+ email:
99
+ - jaydorsey@fastmail.com
100
+ executables:
101
+ - ec
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/setup
115
+ - env_compare.gemspec
116
+ - exe/ec
117
+ - lib/env_compare.rb
118
+ - lib/env_compare/errors.rb
119
+ - lib/env_compare/name_space.rb
120
+ - lib/env_compare/version.rb
121
+ - themes/dark.erb
122
+ - themes/light.erb
123
+ homepage: https://jaydorsey.com/
124
+ licenses: []
125
+ metadata:
126
+ allowed_push_host: https://rubygems.org
127
+ homepage_uri: https://jaydorsey.com/
128
+ source_code_uri: https://github.com/jaydorsey/env_compare
129
+ changelog_uri: https://github.com/jaydorsey/env_compare/CHANGELOG.md
130
+ post_install_message:
131
+ rdoc_options: []
132
+ require_paths:
133
+ - lib
134
+ required_ruby_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 2.3.0
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ requirements: []
145
+ rubygems_version: 3.0.3
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: Compare ENV variables across Heroku environments
149
+ test_files: []