blackstack-core 1.2.29 → 1.2.30

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: 61e89c40560e966edd297c6fbce7e0099a94bce4dd88c0653f7e20feceb8234e
4
- data.tar.gz: 28543d06207cc6399371e857b0982ec7432801e5344372304165a0aaa4053660
3
+ metadata.gz: 6319585aa6afd55c363b5b7e59acc4afe407a741d22306831b3c5cef48724c76
4
+ data.tar.gz: 2d7e134595693737c9beb9cfabaf05ac502a7631a79bafbbb5b60ae03cd90512
5
5
  SHA512:
6
- metadata.gz: 8545ef59846393d06cb272b8e503847b3c11e9837933ac770c546acf724265a6e560407dea7bcbe67bccf49ec505b89463b4aab52bb83094fdeb792b517f7479
7
- data.tar.gz: 3eaac8af64b460a4cf941d3756faa219da65a75300cbe47fe1574ae4bb9426e3a5d6a2c028dcb81e940646bc4566f433ed48493cbf4665c5eee58d76b341823f
6
+ metadata.gz: f6d4de6e017a5871b60a1d1f3a987e9233ac2df83700ba3d794ddf843f5ffd3ec30de9efd4544eb4415e4f9381898826dd80647d8250c89d6d0f3001c38355ed
7
+ data.tar.gz: 3e8c922cb98658ef9677b4e5badb5e4592f112b71d6a76d79ac59361f19cfbb0ad94558bbaea5a6ad99493a876eda33f224ccdde11e0cebc4d4e09716a70c0a7
File without changes
File without changes
File without changes
File without changes
File without changes
data/lib/extend_fixnum.rb CHANGED
File without changes
data/lib/extend_float.rb CHANGED
File without changes
data/lib/extend_string.rb CHANGED
File without changes
data/lib/extend_time.rb CHANGED
File without changes
data/lib/functions.rb CHANGED
@@ -862,6 +862,10 @@ module BlackStack
862
862
  DEFAULT_SSL_VERIFY_MODE = OpenSSL::SSL::VERIFY_NONE
863
863
  SUCCESS = 'success'
864
864
 
865
+ DEFAULT_OPEN_TIMEOUT = 10 # seconds to wait for the initial connection
866
+ DEFAULT_READ_TIMEOUT = 30 # seconds to wait for each response
867
+ DEFAULT_RETRY_ATTEMPTS = 3
868
+
865
869
  @@lockfiles = []
866
870
 
867
871
  @@max_api_call_channels = 0 # 0 means infinite
@@ -927,32 +931,83 @@ module BlackStack
927
931
  #
928
932
  # TODO: parameter support_redirections has been deprecated.
929
933
  #
