akido_pubsub 3.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 71d204cd58c81f0b59a1c443f61dee82da3138199f847b465a3a3984bc4b8ec7
4
+ data.tar.gz: d36f1b80175f1c5b592f38c682da8ce44225d2cf67d3115c1cce7e8c00a08b36
5
+ SHA512:
6
+ metadata.gz: f94640c8834c42ee8f78e188ecda429c7433780811bbfdb272f0b93c2a6b0d149c2c7ede160d722d15a4c22b8023e65ad8c0a57b02370e0843b1ea8b69b8e323
7
+ data.tar.gz: 12f5ae01d09d9637deb82163645050bf0f3fff3096a1756d3c1472ede279d3d7ca1096c0e3bcbaf3ba686109d6f1980833a9da485f55579eafcd3b9f3f3b9fa4
@@ -0,0 +1,45 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ build:
11
+ name: Build + Publish
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ contents: read
15
+ packages: write
16
+
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Set up Ruby 2.6
20
+ uses: actions/setup-ruby@v1
21
+ with:
22
+ ruby-version: 2.6.x
23
+
24
+ - name: Publish to GPR
25
+ run: |
26
+ mkdir -p $HOME/.gem
27
+ touch $HOME/.gem/credentials
28
+ chmod 0600 $HOME/.gem/credentials
29
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
30
+ gem build *.gemspec
31
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
32
+ env:
33
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
34
+ OWNER: ${{ github.repository_owner }}
35
+
36
+ - name: Publish to RubyGems
37
+ run: |
38
+ mkdir -p $HOME/.gem
39
+ touch $HOME/.gem/credentials
40
+ chmod 0600 $HOME/.gem/credentials
41
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
42
+ gem build *.gemspec
43
+ gem push *.gem
44
+ env:
45
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
data/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
1
+ # Changelog
2
+
3
+ ## [2.0.0] - 2018-06-18
4
+ ### Changed
5
+ - AkidoPubsub no longer needs any methods from its host class.
6
+ - Added compatibility with (and dependence on) a configuration initializer.
7
+ - Added this changelog.
8
+
9
+ ## [1.0.0] - 2018-06-18
10
+ ### Changed
11
+ - Changed AkidoPubsub from a singleton to a mix-in.
12
+ - AkidoPubsub now depends on its host class to expose the methods `logger`,
13
+ `platform_audit`, `server_url`, and `self_url`.
14
+
15
+ ## [0.1.3] - 2018-06-09
16
+ ### Added
17
+ - Copied/pasted Fastpass Queue Manager's Pubsub util methods, including:
18
+ - getAuditEventChannel
19
+ - getSubscriptions
20
+ - createAuditEventSubscription
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in akido_pubsub.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ akido_pubsub (3.0.0)
5
+ rest-client
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ bump (0.6.1)
11
+ diff-lcs (1.3)
12
+ domain_name (0.5.20180417)
13
+ unf (>= 0.0.5, < 1.0.0)
14
+ http-cookie (1.0.3)
15
+ domain_name (~> 0.5)
16
+ mime-types (3.1)
17
+ mime-types-data (~> 3.2015)
18
+ mime-types-data (3.2016.0521)
19
+ netrc (0.11.0)
20
+ rake (10.5.0)
21
+ rest-client (2.0.2)
22
+ http-cookie (>= 1.0.2, < 2.0)
23
+ mime-types (>= 1.16, < 4.0)
24
+ netrc (~> 0.8)
25
+ rspec (3.7.0)
26
+ rspec-core (~> 3.7.0)
27
+ rspec-expectations (~> 3.7.0)
28
+ rspec-mocks (~> 3.7.0)
29
+ rspec-core (3.7.1)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-expectations (3.7.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.7.0)
34
+ rspec-mocks (3.7.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.7.0)
37
+ rspec-support (3.7.1)
38
+ unf (0.1.4)
39
+ unf_ext
40
+ unf_ext (0.0.7.5)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ akido_pubsub!
47
+ bump
48
+ bundler (~> 1.16)
49
+ rake (~> 10.0)
50
+ rspec (~> 3.0)
51
+
52
+ BUNDLED WITH
53
+ 1.16.2
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # AkidoPubsub
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/akido_pubsub`. 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 'akido_pubsub'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install akido_pubsub
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/[USERNAME]/akido_pubsub.
data/Rakefile ADDED
@@ -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,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "akido_pubsub/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "akido_pubsub"
8
+ spec.version = AkidoPubsub::VERSION
9
+ spec.authors = ["Dean Tambling"]
10
+ spec.email = ["dean.tambling@gmail.com"]
11
+
12
+ spec.summary = "A gem to encapuslate the creation of pubsub subscriptions"
13
+ spec.description = "Allows for the reading and creation of pubsub channels/subscriptions"
14
+ spec.homepage = "https://github.com/akidolabs/akido_pubsub"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "bump"
29
+ spec.add_dependency "rest-client"
30
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "akido_pubsub"
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__)
data/bin/setup ADDED
@@ -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,102 @@
1
+ require "akido_pubsub/version"
2
+
3
+ module AkidoPubsub
4
+ class << self
5
+ attr_accessor :config
6
+
7
+ def configure
8
+ self.config ||= Configuration.new
9
+ yield(self.config)
10
+ end
11
+ end
12
+
13
+ class Configuration
14
+ attr_accessor :logger, :server_url, :self_url
15
+
16
+ def initialize
17
+ @logger = ::Logger.new(STDOUT)
18
+ @server_url = nil
19
+ @self_url = nil
20
+ end
21
+
22
+ def verify_config *properties
23
+ properties.each do |property|
24
+ if !instance_variable_get("@#{property}")
25
+ raise ConfigError.new("#{property.to_s} needs to be set on AkidoPubsub")
26
+ end
27
+ end
28
+ end
29
+
30
+ class ConfigError < StandardError
31
+ end
32
+ end
33
+
34
+ def get_channel tags
35
+ # fetch list of pubsub channels and find channel for audit events
36
+ path= "pubsub/channel?#{tags.map{ |tag| "tags=#{tag}" }.join('&')}"
37
+
38
+ channels = get_from_server(path: path, error_text: 'Error getting channel')
39
+
40
+ matching_channel = channels.find do |channel|
41
+ (tags - channel["tags"]).empty?
42
+ end
43
+
44
+ matching_channel && matching_channel['uid']
45
+ end
46
+
47
+ def get_subscriptions channel, endpoint
48
+ subscriptions = get_from_server(path: 'pubsub/subscription', error_text: 'Error getting subscriptions')
49
+
50
+ matching_subscription = subscriptions.find do |subscription|
51
+ subscription['channel'] == channel && subscription['endpoints'].include?(endpoint)
52
+ end
53
+
54
+ if matching_subscription
55
+ AkidoPubsub.config.logger.info("Found existing subscription to channel #{channel}")
56
+ return matching_subscription["uid"]
57
+ else
58
+ return nil
59
+ end
60
+ end
61
+
62
+ def create_subscription channel, endpoint
63
+ AkidoPubsub.config.verify_config(:self_url)
64
+
65
+ sub_endpoint = "#{AkidoPubsub.config.self_url}/#{endpoint}"
66
+ existing_subscription = get_subscriptions(channel, sub_endpoint)
67
+
68
+ return existing_subscription if existing_subscription
69
+
70
+ url = "#{AkidoPubsub.config.server_url}/pubsub/subscription"
71
+ body = {
72
+ :channel => channel,
73
+ :endpoints => [
74
+ sub_endpoint
75
+ ],
76
+ :notify => true
77
+ }.to_json
78
+
79
+ response = RestClient.post url, body, { :accept => :json }
80
+
81
+ extract_id_from_url(response.body, 'subscription') if response.code == 200
82
+ end
83
+
84
+ def extract_id_from_url url, resource
85
+ return (match = url.match(/resource\/(\d+)/)) && match.last
86
+ end
87
+
88
+ def get_from_server path:, error_text: "There was an error"
89
+ AkidoPubsub.config.verify_config(:server_url)
90
+
91
+ url = "#{AkidoPubsub.config.server_url}/#{path}"
92
+
93
+ begin
94
+ response = RestClient.get url, { :accept => :json }
95
+ rescue RestClient::ExceptionWithResponse => e
96
+ AkidoPubsub.config.logger.error("#{error_text}: #{e.response}")
97
+ return
98
+ end
99
+
100
+ return JSON.parse(response.body)
101
+ end
102
+ end
@@ -0,0 +1,3 @@
1
+ module AkidoPubsub
2
+ VERSION = "3.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: akido_pubsub
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dean Tambling
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-05-19 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bump
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: rest-client
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Allows for the reading and creation of pubsub channels/subscriptions
84
+ email:
85
+ - dean.tambling@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".github/workflows/gem-push.yml"
91
+ - CHANGELOG.md
92
+ - Gemfile
93
+ - Gemfile.lock
94
+ - README.md
95
+ - Rakefile
96
+ - akido_pubsub.gemspec
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/akido_pubsub.rb
100
+ - lib/akido_pubsub/version.rb
101
+ homepage: https://github.com/akidolabs/akido_pubsub
102
+ licenses: []
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubygems_version: 3.0.3.1
120
+ signing_key:
121
+ specification_version: 4
122
+ summary: A gem to encapuslate the creation of pubsub subscriptions
123
+ test_files: []