Skip to content

Commit

Permalink
chore: Clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmechlark committed Sep 10, 2023
1 parent 0e38bc3 commit ab375ca
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @carabao-capital/auth-engineer
* @itsmechlark
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem "ruby-lsp", require: false

gemspec
133 changes: 82 additions & 51 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,107 +9,137 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activesupport (7.0.2.3)
activesupport (7.0.8)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
base64 (0.1.1)
byebug (11.1.3)
code-scanning-rubocop (0.6.1)
rubocop (~> 1.0)
coderay (1.1.3)
concurrent-ruby (1.1.9)
concurrent-ruby (1.2.2)
crack (0.4.5)
rexml
diff-lcs (1.5.0)
docile (1.4.0)
dry-configurable (0.14.0)
concurrent-ruby (~> 1.0)
dry-configurable (0.16.1)
dry-core (~> 0.6)
dry-core (0.7.1)
zeitwerk (~> 2.6)
dry-core (0.9.1)
concurrent-ruby (~> 1.0)
faker (2.20.0)
zeitwerk (~> 2.6)
faker (2.23.0)
i18n (>= 1.8.11, < 2)
faraday (2.2.0)
faraday-net_http (~> 2.0)
faraday (2.7.10)
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (2.0.1)
faraday-net_http (3.0.2)
hashdiff (1.0.1)
i18n (1.10.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.6.3)
jwt (2.3.0)
language_server-protocol (3.17.0.3)
method_source (1.0.0)
minitest (5.15.0)
minitest (5.20.0)
multipart-parser (0.1.1)
parallel (1.21.0)
parser (3.1.1.0)
parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1)
pry (0.13.1)
racc
prettier_print (1.2.1)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.9.0)
pry-byebug (3.10.1)
byebug (~> 11.0)
pry (~> 0.13.0)
public_suffix (4.0.6)
pry (>= 0.13, < 0.15)
public_suffix (5.0.3)
racc (1.7.1)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.2.1)
rexml (3.2.5)
rspec (3.11.0)
rspec-core (~> 3.11.0)
rspec-expectations (~> 3.11.0)
rspec-mocks (~> 3.11.0)
rspec-core (3.11.0)
rspec-support (~> 3.11.0)
rspec-expectations (3.11.0)
regexp_parser (2.8.1)
rexml (3.2.6)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-mocks (3.11.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.11.0)
rspec-support (3.11.0)
rubocop (1.26.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
rubocop (1.56.2)
base64 (~> 0.1.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.1.0.0)
parser (>= 3.2.2.3)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.16.0, < 2.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.16.0)
parser (>= 3.1.1.0)
rubocop-performance (1.13.3)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.18.0)
rubocop (~> 1.41)
rubocop-factory_bot (2.23.1)
rubocop (~> 1.33)
rubocop-performance (1.19.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rake (0.6.0)
rubocop (~> 1.0)
rubocop-rspec (2.9.0)
rubocop (~> 1.19)
rubocop-shopify (2.4.0)
rubocop (~> 1.24)
ruby-progressbar (1.11.0)
rubocop-rspec (2.24.0)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
rubocop-shopify (2.14.0)
rubocop (~> 1.51)
ruby-lsp (0.9.4)
language_server-protocol (~> 3.17.0)
sorbet-runtime
syntax_tree (>= 6.1.1, < 7)
yarp (>= 0.9, < 0.11)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
simplecov (0.19.1)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov-html (0.12.3)
timecop (0.9.5)
tzinfo (2.0.4)
sorbet-runtime (0.5.11011)
syntax_tree (6.1.1)
prettier_print (>= 1.2.0)
timecop (0.9.8)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.1.0)
vcr (6.1.0)
webmock (3.14.0)
unicode-display_width (2.4.2)
vcr (6.2.0)
webmock (3.19.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
yarp (0.10.0)
zeitwerk (2.6.11)

PLATFORMS
aarch64-linux
x86_64-linux

DEPENDENCIES
bundler (~> 2.0)
code-scanning-rubocop
faker (~> 2.0)
faraday (~> 2.0)
http-auth0!
Expand All @@ -120,7 +150,8 @@ DEPENDENCIES
rubocop-performance
rubocop-rake
rubocop-rspec
rubocop-shopify (~> 2.4.0)
rubocop-shopify (~> 2.14)
ruby-lsp
simplecov (~> 0.19.0)
timecop (~> 0.9.4)
vcr (~> 6.0)
Expand Down
1 change: 1 addition & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
The MIT License (MIT)

Copyright (c) 2023 John Chlark Sumatra
Copyright (c) 2022 First Circle Growth Finance Corp.

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# http-auth0

[![CI](https://github.com/carabao-capital/http-auth0/actions/workflows/release.yml/badge.svg)](https://github.com/carabao-capital/http-auth0/actions/workflows/release.yml)
[![CI](https://github.com/itsmechlark/http-auth0/actions/workflows/release.yml/badge.svg)](https://github.com/itsmechlark/http-auth0/actions/workflows/release.yml)

HTTP client abstraction layer for Auth Application [RFC](https://github.com/carabao-capital/rfcs/pull/2)
HTTP client abstraction layer for Auth Application [RFC](https://github.com/itsmechlark/rfcs/pull/2)

## Installation

Add these lines to your application's Gemfile:

```ruby
source 'https://rubygems.pkg.github.com/carabao-capital' do
source 'https://rubygems.pkg.github.com/itsmechlark' do
gem 'http-auth0'
end
```
Expand Down Expand Up @@ -43,7 +43,7 @@ conn = Faraday.new do |f|
f.use HTTP::Auth0::Middleware
end

conn.post("https://staging-01.api.connect.my.firstcircle.ph/graphql")
conn.post("https://example.com/graphql")
```

#### Net::HTTP Example
Expand All @@ -52,7 +52,7 @@ conn.post("https://staging-01.api.connect.my.firstcircle.ph/graphql")
require 'http/auth0'
require 'net/http'

uri = URI("https://staging-01.api.connect.my.firstcircle.ph/graphql")
uri = URI("https://example.com/graphql")
req = Net::HTTP::Get.new(uri)
req['Authorization'] = HTTP::Auth0.token(aud: uri.to_s)

Expand All @@ -71,7 +71,7 @@ puts res.body

## Contributing

1. Clone the [http-auth0 repo](https://github.com/carabao-capital/http-auth0)
1. Clone the [http-auth0 repo](https://github.com/itsmechlark/http-auth0)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
Expand Down
17 changes: 9 additions & 8 deletions http-auth0.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ require_relative "lib/http/auth0/version"
Gem::Specification.new do |s|
s.name = "http-auth0"
s.version = HTTP::Auth0.gem_version
s.authors = ["First Circle Engineering"]
s.email = ["tech@firstcircle.com"]
s.authors = ["John Chlark Sumatra"]
s.email = ["clark@sumatra.com.ph"]

s.summary = "Faraday adapter for Auth0"
s.description = "Faraday adapter for Auth0"
s.homepage = "https://github.com/carabao-capital/http-auth0"
s.homepage = "https://github.com/itsmechlark/http-auth0"
s.license = "MIT"

s.required_ruby_version = Gem::Requirement.new(">= 2.7")

s.metadata = {
"homepage_uri" => s.homepage,
"changelog_uri" => "https://github.com/carabao-capital/http-auth0/releases/tag/v#{s.version}",
"source_code_uri" => "https://github.com/carabao-capital/http-auth0/tree/v#{s.version}",
"bug_tracker_uri" => "https://github.com/carabao-capital/http-auth0/issues",
"changelog_uri" => "https://github.com/itsmechlark/http-auth0/releases/tag/v#{s.version}",
"source_code_uri" => "https://github.com/itsmechlark/http-auth0/tree/v#{s.version}",
"bug_tracker_uri" => "https://github.com/itsmechlark/http-auth0/issues",
"github_repo" => "https://github.com/itsmechlark/http-auth0",
}

s.files = Dir.glob("lib/**/*") + ["README.md", "LICENSE.md"]
s.test_files = %x(git ls-files -- spec/*).split("\n")
s.require_paths = ["lib"]
s.extra_rdoc_files = ["LICENSE.md", "README.md"]

Expand All @@ -34,6 +34,7 @@ Gem::Specification.new do |s|
s.add_development_dependency("faraday", "~> 2.0")

s.add_development_dependency("bundler", "~> 2.0")
s.add_development_dependency("code-scanning-rubocop")
s.add_development_dependency("faker", "~> 2.0")
s.add_development_dependency("multipart-parser", "~> 0.1.1")
s.add_development_dependency("pry-byebug", "~> 3.7")
Expand All @@ -42,7 +43,7 @@ Gem::Specification.new do |s|
s.add_development_dependency("rubocop-performance")
s.add_development_dependency("rubocop-rake")
s.add_development_dependency("rubocop-rspec")
s.add_development_dependency("rubocop-shopify", "~> 2.4.0")
s.add_development_dependency("rubocop-shopify", "~> 2.14")
s.add_development_dependency("simplecov", "~> 0.19.0")
s.add_development_dependency("timecop", "~> 0.9.4")
s.add_development_dependency("vcr", "~> 6.0")
Expand Down
8 changes: 5 additions & 3 deletions lib/http/auth0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ class Auth0
setting(:client_secret, default: ENV["AUTH0_CLIENT_SECRET"].presence)
setting(:custom_domain, default: ENV["AUTH0_CUSTOM_DOMAIN"].presence)
setting(:domain, default: ENV["AUTH0_DOMAIN"].presence)
setting(:logger, default: Logger.new(STDOUT))
setting(:logger, default: Logger.new($stdout))
setting(:seconds_before_refresh, default: 60)

def self.token(aud:)
Token.instance.token(aud: aud)
class << self
def token(aud:)
Token.instance.token(aud: aud)
end
end
end
end
Expand Down
15 changes: 5 additions & 10 deletions lib/http/auth0/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,12 @@

module HTTP
class Auth0
def self.gem_version
Gem::Version.new(VERSION::STRING)
end

module VERSION
MAJOR = 1
MINOR = 0
TINY = 0
PRE = "rc1"
VERSION = "1.0.0.rc1"

STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
class << self
def gem_version
Gem::Version.new(VERSION)
end
end
end
end
2 changes: 1 addition & 1 deletion spec/fixtures/vcr_cassettes/auth0/token.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions spec/http/auth0/middleware_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let(:auth0) { HTTP::Auth0 }

describe "#on_request(env)" do
let(:app) { instance_double("app") }
let(:app) { instance_double("app") } # rubocop:disable RSpec/VerifiedDoubleReference
let(:middleware) { described_class.new(app) }

context "when Authorization header is set" do
Expand All @@ -15,8 +15,8 @@
it do
expect(
middleware.on_request(
Struct.new(:request_headers).new(request_headers)
)
Struct.new(:request_headers).new(request_headers),
),
).to(be_nil)
end
end
Expand All @@ -25,7 +25,7 @@
let(:env) do
Struct.new(:request_headers, :url).new(
{},
URI("https://mirror.app.firstcircle.ph")
URI("https://example.com"),
)
end

Expand Down
Loading

0 comments on commit ab375ca

Please sign in to comment.