930
- def self.call_post(url, body = {}, ssl_verify_mode=BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, support_redirections=true)
931
- # issue: https://github.com/leandrosardi/mysaas/issues/59
932
- #
933
- # when ruby pushes hash of hashes (or hash of arrays), all values are converted into strings.
934
- # and arrays are mapped to the last element only.
935
- #
936
- # the solution is to convert each element of the hash into a string using `.to_json` method.
937
- #
938
- # references:
939
- # - https://stackoverflow.com/questions/1667630/how-do-i-convert-a-string-object-into-a-hash-object
940
- # - https://stackoverflow.com/questions/67572866/how-to-build-complex-json-to-post-to-a-web-service-with-rails-5-2-and-faraday-ge
941
- #
942
- # iterate the keys of the hash
943
- #
944
- params = {} # not needed for post calls to access points
945
- path = URI::parse(url).path
946
- domain = url.gsub(/#{Regexp.escape(path)}/, '')
947
-
948
- conn = Faraday.new(domain, :ssl=>{:verify=>ssl_verify_mode!=OpenSSL::SSL::VERIFY_NONE})
949
- ret = conn.post(path, params) do |req|
950
- req.body = body.to_json
951
- req.headers['Content-Type'] = 'application/json'
952
- req.headers['Accept'] = 'application/json'
934
+ def self.call_post(url,
935
+ body = {},
936
+ ssl_verify_mode = BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE,
937
+ support_redirections = true)
938
+
939
+ max_redirects = 5
940
+ attempts = 0
941
+
942
+ while attempts < DEFAULT_RETRY_ATTEMPTS
943
+ begin
944
+ uri = URI.parse(url)
945
+
946
+ # Create a basic Faraday connection
947
+ conn = Faraday.new(
948
+ url: "#{uri.scheme}://#{uri.host}",
949
+ ssl: { verify: ssl_verify_mode != OpenSSL::SSL::VERIFY_NONE },
950
+ request: {
951
+ open_timeout: DEFAULT_OPEN_TIMEOUT,
952
+ timeout: DEFAULT_READ_TIMEOUT
953
+ }
954
+ ) do |f|
955
+ f.adapter Faraday.default_adapter
956
+ end
957
+
958
+ # Perform the initial POST request
959
+ response = conn.post(uri.path) do |req|
960
+ req.body = JSON.generate(body) # Manually serialize to JSON
961
+ req.headers['Content-Type'] = 'application/json'
962
+ req.headers['Accept'] = 'application/json'
963
+ end
964
+
965
+ # Manually handle HTTP redirects if requested
966
+ redirect_count = 0
967
+ while support_redirections &&
968
+ response.status.between?(300, 399) &&
969
+ response.headers['location'] &&
970
+ redirect_count < max_redirects
971
+
972
+ redirect_count += 1
973
+ new_url = URI.join(url, response.headers['location']).to_s
974
+
975
+ # Update `url` for the next iteration
976
+ url = new_url
977
+ uri = URI.parse(new_url)
978
+
979
+ response = conn.post(uri.path) do |req|
980
+ req.body = JSON.generate(body)
981
+ req.headers['Content-Type'] = 'application/json'
982
+ req.headers['Accept'] = 'application/json'
983
+ end
984
+ end
985
+
986
+ # Raise an error if the final response is not 2xx
987
+ unless response.success?
988
+ raise "HTTP #{response.status}: #{response.body}"
989
+ end
990
+
991
+ # If all is good, return the Faraday response object
992
+ return response
993
+
994
+ rescue Errno::ETIMEDOUT, Timeout::Error, Faraday::ConnectionFailed => e
995
+ # Basic retry logic for transient network errors
996
+ attempts += 1
997
+ if attempts < DEFAULT_RETRY_ATTEMPTS
998
+ sleep_time = 2**attempts
999
+ sleep(sleep_time) # Exponential backoff
1000
+ retry
1001
+ else
1002
+ # Too many failures, re-raise
1003
+ raise e
1004
+ end
1005
+ rescue => e
1006
+ # For any other error, just re-raise
1007
+ raise e
1008
+ end
953
1009
  end
954
- ret
955
- end
1010
+ end # def self.call_post
956
1011
 
957
1012
  # TODO: deprecated
958
1013
  def self.api_call(url, params={}, method=BlackStack::Netting::CALL_METHOD_POST, ssl_verify_mode=BlackStack::Netting::DEFAULT_SSL_VERIFY_MODE, max_retries=5)
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blackstack-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.29
4
+ version: 1.2.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Daniel Sardi
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-01-13 00:00:00.000000000 Z
10
+ date: 2025-01-30 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: content_spinning
@@ -86,7 +85,6 @@ homepage: https://rubygems.org/gems/blackstack-core
86
85
  licenses:
87
86
  - MIT
88
87
  metadata: {}
89
- post_install_message:
90
88
  rdoc_options: []
91
89
  require_paths:
92
90
  - lib
@@ -101,8 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
99
  - !ruby/object:Gem::Version
102
100
  version: '0'
103
101
  requirements: []
104
- rubygems_version: 3.3.7
105
- signing_key:
102
+ rubygems_version: 3.6.3
106
103
  specification_version: 4
107
104
  summary: Core modules, functions and constants for the BlackStack framework.
108
105
  test_files: []