stitches 4.2.0.RC2 → 4.2.2
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 +4 -4
- data/lib/stitches/api_client_access_wrapper.rb +6 -2
- data/lib/stitches/api_generator.rb +1 -11
- data/lib/stitches/generator_files/db/migrate/add_disabled_at_to_api_clients.rb +1 -5
- data/lib/stitches/generator_files/db/migrate/add_enabled_to_api_clients.rb +1 -5
- data/lib/stitches/generator_files/db/migrate/create_api_clients.rb +1 -5
- data/lib/stitches/generator_files/db/migrate/enable_uuid_ossp_extension.rb +1 -5
- data/lib/stitches/version.rb +1 -1
- data/spec/api_key_middleware_spec.rb +12 -4
- data/spec/fake_app/Gemfile +0 -1
- data/spec/integration/add_to_rails_app_spec.rb +1 -5
- metadata +5 -7
- data/spec/fake_app/doc/api.md +0 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 31a88657d0835e4d9dae083be3a5351e0cfe719dc0c930def115d0a1d9749849
         | 
| 4 | 
            +
              data.tar.gz: 4f873d97147ef91da025f0f06eb29c0c800f6a2f6410739cc64c7050b17fbb4b
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9c78c55c6a88cf128e1d58e9fce561f32f53207c0de2f8ddb107449fe2de2638e73f76e842aece05b1d5431072459bf7747dd736746d7ad81f3c153841f00627
         | 
| 7 | 
            +
              data.tar.gz: 0ae33e523eb0f782f6cdf3a0bc457c8f09fa3a140759e344f8fe07b6a9b209dfcb119df77abe167017a491462bb83db9f10ce7f1aae7d82aa5c8b9b7046ef1bb
         | 
| @@ -33,7 +33,7 @@ module Stitches::ApiClientAccessWrapper | |
| 33 33 |  | 
| 34 34 | 
             
                disabled_at = api_client.respond_to?(:disabled_at) ? api_client.disabled_at : nil
         | 
| 35 35 | 
             
                if disabled_at && disabled_at > configuration.disabled_key_leniency_in_seconds.seconds.ago
         | 
| 36 | 
            -
                  message = "Allowing disabled ApiClient: #{api_client.name} with key #{api_client | 
| 36 | 
            +
                  message = "Allowing disabled ApiClient: #{api_client.name} with key #{redact_key(api_client)} disabled at #{disabled_at}"
         | 
| 37 37 | 
             
                  if disabled_at > configuration.disabled_key_leniency_error_log_threshold_in_seconds.seconds.ago
         | 
| 38 38 | 
             
                    logger.warn(message)
         | 
| 39 39 | 
             
                  else
         | 
| @@ -41,11 +41,15 @@ module Stitches::ApiClientAccessWrapper | |
| 41 41 | 
             
                  end
         | 
| 42 42 | 
             
                  return api_client
         | 
| 43 43 | 
             
                else
         | 
