active_force 0.24.0 → 0.26.0

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: 0e6bf4ca3441ea8c1d0df00f6a8925f021fa53a3a0ce2e19beda69ecab4b5881
4
- data.tar.gz: 940b3627880eb3a67d8387c744246a8bb29cc816ccf828130dd375e1e33b1791
3
+ metadata.gz: 657c5d9e979b06641cae8f6734a9a0371669dcc3fca816e89c0a23fca20537fb
4
+ data.tar.gz: c6e3646ea293a22d459faca15f8fbf9b16cbaf4482b7c38dc4e135dac22da6e7
5
5
  SHA512:
6
- metadata.gz: b7ab1dc49814c642b34b61391a2d8ab99fc2b0854f3113b5c4d5715a67ec681d3061fa2e3e53eea3ec9780525aeba3804c7043901b7652baa67113d2659bd8dc
7
- data.tar.gz: d69e76e37be28552a80a9a3e2872a48ff15e04df4178f5ce2b670426be23570a7ca11256e41ed757ba04fc20270bff875730d8aea2927eee7e0129124c5f994e
6
+ metadata.gz: b9a1fb7822ad1950f32fc86e20e9e00cf29a5f471b2792eda9fe8ae9aae1db6f2b1817ac8fcf6fc9b0ec74ee351e62befb0aab8a6e83a7a5ec09a3761e656f85
7
+ data.tar.gz: 7f1cb6448305cef1fd185cce72571f1eff55aa3115444edf215dd031711fe6027b51922832392eb02a1e60a82b9d77616bffe271aad638344686122bdeae91c6
data/.circleci/config.yml CHANGED
@@ -1,4 +1,7 @@
1
- version: 2
1
+ version: 2.1
2
+
3
+ orbs:
4
+ codecov: codecov/codecov@4.0.1
2
5
 
3
6
  references:
4
7
  default_docker_ruby_executor: &default_docker_ruby_executor
@@ -51,49 +54,16 @@ jobs:
51
54
  key: active_force-{{ checksum "active_force.gemspec" }}
52
55
  paths:
53
56
  - ~/active_force/active_force_index/vendor/bundle
54
- - run:
55
- name: Install Code Climate Test Reporter
56
- command: |
57
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
58
- chmod +x ./cc-test-reporter
59
57
  - run:
60
58
  name: Run RSpec
61
59
  command: |
62
60
  mkdir /tmp/test-results
63
- ./cc-test-reporter before-build
64
61
  TESTFILES=$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
65
62
  bundle exec rspec $TESTFILES --profile 10 --format RspecJunitFormatter --out /tmp/test-results/rspec.xml --format progress
66
- - run:
67
- name: Code Climate Test Coverage
68
- command: |
69
- ./cc-test-reporter format-coverage -t simplecov -o "coverage/codeclimate.$CIRCLE_NODE_INDEX.json"
70
- - persist_to_workspace:
71
- root: coverage
72
- paths:
73
- - codeclimate.*.json
74
- - store_test_results:
75
- path: /tmp/test-results
76
- - store_artifacts:
77
- path: /tmp/test-results
78
- destination: test-results
63
+ - codecov/upload
79
64
  - store_artifacts:
80
65
  path: coverage
81
- upload-coverage:
82
- working_directory: ~/active_force/active_force_index
83
- docker:
84
- - *default_docker_ruby_executor
85
- steps:
86
- - attach_workspace:
87
- at: ~/active_force/active_force_index
88
- - run:
89
- name: Install Code Climate Test Reporter
90
- command: |
91
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
92
- chmod +x ./cc-test-reporter
93
- - run:
94
- name: Combine and Upload Coverage
95
- command: |
96
- ./cc-test-reporter sum-coverage --output - codeclimate.*.json | ./cc-test-reporter upload-coverage --debug --input -
66
+
97
67
  workflows:
98
68
  version: 2
99
69
  build_and_test:
@@ -102,6 +72,3 @@ workflows:
102
72
  - rspec-test:
103
73
  requires:
104
74
  - build
105
- - upload-coverage:
106
- requires:
107
- - rspec-test
data/.travis.yml CHANGED
@@ -9,8 +9,6 @@ matrix:
9
9
  - rvm:
10
10
  - rbx-2
11
11
  fast_finish: true
