stitches 5.1.0.RC2 → 5.1.0.RC3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74c049e2d66d366adce255f0fd8d41b6eb0e121669225b1fbce4dbd8ccb19b10
4
- data.tar.gz: 8d8b6b8d5cc2e57b4e21a5a9097ccd14b462087c82ce6c30cfd2e6b4617c49c5
3
+ metadata.gz: e2b49b7056175fa55cc2b597754f143cca6e841a3aafe723fab3681fb646f4c2
4
+ data.tar.gz: 87a15dcf53ad770755faec02eae327a9195c26b834babaef526dedffe4d9568e
5
5
  SHA512:
6
- metadata.gz: 343c659a9e37f29caadad39b2c0d66496f164efea60e9a499daec8bb156fd5e90801af304d2bc0ac307c00ee4934b400ea4f22db4e7a996b9d7d114751a5a55c
7
- data.tar.gz: dfaa3c860b35fbbbd44ba3c99d4ac1a1ce820de42393ddaa9d93cb12fb0062ad03d14cfb2a7f0ab64dfe5fa83ecd72271c30aa222923ba9fc5cecb35501d8311
6
+ metadata.gz: b076a27646bd5919cdcf1a2c066536888b90e9a851ce9828369891c3198cbdef8f3208ee1d643344b7f592057d72fefd1b855ab0de0705cdcb708a1d91aa1ccc
7
+ data.tar.gz: e5d3445946a09d9e54f63060edea96fd5fd0b9156622f9f094850d7ae93cca9a7737d5c7d3800e3c722dbe87a69ea3911e332da1fe3d5ee8c680e4f045cca016
data/.circleci/config.yml CHANGED
@@ -26,6 +26,9 @@ parameters:
26
26
  type: string
27
27
  default: "8.1.2"
28
28
 
29
+ orbs:
30
+ stitchfix_build: stitchfix/build@dev:master
31
+
29
32
  jobs:
30
33
  generate-and-push-docs:
31
34
  docker:
@@ -45,29 +48,12 @@ jobs:
45
48
  docs:generate:custom ; elif [[ $(bundle exec rake -T docs:generate) ]];
46
49
  then echo "Generating docs using rake task docs:generate" ; bundle exec
47
50
  rake docs:generate ; else echo "Skipping doc generation" ; exit 0 ; fi '
51
+ - stitchfix_build/aws_cli_setup_eng
48
52
  - run:
49
53
  name: Push documentation to Unwritten
50
54
  command:
51
55
  if [[ $(bundle exec rake -T docs:push) ]]; then bundle exec rake
52
56
  docs:push; fi
53
- release:
54
- docker:
55
- - image: cimg/ruby:3.3.7
56
- auth:
57
- username: "$DOCKERHUB_USERNAME"
58
- password: "$DOCKERHUB_PASSWORD"
59
- steps:
60
- - checkout
61
- - run: bundle config stitchfix01.jfrog.io $ARTIFACTORY_USER:$ARTIFACTORY_TOKEN
62
- - run: bundle install
63
- - run:
64
- name: Artifactory login
65
- command:
66
- mkdir -p ~/.gem && curl -u$ARTIFACTORY_USER:$ARTIFACTORY_TOKEN https://stitchfix01.jfrog.io/stitchfix01/api/gems/eng-gems/api/v1/api_key.yaml
67
- > ~/.gem/credentials && chmod 0600 ~/.gem/credentials
68
- - run:
69
- name: Build/release gem to artifactory
70
- command: bundle exec rake push_artifactory
71
57
  test:
72
58
  parameters:
73
59
  ruby-version:
@@ -87,6 +73,7 @@ jobs:
87
73
  auth:
88
74
  username: "$DOCKERHUB_USERNAME"
89
75
  password: "$DOCKERHUB_PASSWORD"
76
+ resource_class: medium.gen2
90
77
  working_directory: "~/stitches"
91
78
  environment:
92
79
  DATABASE_URL: "postgres://postgres:@localhost:5432/stitches_fake_app_test"
