gcp-api-discovery-watcher 0.0.1

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: 6f953580ca5f3c5317ef5fb843b57af46c2c360e4f43dc691c5198b77d6c01b7
4
+ data.tar.gz: 469e87fe8533d4561ccaa7b12907fec7d6ee12b5af676cb7912b6f91f3b7a3b7
5
+ SHA512:
6
+ metadata.gz: ea08f9441832bf376064ec5dbed5cebb51122fbd6e974f3324b07cd63d7186f6aa6f5f9f1c37fd9d298d5ea5153ae42d1ea45cc1a1406add2403ad5a03423a42
7
+ data.tar.gz: 37249cdc040ac6da277dcdf56ced97b0b752c59c9941a16324aac02b56d31f50adbabf9b23b58adbab05e64307864ede38c2a8d332fee3328fa5f662f733ab53
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/bundle/
10
+ /cache/
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.4
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gcp-api-discovery-watcher.gemspec
4
+ gemspec
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gcp-api-discovery-watcher (0.0.1)
5
+ diffy
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ diffy (3.3.0)
12
+ rake (13.0.0)
13
+ rspec (3.8.0)
14
+ rspec-core (~> 3.8.0)
15
+ rspec-expectations (~> 3.8.0)
16
+ rspec-mocks (~> 3.8.0)
17
+ rspec-core (3.8.2)
18
+ rspec-support (~> 3.8.0)
19
+ rspec-expectations (3.8.5)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.8.0)
22
+ rspec-mocks (3.8.2)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.8.0)
25
+ rspec-support (3.8.3)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler
32
+ gcp-api-discovery-watcher!
33
+ rake
34
+ rspec
35
+
36
+ BUNDLED WITH
37
+ 2.0.2
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 Tomoyuki Chikanaga.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,35 @@
1
+ # Gcp::Api::Discovery::Watcher
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gcp/api/discovery/watcher`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'gcp-api-discovery-watcher'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gcp-api-discovery-watcher
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nagachika/gcp-api-discovery-watcher.
@@ -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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gcp/api/discovery/watcher"
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
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -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,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "gcp/api/discovery/watcher"
4
+
5
+ app = Gcp::Api::Discovery::Watcher.new
6
+
7
+ app.run(ARGV)
@@ -0,0 +1,28 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "gcp-api-discovery-watcher"
3
+ spec.version = "0.0.1"
4
+ spec.authors = ["nagachika"]
5
+ spec.email = ["nagachika@ruby-lang.org"]
6
+
7
+ spec.summary = %q{I AM ALL SEEING EYES}
8
+ spec.description = %q{I AM ALL SEEING EYES}
9
+ spec.homepage = "https://github.com/nagachika/gcp-api-discovery-watcher"
10
+
11
+ spec.metadata["homepage_uri"] = spec.homepage
12
+ spec.metadata["source_code_uri"] = spec.homepage
13
+
14
+ # Specify which files should be added to the gem when it is released.
15
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "diffy"
24
+
25
+ spec.add_development_dependency "bundler"
26
+ spec.add_development_dependency "rake"
27
+ spec.add_development_dependency "rspec"
28
+ end
@@ -0,0 +1,106 @@
1
+ require "optparse"
2
+ require "fileutils"
3
+ require "open-uri"
4
+ require "yaml"
5
+
6
+ require_relative "watcher/api_metadata"
7
+ require_relative "watcher/diff_hash"
8
+
9
+ module Gcp
10
+ module Api
11
+ module Discovery
12
+ class Watcher
13
+ class Error < StandardError; end
14
+
15
+ def fetch_discover_api(api_name, version)
16
+ url = "https://www.googleapis.com/discovery/v1/apis/#{api_name}/#{version}/rest"
17
+ json = URI.open(url){|io| io.read }
18
+ ApiMetadata.new(api_name, version, json)
19
+ end
20
+
21
+ def load_file(api_name, version, filepath)
22
+ ApiMetadata.new(api_name, version, File.read(filepath))
23
+ end
24
+
25
+ def save_file(filepath, api_metadata)
26
+ FileUtils.mkdir_p(File.dirname(filepath))
27
+ File.write(filepath, YAML.dump(api_metadata.to_hash))
28
+ end
29
+
30
+ def parse_options(argv, conf)
31
+ OptionParser.new{|opt|
32
+ opt.on("--api API_NAME", "GCP API Name (ex. ml, bigquery ...)") do |api|
33
+ conf[:api] = api
34
+ end
35
+ opt.on("--api_version API_VERSION", "API version (ex. v1, v1beta1)") do |v|
36
+ conf[:version] = v
37
+ end
38
+ opt.on("--storage DIR") do |dir|
39
+ conf[:dir] = dir
40
+ end
41
+ opt.on("--output FILE") do |file|
42
+ conf[:output_file] = file
43
+ end
44
+ opt.parse!
45
+ }
46
+ conf
47
+ end
48
+
49
+ def current_filename(dir, api, version)
50
+ basedir = File.join(dir, api, version)
51
+ File.join(basedir, "#{api}_#{version}.yaml")
52
+ end
53
+
54
+ def metadata_filename(dir, metadata)
55
+ File.join(dir, metadata.api, metadata.version, "#{metadata.api}_#{metadata.version}_#{metadata.revision}.yaml")
56
+ end
57
+
58
+ def run(argv)
59
+ conf = {
60
+ dir: "./cache"
61
+ }
62
+ conf = parse_options(argv, conf)
63
+
64
+ current_path = current_filename(conf[:dir], conf[:api], conf[:version])
65
+ previous = nil
66
+ if File.readable?(current_path)
67
+ previous = load_file(conf[:api], conf[:version], current_path)
68
+ end
69
+
70
+ new_metadata = fetch_discover_api(conf[:api], conf[:version])
71
+
72
+ write_current = false
73
+ write_new_metadata = true
74
+ if previous
75
+ if previous.revision == new_metadata.revision
76
+ puts "API #{conf[:api]}_#{conf[:version]}: No Change (revision #{new_metadata.revision})"
77
+ write_new_metadata = false
78
+ else
79
+ if previous.revision < new_metadata.revision
80
+ write_current = true
81
+ end
82
+ puts "API #{conf[:api]}_#{conf[:version]}: revision #{previous.revision} -> #{new_metadata.revision}"
83
+ if conf[:output_file].nil? or conf[:output_file] == "-"
84
+ DiffHash.diff_hash(previous, new_metadata, $stdout)
85
+ else
86
+ open(conf[:output_file], "wb") do |f|
87
+ DiffHash.diff_hash(previous, new_metadata, f)
88
+ end
89
+ end
90
+ end
91
+ else
92
+ puts "New API #{conf[:api]}_#{conf[:version]}"
93
+ write_current = true
94
+ end
95
+
96
+ if write_current
97
+ save_file(current_path, new_metadata)
98
+ end
99
+ if write_new_metadata
100
+ save_file(metadata_filename(conf[:dir], new_metadata), new_metadata)
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,34 @@
1
+ # frozen-string-literal: true
2
+
3
+ require "yaml"
4
+
5
+ module Gcp
6
+ module Api
7
+ module Discovery
8
+ class Watcher
9
+ class ApiMetadata
10
+ def initialize(api, version, obj_or_yaml_string)
11
+ case obj_or_yaml_string
12
+ when String
13
+ obj = YAML.safe_load(obj_or_yaml_string)
14
+ when Hash
15
+ obj = obj_or_yaml_string
16
+ else
17
+ raise ArgumentError, "ApiMetadata.new accept String or Hash"
18
+ end
19
+ @api = api
20
+ @version = version
21
+ @obj = obj.sort.each_with_object({}){|(k, v), t| t[k] = v }
22
+ @revision = obj["revision"]
23
+ end
24
+
25
+ attr_reader :api, :version, :obj, :revision
26
+
27
+ def to_hash
28
+ self.obj
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "diffy"
4
+ require "json"
5
+ require "tmpdir"
6
+ require "pp"
7
+ require "optparse"
8
+
9
+ module Gcp
10
+ module Api
11
+ module Discovery
12
+ class Watcher
13
+ module DiffHash
14
+ module_function
15
+
16
+ def diff_hash(a, b, port=$stdout, current_keys=[])
17
+ a = a.to_hash
18
+ b = b.to_hash
19
+ a_keys = a.keys.sort
20
+ b_keys = b.keys.sort
21
+ (a_keys - b_keys).each do |k|
22
+ port << "\n--- '#{(current_keys+[k]).join(".")}':"
23
+ port << a[k].pretty_inspect
24
+ end
25
+ (b_keys - a_keys).each do |k|
26
+ port << "\n+++ '#{(current_keys+[k]).join(".")}':"
27
+ port << b[k].pretty_inspect
28
+ end
29
+ (a_keys & b_keys).each do |k|
30
+ unless a[k] == b[k]
31
+ if a[k].is_a?(Hash) and b[k].is_a?(Hash)
32
+ diff_hash(a[k], b[k], port, current_keys + [k])
33
+ else
34
+ port << "\n'#{(current_keys+[k]).join(".")}' is changed:\n"
35
+ if a[k].is_a?(String) and b[k].is_a?(String)
36
+ port << Diffy::Diff.new(a[k], b[k]).to_s
37
+ else
38
+ port << "--- #{a[k].to_json}\n"
39
+ port << "+++ #{b[k].to_json}\n"
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gcp-api-discovery-watcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - nagachika
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: diffy
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: rake
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
+ description: I AM ALL SEEING EYES
70
+ email:
71
+ - nagachika@ruby-lang.org
72
+ executables:
73
+ - gcp-api-discovery-watcher
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - exe/gcp-api-discovery-watcher
88
+ - gcp-api-discovery-watcher.gemspec
89
+ - lib/gcp/api/discovery/watcher.rb
90
+ - lib/gcp/api/discovery/watcher/api_metadata.rb
91
+ - lib/gcp/api/discovery/watcher/diff_hash.rb
92
+ homepage: https://github.com/nagachika/gcp-api-discovery-watcher
93
+ licenses: []
94
+ metadata:
95
+ homepage_uri: https://github.com/nagachika/gcp-api-discovery-watcher
96
+ source_code_uri: https://github.com/nagachika/gcp-api-discovery-watcher
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubygems_version: 3.0.3
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: I AM ALL SEEING EYES
116
+ test_files: []