| 44 | 
            -
                  logger.error("Rejecting disabled ApiClient: #{api_client.name} with key #{api_client | 
| 44 | 
            +
                  logger.error("Rejecting disabled ApiClient: #{api_client.name} with key #{redact_key(api_client)}")
         | 
| 45 45 | 
             
                end
         | 
| 46 46 | 
             
                nil
         | 
| 47 47 | 
             
              end
         | 
| 48 48 |  | 
| 49 | 
            +
              def self.redact_key(api_client)
         | 
| 50 | 
            +
                "*****#{api_client.key.to_s[-8..-1]}"
         | 
| 51 | 
            +
              end
         | 
| 52 | 
            +
             | 
| 49 53 | 
             
              def self.logger
         | 
| 50 54 | 
             
                if defined?(StitchFix::Logger::LogWriter)
         | 
| 51 55 | 
             
                  StitchFix::Logger::LogWriter
         | 
| @@ -12,7 +12,6 @@ module Stitches | |
| 12 12 |  | 
| 13 13 | 
             
                desc "Bootstraps your API service with a basic ping controller and spec to ensure everything is setup properly"
         | 
| 14 14 | 
             
                def bootstrap_api
         | 
| 15 | 
            -
                  gem "apitome"
         | 
| 16 15 | 
             
                  gem_group :development, :test do
         | 
| 17 16 | 
             
                    gem "rspec"
         | 
| 18 17 | 
             
                    gem "rspec-rails"
         | 
| @@ -22,12 +21,8 @@ module Stitches | |
| 22 21 | 
             
                  Bundler.with_clean_env do
         | 
| 23 22 | 
             
                    run "bundle install"
         | 
| 24 23 | 
             
                  end
         | 
| 25 | 
            -
                  generate "apitome:install"
         | 
| 26 24 | 
             
                  generate "rspec:install"
         | 
| 27 25 |  | 
| 28 | 
            -
                  gsub_file 'config/initializers/apitome.rb', /config.mount_at = .*$/, "config.mount_at = nil"
         | 
| 29 | 
            -
                  gsub_file 'config/initializers/apitome.rb', /config.title = .*$/, "config.title = 'Service Documentation'"
         | 
| 30 | 
            -
             | 
| 31 26 | 
             
                  inject_into_file "config/routes.rb", before: /^end/ do<<-ROUTES
         | 
| 32 27 | 
             
            namespace :api do
         | 
| 33 28 | 
             
              scope module: :v1, constraints: Stitches::ApiVersionConstraint.new(1) do
         | 
| @@ -40,11 +35,6 @@ namespace :api do | |
| 40 35 | 
             
                # as well as for your client to be able to validate this as well.
         | 
| 41 36 | 
             
              end
         | 
| 42 37 | 
             
            end
         | 
| 43 | 
            -
             | 
| 44 | 
            -
            api_docs = Rack::Auth::Basic.new(Apitome::Engine) do |_, password|
         | 
| 45 | 
            -
              password == ENV['HTTP_AUTH_PASSWORD']
         | 
| 46 | 
            -
            end
         | 
| 47 | 
            -
            mount api_docs, at: "docs"
         | 
| 48 38 | 
             
                  ROUTES
         | 
| 49 39 | 
             
                  end
         | 
| 50 40 |  | 
| @@ -77,7 +67,7 @@ require 'stitches/spec' | |
| 77 67 | 
             
            require 'rspec_api_documentation'
         | 
| 78 68 |  | 
| 79 69 | 
             
            RspecApiDocumentation.configure do |config|
         | 
| 80 | 
            -
              config.format = :json
         | 
| 70 | 
            +
              config.format = [:json, :html]
         | 
| 81 71 | 
             
              config.request_headers_to_include = %w(
         | 
| 82 72 | 
             
                Accept
         | 
| 83 73 | 
             
                Content-Type
         | 
| @@ -1,8 +1,4 @@ | |
| 1 | 
            -
            <% if Rails::VERSION::MAJOR >= 5 %>
         | 
| 2 | 
            -
            class AddDisabledAtToApiClients < ActiveRecord::Migration[<%= Rails::VERSION::MAJOR %>.<%= Rails::VERSION::MINOR %>]
         | 
| 3 | 
            -
            <% else %>
         | 
| 4 | 
            -
            class AddDisabledAtToApiClients < ActiveRecord::Migration
         | 
| 5 | 
            -
            <% end %>
         | 
| 1 | 
            +
            class AddDisabledAtToApiClients < ActiveRecord::Migration<% if Rails::VERSION::MAJOR >= 5 %>[<%= Rails::VERSION::MAJOR %>.<%= Rails::VERSION::MINOR %>]<% end %>
         | 
| 6 2 | 
             
              def change
         | 
| 7 3 | 
             
                add_column :api_clients, :disabled_at, "timestamp with time zone", null: true
         | 
| 8 4 | 
             
              end
         | 
| @@ -1,8 +1,4 @@ | |
| 1 | 
            -
            <% if Rails::VERSION::MAJOR >= 5 %>
         | 
| 2 | 
            -
            class AddEnabledToApiClients < ActiveRecord::Migration[<%= Rails::VERSION::MAJOR %>.<%= Rails::VERSION::MINOR %>]
         | 
| 3 | 
            -
            <% else %>
         | 
| 4 | 
            -
            class AddEnabledToApiClients < ActiveRecord::Migration
         | 
| 5 | 
            -
            <% end %>
         | 
| 1 | 
            +
            class AddEnabledToApiClients < ActiveRecord::Migration<% if Rails::VERSION::MAJOR >= 5 %>[<%= Rails::VERSION::MAJOR %>.<%= Rails::VERSION::MINOR %>]<% end %>
         | 
| 6 2 | 
             
              def change
         | 
| 7 3 | 
             
                add_column :api_clients, :enabled, :bool, null: false, default: true
         | 
| 8 4 | 
             
                remove_index :api_clients, [:name ] # existing one would be unique
         | 
| @@ -1,8 +1,4 @@ | |
| 1 | 
            -
            <% if Rails::VERSION::MAJOR >= 5 %>
         | 
| 2 | 
            -
            class CreateApiClients < ActiveRecord::Migration[<%= Rails::VERSION::MAJOR %>.<%= Rails::VERSION::MINOR %>]
         | 
| 3 | 
            -
            <% else %>
         | 
| 4 | 
            -
            class CreateApiClients < ActiveRecord::Migration
         | 
| 5 | 
            -
            <% end %>
         | 
| 1 | 
            +
            class CreateApiClients < ActiveRecord::Migration<% if Rails::VERSION::MAJOR >= 5 %>[<%= Rails::VERSION::MAJOR %>.<%= Rails::VERSION::MINOR %>]<% end %>
         | 
| 6 2 | 
             
              def change
         | 
| 7 3 | 
             
                create_table :api_clients do |t|
         | 
| 8 4 | 
             
                  t.string :name, null: false
         | 
| @@ -1,8 +1,4 @@ | |
| 1 | 
            -
            <% if Rails::VERSION::MAJOR >= 5 %>
         | 
| 2 | 
            -
            class EnableUuidOsspExtension < ActiveRecord::Migration[<%= Rails::VERSION::MAJOR %>.<%= Rails::VERSION::MINOR %>]
         | 
| 3 | 
            -
            <% else %>
         | 
| 4 | 
            -
            class EnableUuidOsspExtension < ActiveRecord::Migration
         | 
| 5 | 
            -
            <% end %>
         | 
| 1 | 
            +
            class EnableUuidOsspExtension < ActiveRecord::Migration<% if Rails::VERSION::MAJOR >= 5 %>[<%= Rails::VERSION::MAJOR %>.<%= Rails::VERSION::MINOR %>]<% end %>
         | 
| 6 2 | 
             
              def change
         | 
| 7 3 | 
             
                enable_extension 'uuid-ossp'
         | 
| 8 4 | 
             
              end
         | 
    
        data/lib/stitches/version.rb
    CHANGED
    
    
| @@ -102,10 +102,11 @@ RSpec.describe "/api/hellos", type: :request do | |
| 102 102 | 
             
                    context "when disabled_at is set to a time older than three days ago" do
         | 
| 103 103 | 
             
                      let(:disabled_at) { 4.day.ago }
         | 
| 104 104 |  | 
| 105 | 
            -
                      it " | 
| 105 | 
            +
                      it "does not allow the call" do
         | 
| 106 106 | 
             
                        execute_call
         | 
| 107 107 |  | 
| 108 108 | 
             
                        expect_unauthorized
         | 
| 109 | 
            +
             | 
| 109 110 | 
             
                      end
         | 
| 110 111 | 
             
                    end
         | 
| 111 112 |  | 
| @@ -162,7 +163,9 @@ RSpec.describe "/api/hellos", type: :request do | |
| 162 163 |  | 
| 163 164 | 
             
                      it "logs error about the disabled key to the Rails.logger" do
         | 
| 164 165 | 
             
                        allow(Rails.logger).to receive(:warn)
         | 
| 165 | 
            -
                        allow(Rails.logger).to receive(:error)
         | 
| 166 | 
            +
                        allow(Rails.logger).to receive(:error) do |message1|
         | 
| 167 | 
            +
                          expect(message1).not_to include uuid
         | 
| 168 | 
            +
                        end
         | 
| 166 169 |  | 
| 167 170 | 
             
                        execute_call
         | 
| 168 171 |  | 
| @@ -210,7 +213,10 @@ RSpec.describe "/api/hellos", type: :request do | |
| 210 213 | 
             
                        let(:disabled_at) { 101.seconds.ago }
         | 
| 211 214 |  | 
| 212 215 | 
             
                        it "forbids the call" do
         | 
| 213 | 
            -
                          allow(Rails.logger).to receive(:error)
         | 
| 216 | 
            +
                          allow(Rails.logger).to receive(:error) do |message1|
         | 
| 217 | 
            +
                            expect(message1).not_to include uuid
         | 
| 218 | 
            +
                          end
         | 
| 219 | 
            +
             | 
| 214 220 | 
             
                          execute_call
         | 
| 215 221 |  | 
| 216 222 | 
             
                          expect_unauthorized
         | 
| @@ -235,7 +241,9 @@ RSpec.describe "/api/hellos", type: :request do | |
| 235 241 | 
             
                        let(:disabled_at) { 25.seconds.ago }
         | 
| 236 242 |  | 
| 237 243 | 
             
                        it "allows the call" do
         | 
| 238 | 
            -
                          allow(Rails.logger).to receive(:warn)
         | 
| 244 | 
            +
                          allow(Rails.logger).to receive(:warn) do |message1|
         | 
| 245 | 
            +
                            expect(message1).not_to include uuid
         | 
| 246 | 
            +
                          end
         | 
| 239 247 |  | 
| 240 248 | 
             
                          execute_call
         | 
| 241 249 |  | 
    
        data/spec/fake_app/Gemfile
    CHANGED
    
    
| @@ -51,7 +51,7 @@ RSpec.describe "Adding Stitches to a New Rails App", :integration do | |
| 51 51 | 
             
                      run use_local_stitches
         | 
| 52 52 | 
             
                      # It's unclear why, but on CI the gems are not found when installed
         | 
| 53 53 | 
             
                      # through bundler however installing them explicitly first fixes it.
         | 
| 54 | 
            -
                      run "gem install  | 
| 54 | 
            +
                      run "gem install rspec-rails rspec_api_documentation"
         | 
| 55 55 | 
             
                      run "bundle install"
         | 
| 56 56 | 
             
                      example.run
         | 
| 57 57 | 
             
                    end
         | 
| @@ -69,11 +69,9 @@ RSpec.describe "Adding Stitches to a New Rails App", :integration do | |
| 69 69 | 
             
                # It's also in one big block because making a new rails app and running the generator multiple times seems bad.
         | 
| 70 70 | 
             
                aggregate_failures do
         | 
| 71 71 | 
             
                  expect(File.exist?(rails_root / "app" / "controllers" / "api" / "api_controller.rb")).to eq(true)
         | 
| 72 | 
            -
                  expect(rails_root / "Gemfile").to contain_gem("apitome")
         | 
| 73 72 | 
             
                  expect(rails_root / "Gemfile").to contain_gem("rspec_api_documentation")
         | 
| 74 73 | 
             
                  expect(rails_root / "config" / "routes.rb").to have_route(namespace: :api, module_scope: :v1, resource: 'ping')
         | 
| 75 74 | 
             
                  expect(rails_root / "config" / "routes.rb").to have_route(namespace: :api, module_scope: :v2, resource: 'ping')
         | 
| 76 | 
            -
                  expect(rails_root / "config" / "routes.rb").to have_mounted_engine("Apitome::Engine")
         | 
| 77 75 | 
             
                  migrations = Dir["#{rails_root}/db/migrate/*.rb"].sort
         | 
| 78 76 | 
             
                  expect(migrations.size).to eq(2)
         | 
| 79 77 | 
             
                  expect(migrations[0]).to match(/\/\d+_enable_uuid_ossp_extension.rb/)
         | 
| @@ -81,8 +79,6 @@ RSpec.describe "Adding Stitches to a New Rails App", :integration do | |
| 81 79 | 
             
                  expect(File.read(rails_root / "spec" / "rails_helper.rb")).to include("config.include RSpec::Rails::RequestExampleGroup, type: :feature")
         | 
| 82 80 | 
             
                  expect(File.read(rails_root / "spec" / "rails_helper.rb")).to include("require 'stitches/spec'")
         | 
| 83 81 | 
             
                  expect(File.read(rails_root / "spec" / "rails_helper.rb")).to include("require 'rspec_api_documentation'")
         | 
| 84 | 
            -
                  expect(File.read(rails_root / "config" / "initializers" / "apitome.rb")).to include("config.mount_at = nil")
         | 
| 85 | 
            -
                  expect(File.read(rails_root / "config" / "initializers" / "apitome.rb")).to include("config.title = 'Service Documentation'")
         | 
| 86 82 | 
             
                  expect(File.read(rails_root / "app" / "controllers" / "api" / "api_controller.rb")).to include("rescue_from StandardError")
         | 
| 87 83 | 
             
                  expect(File.read(rails_root / "app" / "controllers" / "api" / "api_controller.rb")).to include("rescue_from ActiveRecord::RecordNotFound")
         | 
| 88 84 |  | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: stitches
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 4.2. | 
| 4 | 
            +
              version: 4.2.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Stitch Fix Engineering
         | 
| @@ -11,7 +11,7 @@ authors: | |
| 11 11 | 
             
            autorequire:
         | 
| 12 12 | 
             
            bindir: bin
         | 
| 13 13 | 
             
            cert_chain: []
         | 
| 14 | 
            -
            date: 2021- | 
| 14 | 
            +
            date: 2021-10-11 00:00:00.000000000 Z
         | 
| 15 15 | 
             
            dependencies:
         | 
| 16 16 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 17 17 | 
             
              name: rails
         | 
| @@ -251,7 +251,6 @@ files: | |
| 251 251 | 
             
            - spec/fake_app/db/schema_modern.rb
         | 
| 252 252 | 
             
            - spec/fake_app/db/seeds.rb
         | 
| 253 253 | 
             
            - spec/fake_app/db/test.sqlite3
         | 
| 254 | 
            -
            - spec/fake_app/doc/api.md
         | 
| 255 254 | 
             
            - spec/fake_app/lib/tasks/generate_api_key.rake
         | 
| 256 255 | 
             
            - spec/fake_app/public/404.html
         | 
| 257 256 | 
             
            - spec/fake_app/public/422.html
         | 
| @@ -289,11 +288,11 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 289 288 | 
             
                  version: '0'
         | 
| 290 289 | 
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 291 290 | 
             
              requirements:
         | 
| 292 | 
            -
              - - " | 
| 291 | 
            +
              - - ">="
         | 
| 293 292 | 
             
                - !ruby/object:Gem::Version
         | 
| 294 | 
            -
                  version:  | 
| 293 | 
            +
                  version: '0'
         | 
| 295 294 | 
             
            requirements: []
         | 
| 296 | 
            -
            rubygems_version: 3. | 
| 295 | 
            +
            rubygems_version: 3.1.4
         | 
| 297 296 | 
             
            signing_key:
         | 
| 298 297 | 
             
            specification_version: 4
         | 
| 299 298 | 
             
            summary: You'll be in stitches at how easy it is to create a service at Stitch Fix
         | 
| @@ -352,7 +351,6 @@ test_files: | |
| 352 351 | 
             
            - spec/fake_app/db/schema_modern.rb
         | 
| 353 352 | 
             
            - spec/fake_app/db/seeds.rb
         | 
| 354 353 | 
             
            - spec/fake_app/db/test.sqlite3
         | 
| 355 | 
            -
            - spec/fake_app/doc/api.md
         | 
| 356 354 | 
             
            - spec/fake_app/lib/tasks/generate_api_key.rake
         | 
| 357 355 | 
             
            - spec/fake_app/public/404.html
         | 
| 358 356 | 
             
            - spec/fake_app/public/422.html
         | 
    
        data/spec/fake_app/doc/api.md
    DELETED