@@ -136,19 +123,10 @@ workflows:
136
123
  unless:
137
124
  equal: ["schedule", << pipeline.parameters.GHA_Event >>]
138
125
  jobs:
139
- - release:
140
- context: org-global
141
- requires:
142
- - test
143
- filters:
144
- tags:
145
- only: "/^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:(-|\\.)(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$/"
146
- branches:
147
- ignore: /.*/
148
126
  - generate-and-push-docs:
149
127
  context: org-global
150
128
  requires:
151
- - release
129
+ - test
152
130
  filters:
153
131
  tags:
154
132
  only: "/^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:(-|\\.)(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$/"
@@ -1,11 +1,9 @@
1
1
  module Stitches
2
2
  module CallingServiceName
3
- HEADER = "X-StitchFix-Calling-Service"
4
-
5
3
  def calling_service_name
6
4
  @calling_service_name ||=
7
- request.headers[HEADER].presence ||
8
- (respond_to?(:api_client, true) && api_client&.name) ||
5
+ request.headers[Stitches.configuration.calling_service_header].presence ||
6
+ request.env[Stitches.configuration.env_var_to_hold_api_client]&.name ||
9
7
  ""
10
8
  end
11
9
  end
@@ -13,6 +13,7 @@ class Stitches::Configuration
13
13
  @custom_http_auth_scheme = UnsetString.new("custom_http_auth_scheme")
14
14
  @env_var_to_hold_api_client_primary_key = NonNullString.new("env_var_to_hold_api_client_primary_key","STITCHES_API_CLIENT_ID")
15
15
  @env_var_to_hold_api_client= NonNullString.new("env_var_to_hold_api_client","STITCHES_API_CLIENT")
16
+ @calling_service_header = NonNullString.new("calling_service_header", "X-StitchFix-Calling-Service")
16
17
  @max_cache_ttl = NonNullInteger.new("max_cache_ttl", 0)
17
18
  @max_cache_size = NonNullInteger.new("max_cache_size", 0)
18
19
  @disabled_key_leniency_in_seconds = ActiveSupport::Duration.days(3)
@@ -61,6 +62,16 @@ class Stitches::Configuration
61
62
  @env_var_to_hold_api_client= NonNullString.new("env_var_to_hold_api_client",new_env_var_to_hold_api_client)
62
63
  end
63
64
 
65
+ # The name of the HTTP header used to identify the calling service.
66
+ # Clients send this header; servers read it via CallingServiceName.
67
+ def calling_service_header
68
+ @calling_service_header.to_s
69
+ end
70
+
71
+ def calling_service_header=(new_calling_service_header)
72
+ @calling_service_header = NonNullString.new("calling_service_header", new_calling_service_header)
73
+ end
74
+
64
75
  def max_cache_ttl
65
76
  @max_cache_ttl.to_i
66
77
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stitches
4
- VERSION = '5.1.0.RC2'
4
+ VERSION = '5.1.0.RC3'
5
5
  end
@@ -2,15 +2,13 @@ require 'rails_helper'
2
2
 
3
3
  describe Stitches::CallingServiceName do
4
4
  let(:headers) { {} }
5
- let(:fake_request) { double("request", headers: headers) }
6
- let(:fake_api_client) { nil }
5
+ let(:env) { {} }
6
+ let(:fake_request) { double("request", headers: headers, env: env) }
7
7
  let(:fake_controller) {
8
8
  req = fake_request
9
- client = fake_api_client
10
9
  Object.new.tap { |c|
11
10
  c.extend(described_class)
12
11
  c.define_singleton_method(:request) { req }
13
- c.define_singleton_method(:api_client) { client }
14
12
  }
15
13
  }
16
14
 
@@ -22,8 +20,8 @@ describe Stitches::CallingServiceName do
22
20
  expect(fake_controller.calling_service_name).to eq("kingmob")
23
21
  end
24
22
 
