-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: ruby client #89
Open
davalpargal
wants to merge
7
commits into
raystack:main
Choose a base branch
from
davalpargal:feat/ruby-client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e38335b
feat/ruby-client: initialize ruby client
davalpargal 384da70
Add configuration for stencil
davalpargal 8d4c54c
Add client for stencil to get file set descriptor
davalpargal dbd1aa0
Add store for saving current proto descriptor file set
davalpargal e6c6811
Add workflow for ruby client testing
davalpargal b757527
Update README.md
davalpargal 4dd7e95
Fix repository setup
davalpargal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Test stencil RUBY client | ||
on: | ||
push: | ||
paths: | ||
- "clients/ruby/**" | ||
branches: | ||
- master | ||
pull_request: | ||
paths: | ||
- "clients/ruby/**" | ||
branches: | ||
- master | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-ruby@v1 | ||
with: | ||
ruby-version: '2.5' | ||
- run: cd clients/ruby; bin/setup; rspec -fd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.mine | ||
*.gem | ||
.config | ||
.rvmrc | ||
.yardoc | ||
InstalledFiles | ||
_yardoc | ||
|
||
.bundle | ||
.ruby-version | ||
doc | ||
coverage | ||
pkg | ||
spec/examples.txt | ||
tmp | ||
Gemfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--backtrace | ||
--color | ||
--format=documentation | ||
--order random | ||
--require spec_helper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
source "https://rubygems.org" | ||
|
||
# Specify your gem's dependencies in stencil.gemspec | ||
gemspec | ||
|
||
gem "rake", "~> 13.0" | ||
gem "http", "4.4.1" | ||
gem 'concurrent-ruby', require: 'concurrent' | ||
gem 'protobuf' | ||
|
||
group :test do | ||
gem "simplecov", ">= 0.9" | ||
gem "rspec", "~> 3.0" | ||
gem "rubocop", "~> 1.7" | ||
gem "pry" | ||
gem "google-protobuf" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Stencil | ||
|
||
Stencil ruby gem provides a store to lookup protobuf descriptors and options to keep the protobuf descriptors upto date. | ||
|
||
## Installation | ||
|
||
```ruby | ||
gem 'stencil' | ||
``` | ||
|
||
And then execute: | ||
|
||
$ bundle install | ||
|
||
Or install it yourself as: | ||
|
||
$ gem install stencil | ||
|
||
## Usage | ||
|
||
|
||
## Development | ||
|
||
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment. | ||
|
||
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require "bundler/gem_tasks" | ||
require "rubocop/rake_task" | ||
|
||
RuboCop::RakeTask.new | ||
|
||
task default: :rubocop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require "bundler/setup" | ||
require "stencil" | ||
|
||
# You can add fixtures and/or initialization code here to make experimenting | ||
# with your gem easier. You can also use a different console, if you like. | ||
|
||
# (If you use this, don't forget to add pry to your Gemfile!) | ||
# require "pry" | ||
# Pry.start | ||
|
||
require "irb" | ||
IRB.start(__FILE__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
set -vx | ||
|
||
gem install bundler:1.17.3 | ||
bundle install | ||
|
||
# Do any other automated setup that you need to do here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require_relative "stencil/version" | ||
require_relative "stencil/configuration" | ||
require_relative "stencil/constants" | ||
require_relative "stencil/client" | ||
require_relative "stencil/store" | ||
|
||
require "http" | ||
require "concurrent/timer_task" | ||
require "concurrent/mutable_struct" | ||
require "protobuf" | ||
|
||
module Stencil | ||
class Error < StandardError; end | ||
class InvalidConfiguration < Error; end | ||
class InvalidProtoClass < Error; end | ||
class HTTPClientError < Error; end | ||
class HTTPServerError < Error; end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
module Stencil | ||
class Client | ||
attr_reader :root | ||
def initialize | ||
begin | ||
@config = Stencil.configuration | ||
validate_configuration(@config) | ||
|
||
setup_http_client | ||
|
||
@store = Store.new | ||
load_descriptors | ||
setup_store_update_job | ||
end | ||
end | ||
|
||
def get_type(proto_name) | ||
file_descriptor_set = @store.read(@config.registry_url) | ||
file_descriptor_set.file.each do |file_desc| | ||
file_desc.message_type.each do |message| | ||
if proto_name == "#{file_desc.options.java_package}.#{message.name}" | ||
return message | ||
end | ||
end | ||
end | ||
raise InvalidProtoClass.new | ||
end | ||
|
||
def close | ||
@task.shutdown | ||
end | ||
|
||
private | ||
|
||
def validate_configuration(configuration) | ||
raise Stencil::InvalidConfiguration.new() if configuration.registry_url.nil? || configuration.bearer_token.nil? || configuration.bearer_token == "Bearer " | ||
end | ||
|
||
def setup_http_client | ||
@http_client = HTTP.auth(@config.bearer_token).timeout(@config.http_timeout) | ||
end | ||
|
||
def load_descriptors | ||
begin | ||
response = @http_client.get(@config.registry_url) | ||
if response.code != 200 | ||
raise HTTPServerError.new("Error while fetching descriptor file: Got #{response.code} from stencil server") | ||
end | ||
rescue StandardError => e | ||
raise HTTPClientError.new(e.message) | ||
end | ||
|
||
file_descriptor_set = Google::Protobuf::FileDescriptorSet.decode(response.body) | ||
@store.write(@config.registry_url, file_descriptor_set) | ||
end | ||
|
||
def setup_store_update_job | ||
begin | ||
@task = Concurrent::TimerTask.new(execution_interval: @config.refresh_ttl_in_secs) do | ||
load_descriptors | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module Stencil | ||
class Configuration | ||
def initialize | ||
@config = ::OpenStruct.new | ||
end | ||
|
||
def registry_url | ||
@config.registry_url | ||
end | ||
|
||
def registry_url=(registry_url) | ||
@config.registry_url = registry_url | ||
end | ||
|
||
def http_timeout | ||
@config.http_timeout || DEFAULT_TIMEOUT_IN_MS | ||
end | ||
|
||
def http_timeout=(timeout) | ||
@config.http_timeout = timeout | ||
end | ||
|
||
def refresh_enabled | ||
@config.refresh_enabled.nil? ? true : @config.refresh_enabled | ||
end | ||
|
||
def refresh_enabled=(refresh_enabled = true) | ||
@config.refresh_enabled = refresh_enabled | ||
end | ||
|
||
def refresh_ttl_in_secs | ||
@config.refresh_ttl_in_secs || DEFAULT_REFRESH_INTERVAL_IN_SECONDS | ||
end | ||
|
||
def refresh_ttl_in_secs=(refresh_ttl_in_secs) | ||
@config.refresh_ttl_in_secs = refresh_ttl_in_secs | ||
end | ||
|
||
def bearer_token=(token) | ||
@config.bearer_token = "Bearer " + token | ||
end | ||
|
||
def bearer_token | ||
@config.bearer_token | ||
end | ||
end | ||
|
||
def self.configuration | ||
@config ||= Configuration.new | ||
end | ||
|
||
def self.configure | ||
yield(configuration) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Stencil | ||
DEFAULT_TIMEOUT_IN_MS = 10000 | ||
DEFAULT_REFRESH_INTERVAL_IN_SECONDS = 43200 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Stencil | ||
class Store | ||
def initialize | ||
@lock = Concurrent::ReadWriteLock.new | ||
@data = Hash.new | ||
end | ||
|
||
def write(key, value) | ||
@lock.with_write_lock do | ||
@data.store(key, value) | ||
end | ||
end | ||
|
||
def read(key) | ||
@data[key] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
module Stencil | ||
VERSION = "0.1.0" | ||
end |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'simplecov' | ||
|
||
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new( | ||
[ | ||
SimpleCov::Formatter::HTMLFormatter, | ||
] | ||
) | ||
|
||
SimpleCov.start do | ||
add_filter "/spec/" | ||
minimum_coverage 80 | ||
end | ||
|
||
require 'bundler/setup' | ||
Bundler.setup | ||
|
||
require 'pry' | ||
require 'stencil' | ||
require 'webmock/rspec' | ||
|
||
RSpec.configure do |config| | ||
config.filter_run_when_matching focus: true | ||
config.disable_monkey_patching! | ||
config.profile_examples = 10 | ||
config.order = :random | ||
end | ||
|
||
WebMock.disable_net_connect!(allow_localhost: true) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@davalpargal Typo here. Secret name is
RUBYGEMS_TOKEN