12
- env:
13
- - CODECLIMATE_REPO_TOKEN=1c5ed259429e0bfc5412974d69cfba2780962a87ca8c543d684e33fea37f7e71
14
12
  notifications:
15
13
  webhooks:
16
14
  urls:
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Not released
4
4
 
5
+ ## 0.26.0
6
+ - Add ability to query using Composite Batch Api (https://github.com/Beyond-Finance/active_force/pull/114)
7
+
8
+ ## 0.25.0
9
+ - Add support for Rails 8.x (https://github.com/Beyond-Finance/active_force/pull/108)
10
+
5
11
  ## 0.24.0
6
12
  - Add support for nested select statements that are used in conjuction with nested includes (https://github.com/Beyond-Finance/active_force/pull/102)
7
13
 
data/LICENSE.txt CHANGED
@@ -1,3 +1,11 @@
1
+ [Copyright © 2024 Beyond Finance, LLC.]
2
+
3
+ This library is available as open source under the terms of the
4
+ MIT License (https://opensource.org/license/mit). This library is
5
+ based on the open source code library "https://github.com/heroku/active_force" which was in turn forked from
6
+ "https://github.com/ionia-corporation/active_force" and licensed
7
+ under the MIT License.
8
+
1
9
  Copyright (c) 2013 Eloy Espinaco
2
10
 
3
11
  MIT License
data/active_force.gemspec CHANGED
@@ -25,12 +25,13 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.required_ruby_version = '>= 1.9.3'
27
27
 
28
- spec.add_dependency 'activemodel', '~> 7.0'
29
- spec.add_dependency 'activesupport', '~> 7.0'
28
+ spec.add_dependency 'activemodel', '>= 7.0'
29
+ spec.add_dependency 'activesupport', '>= 7.0'
30
30
  spec.add_dependency 'restforce', '>= 5'
31
31
  spec.add_development_dependency 'rake', '>= 0'
32
32
  spec.add_development_dependency 'rspec', '>= 0'
33
33
  spec.add_development_dependency 'rspec_junit_formatter'
34
34
  spec.add_development_dependency 'pry', '>= 0'
35
- spec.add_development_dependency 'simplecov', '>= 0'
35
+ spec.add_development_dependency 'simplecov'
36
+ spec.add_development_dependency 'simplecov-cobertura'
36
37
  end
@@ -1,6 +1,7 @@
1
1
  require 'active_support/all'
2
2
  require 'active_force/query'
3
3
  require 'active_force/select_builder'
4
+ require 'active_force/composite_batch_query'
4
5
  require 'forwardable'
5
6
 
6
7
  module ActiveForce
@@ -245,7 +246,13 @@ module ActiveForce
245
246
  end
246
247
 
247
248
  def result
248
- sfdc_client.query(self.to_s)
249
+ soql = self.to_s
250
+
251
+ if soql.length >= ActiveForce.composite_batch_query_threshold
252
+ CompositeBatchQuery.call(soql, sfdc_client)
253
+ else
254
+ sfdc_client.query(soql)
255
+ end
249
256
  end
250
257
 
251
258
  def build_order_by(args)
@@ -0,0 +1,42 @@
1
+ require 'active_support/all'
2
+
3
+ module ActiveForce
4
+ class CompositeBatchQuery
5
+ def self.call(soql, sfdc_client = ActiveForce.sfdc_client)
6
+ new(soql, sfdc_client).call
7
+ end
8
+
9
+ attr_reader :sfdc_client, :soql
10
+
11
+ def initialize(soql, sfdc_client)
12
+ @sfdc_client = sfdc_client
13
+ @soql = soql
14
+ end
15
+
16
+ def call
17
+ results = sfdc_client.batch do |subrequests|
18
+ subrequests.requests << {
19
+ method: "GET",
20
+ url: "v#{subrequests.options[:api_version]}/query?" + {q: soql}.to_query
21
+ }
22
+ end
23
+
24
+ r = results.first
25
+
26
+ process_composite_batch_error_response(r) if r.statusCode >= 300
27
+
28
+ r.result
29
+ end
30
+
31
+ private
32
+
33
+ def process_composite_batch_error_response(r)
34
+ response_value = {status: r.statusCode, body: r.result.as_json}
35
+ error_code = r.result.dig(0, "errorCode")
36
+ message = "#{error_code}: #{r.result.dig(0, "message")}"
37
+ message << "\nRESPONSE: #{r.result.to_json}"
38
+
39
+ raise Restforce::ErrorCode.get_exception_class(error_code).new(message, response_value)
40
+ end
41
+ end
42
+ end
@@ -26,14 +26,15 @@ module ActiveForce
26
26
 
27
27
  define_model_callbacks :build, :create, :update, :save, :destroy
28
28
 
29
- class_attribute :mappings, :table_name
29
+ class_attribute :mappings, :table_name_store
30
30
 
31
31
  attr_accessor :id, :title
32
32
 
33
33
  class << self
34
34
  extend Forwardable
35
35
  def_delegators :query, :not, :or, :where, :first, :last, :all, :find, :find!, :find_by, :find_by!, :sum, :count, :includes, :limit, :order, :select, :none
36
- def_delegators :mapping, :table, :table_name, :custom_table?, :mappings
36
+ def_delegators :mapping, :table, :custom_table?, :mappings
37
+ alias_method :table_name=, :table_name_store=
37
38
 
38
39
  def update(id, attributes)
39
40
  prepare_for_update(id, attributes).update
@@ -43,6 +44,10 @@ module ActiveForce
43
44
  prepare_for_update(id, attributes).update!
44
45
  end
45
46
 
47
+ def table_name
48
+ table_name_store || mapping.table_name
49
+ end
50
+
46
51
  private
47
52
 
48
53
  def prepare_for_update(id, attributes)
@@ -65,6 +70,10 @@ module ActiveForce
65
70
  @mapping ||= ActiveForce::Mapping.new name
66
71
  end
67
72
 
73
+ def table_name
74
+ table_name_store || self.class.mapping.table_name
75
+ end
76
+
68
77
  def self.fields
69
78
  mapping.sfdc_names
70
79
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveForce
4
- VERSION = '0.24.0'
4
+ VERSION = '0.26.0'
5
5
  end
data/lib/active_force.rb CHANGED
@@ -9,8 +9,16 @@ module ActiveForce
9
9
 
10
10
  class << self
11
11
  attr_accessor :sfdc_client
12
+ attr_writer :composite_batch_query_threshold
13
+
14
+ def composite_batch_query_threshold
15
+ @composite_batch_query_threshold ||= 100_000
16
+
17
+ return @composite_batch_query_threshold.call if @composite_batch_query_threshold.respond_to?(:call)
18
+
19
+ @composite_batch_query_threshold
20
+ end
12
21
  end
13
22
 
14
23
  self.sfdc_client = Restforce.new
15
-
16
24
  end
@@ -557,6 +557,26 @@ describe ActiveForce::ActiveQuery do
557
557
  end
558
558
  end
559
559
 
560
+ describe '#result routing' do
561
+ after do
562
+ ActiveForce.instance_variable_set(:@composite_batch_query_threshold, nil)
563
+ end
564
+
565
+ it 'uses sfdc_client.query when SOQL is at or below the threshold' do
566
+ ActiveForce.composite_batch_query_threshold = 100_000
567
+ expect(client).to receive(:query).and_return([])
568
+ expect(ActiveForce::CompositeBatchQuery).not_to receive(:call)
569
+ active_query.where("Id = 'foo'").to_a
570
+ end
571
+
572
+ it 'uses CompositeBatchQuery.call when SOQL exceeds the threshold' do
573
+ ActiveForce.composite_batch_query_threshold = 0
574
+ expect(ActiveForce::CompositeBatchQuery).to receive(:call).and_return([])
575
+ expect(client).not_to receive(:query)
576
+ active_query.where("Id = 'foo'").to_a
577
+ end
578
+ end
579
+
560
580
  describe "#order" do
561
581
  context 'when it is symbol' do
562
582
  it "should add an order condition with actual SF field name" do
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveForce::CompositeBatchQuery do
4
+ let(:soql) { "SELECT Id FROM Account WHERE Name = 'Test'" }
5
+ let(:api_version) { '58.0' }
6
+ let(:sfdc_client) { double(Restforce) }
7
+ let(:subrequests) do
8
+ double('subrequests', requests: [], options: { api_version: api_version })
9
+ end
10
+
11
+ describe '.call' do
12
+ it 'delegates to new(...).call' do
13
+ result_record = double('result_record')
14
+ instance = instance_double(described_class)
15
+ allow(described_class).to receive(:new).with(soql, sfdc_client).and_return(instance)
16
+ allow(instance).to receive(:call).and_return(result_record)
17
+
18
+ expect(described_class.call(soql, sfdc_client)).to eq(result_record)
19
+ end
20
+
21
+ it 'defaults to ActiveForce.sfdc_client when no client is provided' do
22
+ default_client = double(Restforce)
23
+ allow(ActiveForce).to receive(:sfdc_client).and_return(default_client)
24
+
25
+ instance = instance_double(described_class)
26
+ allow(described_class).to receive(:new).with(soql, default_client).and_return(instance)
27
+ allow(instance).to receive(:call).and_return(double('result'))
28
+
29
+ expect { described_class.call(soql) }.not_to raise_error
30
+ expect(described_class).to have_received(:new).with(soql, default_client)
31
+ end
32
+ end
33
+
34
+ describe '#call' do
35
+ context 'when the response is successful' do
36
+ let(:result_record) { double(Restforce::Collection) }
37
+ let(:batch_result) do
38
+ double(Restforce::Mash, statusCode: 200, result: result_record)
39
+ end
40
+
41
+ before do
42
+ allow(sfdc_client).to receive(:batch).and_yield(subrequests).and_return([batch_result])
43
+ end
44
+
45
+ it 'sends a GET batch subrequest with the correct URL' do
46
+ described_class.call(soql, sfdc_client)
47
+
48
+ expected_url = "v#{api_version}/query?" + { q: soql }.to_query
49
+ expect(subrequests.requests).to include(
50
+ hash_including(method: 'GET', url: expected_url)
51
+ )
52
+ end
53
+
54
+ it 'returns the result from the batch response' do
55
+ expect(described_class.call(soql, sfdc_client)).to eq(result_record)
56
+ end
57
+ end
58
+
59
+ context 'when the response statusCode is exactly 300' do
60
+ let(:error_body) do
61
+ [{ 'errorCode' => 'MULTIPLE_CHOICES', 'message' => 'multiple records found' }]
62
+ end
63
+ let(:batch_result) do
64
+ double('batch_result', statusCode: 300, result: error_body)
65
+ end
66
+
67
+ before do
68
+ allow(sfdc_client).to receive(:batch).and_yield(subrequests).and_return([batch_result])
69
+ end
70
+
71
+ it 'treats it as an error' do
72
+ expect {
73
+ described_class.call(soql, sfdc_client)
74
+ }.to raise_error(Restforce::ResponseError)
75
+ end
76
+ end
77
+
78
+ context 'when the response is an error' do
79
+ let(:error_body) do
80
+ [{ 'errorCode' => 'MALFORMED_QUERY', 'message' => 'unexpected token' }]
81
+ end
82
+ let(:batch_result) do
83
+ double(Restforce::Mash, statusCode: 400, result: error_body)
84
+ end
85
+
86
+ before do
87
+ allow(sfdc_client).to receive(:batch).and_yield(subrequests).and_return([batch_result])
88
+ end
89
+
90
+ it 'raises a Restforce error with the correct error code and message' do
91
+ expect {
92
+ described_class.call(soql, sfdc_client)
93
+ }.to raise_error(Restforce::ErrorCode::MalformedQuery) do |error|
94
+ expect(error.message).to include('MALFORMED_QUERY')
95
+ expect(error.message).to include('unexpected token')
96
+ expect(error.message).to include('RESPONSE:')
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -375,6 +375,20 @@ describe ActiveForce::SObject do
375
375
  end
376
376
  end
377
377
 
378
+ describe '.table_name' do
379
+
380
+ context 'when no explicit table name is set' do
381
+ it 'derives the table name from the class name' do
382
+ expect(Whizbang.table_name).to eq('Whizbang__c')
383
+ end
384
+ end
385
+ context 'when explicit table name is set' do
386
+ it 'returns the explicit table name' do
387
+ expect(Whizbang2.table_name).to eq('Whiz_bang2__c')
388
+ end
389
+ end
390
+ end
391
+
378
392
  describe '.sum' do
379
393
  let(:response) { [Restforce::Mash.new(expr0: 22)] }
380
394
 
@@ -4,4 +4,24 @@ describe ActiveForce do
4
4
  it 'should have a version number' do
5
5
  expect(ActiveForce::VERSION).to_not be_nil
6
6
  end
7
+
8
+ describe '.composite_batch_query_threshold' do
9
+ after do
10
+ ActiveForce.instance_variable_set(:@composite_batch_query_threshold, nil)
11
+ end
12
+
13
+ it 'returns 100_000 by default' do
14
+ expect(ActiveForce.composite_batch_query_threshold).to eq(100_000)
15
+ end
16
+
17
+ it 'allows setting a custom integer value' do
18
+ ActiveForce.composite_batch_query_threshold = 25_000
19
+ expect(ActiveForce.composite_batch_query_threshold).to eq(25_000)
20
+ end
21
+
22
+ it 'supports callable values (proc/lambda)' do
23
+ ActiveForce.composite_batch_query_threshold = -> { 50_000 }
24
+ expect(ActiveForce.composite_batch_query_threshold).to eq(50_000)
25
+ end
26
+ end
7
27
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  require 'simplecov'
2
+ require 'simplecov-cobertura'
2
3
  SimpleCov.start do
3
4
  add_filter '/vendor'
4
5
  add_filter '/spec'
6
+
7
+ formatter SimpleCov::Formatter::CoberturaFormatter
5
8
  end
6
9
 
7
10
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
@@ -28,3 +28,7 @@ class Whizbang < ActiveForce::SObject
28
28
  end
29
29
 
30
30
  end
31
+
32
+ class Whizbang2 < Whizbang
33
+ self.table_name = 'Whiz_bang2__c'
34
+ end
metadata CHANGED
@@ -1,44 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_force
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.24.0
4
+ version: 0.26.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eloy Espinaco
8
8
  - Pablo Oldani
9
9
  - Armando Andini
10
10
  - José Piccioni
11
- autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2024-10-01 00:00:00.000000000 Z
13
+ date: 1980-01-02 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: activemodel
18
17
  requirement: !ruby/object:Gem::Requirement
19
18
  requirements:
20
- - - "~>"
19
+ - - ">="
21
20
  - !ruby/object:Gem::Version
22
21
  version: '7.0'
23
22
  type: :runtime
24
23
  prerelease: false
25
24
  version_requirements: !ruby/object:Gem::Requirement
26
25
  requirements:
27
- - - "~>"
26
+ - - ">="
28
27
  - !ruby/object:Gem::Version
29
28
  version: '7.0'
30
29
  - !ruby/object:Gem::Dependency
31
30
  name: activesupport
32
31
  requirement: !ruby/object:Gem::Requirement
33
32
  requirements:
34
- - - "~>"
33
+ - - ">="
35
34
  - !ruby/object:Gem::Version
36
35
  version: '7.0'
37
36
  type: :runtime
38
37
  prerelease: false
39
38
  version_requirements: !ruby/object:Gem::Requirement
40
39
  requirements:
41
- - - "~>"
40
+ - - ">="
42
41
  - !ruby/object:Gem::Version
43
42
  version: '7.0'
44
43
  - !ruby/object:Gem::Dependency
@@ -125,6 +124,20 @@ dependencies:
125
124
  - - ">="
126
125
  - !ruby/object:Gem::Version
127
126
  version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: simplecov-cobertura
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
128
141
  description: Use SalesForce as an ActiveModel
129
142
  email: eloyesp@gmail.com
130
143
  executables: []
@@ -134,7 +147,6 @@ files:
134
147
  - ".circleci/config.yml"
135
148
  - ".github/ISSUE_TEMPLATE/bug_report.md"
136
149
  - ".github/ISSUE_TEMPLATE/feature_request.md"
137
- - ".github/workflows"
138
150
  - ".gitignore"
139
151
  - ".mailmap"
140
152
  - ".rspec"
@@ -160,6 +172,7 @@ files:
160
172
  - lib/active_force/bulk/job.rb
161
173
  - lib/active_force/bulk/job_result.rb
162
174
  - lib/active_force/bulk/records.rb
175
+ - lib/active_force/composite_batch_query.rb
163
176
  - lib/active_force/field.rb
164
177
  - lib/active_force/mapping.rb
165
178
  - lib/active_force/query.rb
@@ -182,6 +195,7 @@ files:
182
195
  - spec/active_force/bulk/record_spec.rb
183
196
  - spec/active_force/bulk_spec.rb
184
197
  - spec/active_force/callbacks_spec.rb
198
+ - spec/active_force/composite_batch_query_spec.rb
185
199
  - spec/active_force/field_spec.rb
186
200
  - spec/active_force/mapping_spec.rb
187
201
  - spec/active_force/query_spec.rb
@@ -205,7 +219,6 @@ metadata:
205
219
  bug_tracker_uri: https://github.com/Beyond-Finance/active_force/issues
206
220
  changelog_uri: https://github.com/Beyond-Finance/active_force/blob/main/CHANGELOG.md
207
221
  source_code_uri: https://github.com/Beyond-Finance/active_force
208
- post_install_message:
209
222
  rdoc_options: []
210
223
  require_paths:
211
224
  - lib
@@ -220,8 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
233
  - !ruby/object:Gem::Version
221
234
  version: '0'
222
235
  requirements: []
223
- rubygems_version: 3.4.10
224
- signing_key:
236
+ rubygems_version: 3.6.9
225
237
  specification_version: 4
226
238
  summary: Help you implement models persisting on Sales Force within Rails using RESTForce
227
239
  test_files:
@@ -233,6 +245,7 @@ test_files:
233
245
  - spec/active_force/bulk/record_spec.rb
234
246
  - spec/active_force/bulk_spec.rb
235
247
  - spec/active_force/callbacks_spec.rb
248
+ - spec/active_force/composite_batch_query_spec.rb
236
249
  - spec/active_force/field_spec.rb
237
250
  - spec/active_force/mapping_spec.rb
238
251
  - spec/active_force/query_spec.rb
data/.github/workflows DELETED
@@ -1,51 +0,0 @@
1
- on:
2
- pull_request:
3
- types: [opened, reopened, synchronize]
4
- pull_request_review_comment:
5
- types: [created, edited, deleted]
6
-
7
- name: Metomic Scan
8
-
9
- jobs:
10
- scan-secrets:
11
- name: Scan For Secrets
12
- runs-on: ubuntu-latest
13
- steps:
14
- - name: checkout-repo
15
- uses: actions/checkout@v3
16
- with:
17
- ref: ${{ github.event.pull_request.head.sha }}
18
-
19
- - name: authenticate-with-metomic
20
- id: authenticate
21
- continue-on-error: ${{ vars.METOMIC_FAIL_ON_CONNECTION_ERROR != 'TRUE' }}
22
- run: |
23
- curl -s --location --request GET '${{ vars.METOMIC_INTEGRATION_ENDPOINT }}/token' --header 'X-API-Key: ${{ secrets.METOMIC_API_TOKEN }}' -o .metomic_token.json
24
- echo METOMIC_ACCESS_TOKEN=$(cat .metomic_token.json | jq -r -c '.accessToken') >> $GITHUB_OUTPUT
25
- PASS=$(cat .metomic_token.json | jq -r -c '.accessToken // empty')
26
- if [ -z "$PASS" ]; then
27
- cat .metomic_token.json
28
- echo ""
29
- echo "FAIL: failed to fetch auth token from Metomic. Ensure required organisation variables / secrets are set correctly. METOMIC_INTEGRATION_ENDPOINT, METOMIC_API_TOKEN"
30
- echo "The correct values for these variables are available from the installations page of the Metomic dashboard"
31
- exit 1
32
- fi
33
-
34
- - name: checkout-metomic-action
35
- id: checkout
36
- uses: actions/checkout@v3
37
- if: ${{ steps.authenticate.outcome == 'success' }}
38
- continue-on-error: ${{ vars.METOMIC_FAIL_ON_CONNECTION_ERROR != 'TRUE' }}
39
- with:
40
- repository: metomic/metomic-github-integration-action.git
41
- path: "./.metomic"
42
- ref: "main"
43
- token: ${{ steps.authenticate.outputs.METOMIC_ACCESS_TOKEN }}
44
-
45
- - name: scan
46
- uses: ./.metomic/.github/actions/scan-secrets
47
- if: ${{ steps.authenticate.outputs.METOMIC_ACCESS_TOKEN && steps.checkout.outcome == 'success' }}
48
- with:
49
- metomic_endpoint: ${{ vars.METOMIC_INTEGRATION_ENDPOINT }}
50
- metomic_api_token: ${{ secrets.METOMIC_API_TOKEN }}
51
- head_ref: ${{ github.event.pull_request.head.sha }}