25
- context "and api_client is also present" do
26
- let(:fake_api_client) { double("ApiClient", name: "other-service") }
23
+ context "and env var client is also present" do
24
+ let(:env) { {Stitches.configuration.env_var_to_hold_api_client => double(name: "other-service")} }
27
25
 
28
26
  it "prefers the header" do
29
27
  expect(fake_controller.calling_service_name).to eq("kingmob")
@@ -31,63 +29,58 @@ describe Stitches::CallingServiceName do
31
29
  end
32
30
  end
33
31
 
34
- context "when header is absent but api_client is present" do
35
- let(:fake_api_client) { double("ApiClient", name: "mobile-service") }
32
+ context "when header is absent but env var client is present" do
33
+ let(:env) { {Stitches.configuration.env_var_to_hold_api_client => double(name: "mobile-service")} }
36
34
 
37
- it "returns the api_client name" do
35
+ it "returns the client name from env" do
38
36
  expect(fake_controller.calling_service_name).to eq("mobile-service")
39
37
  end
40
38
  end
41
39
 
42
40
  context "when header is blank" do
43
41
  let(:headers) { {"X-StitchFix-Calling-Service" => ""} }
44
- let(:fake_api_client) { double("ApiClient", name: "fallback-service") }
42
+ let(:env) { {Stitches.configuration.env_var_to_hold_api_client => double(name: "fallback-service")} }
45
43
 
46
- it "treats blank as absent and falls through to api_client" do
44
+ it "treats blank as absent and falls through to env var client" do
47
45
  expect(fake_controller.calling_service_name).to eq("fallback-service")
48
46
  end
49
47
  end
50
48
 
51
- context "when neither header nor api_client is present" do
52
- it "returns 'unknown'" do
49
+ context "when neither header nor env var client is present" do
50
+ it "returns empty string" do
53
51
  expect(fake_controller.calling_service_name).to eq("")
54
52
  end
55
53
  end
56
54
 
57
- context "when api_client is nil" do
58
- let(:fake_api_client) { nil }
55
+ context "when env var client is nil" do
56
+ let(:env) { {Stitches.configuration.env_var_to_hold_api_client => nil} }
59
57
 
60
58
  it "returns empty string" do
61
59
  expect(fake_controller.calling_service_name).to eq("")
62
60
  end
63
61
  end
64
62
 
65
- context "when api_client method is not defined" do
66
- let(:fake_controller) {
67
- req = fake_request
68
- Object.new.tap { |c|
69
- c.extend(described_class)
70
- c.define_singleton_method(:request) { req }
71
- }
72
- }
63
+ end
73
64
 
74
- it "returns empty string" do
75
- expect(fake_controller.calling_service_name).to eq("")
76
- end
65
+ describe "configurable header" do
66
+ it "defaults to X-StitchFix-Calling-Service" do
67
+ expect(Stitches.configuration.calling_service_header).to eq("X-StitchFix-Calling-Service")
68
+ end
77
69
 
78
- context "and header is present" do
79
- let(:headers) { {"X-StitchFix-Calling-Service" => "fixops"} }
70
+ context "when configured to a custom header" do
71
+ let(:headers) { {"X-Custom-Caller" => "my-service"} }
80
72
 
81
- it "returns the header value" do
82
- expect(fake_controller.calling_service_name).to eq("fixops")
83
- end
73
+ before do
74
+ Stitches.configuration.calling_service_header = "X-Custom-Caller"
84
75
  end
85
- end
86
- end
87
76
 
88
- describe "::HEADER" do
89
- it "is the expected header name" do
90
- expect(described_class::HEADER).to eq("X-StitchFix-Calling-Service")
77
+ after do
78
+ Stitches.configuration.reset_to_defaults!
79
+ end
80
+
81
+ it "reads from the configured header" do
82
+ expect(fake_controller.calling_service_name).to eq("my-service")
83
+ end
91
84
  end
92
85
  end
93
86
  end
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: 5.1.0.RC2
4
+ version: 5.1.0.RC3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stitch Fix Engineering