regolith 0.1.6 → 0.1.7
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/regolith/cli.rb +882 -232
- data/lib/regolith/service_client.rb +82 -26
- data/lib/regolith/version.rb +1 -1
- metadata +2 -2
@@ -1,32 +1,66 @@
|
|
1
|
-
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
require 'ostruct'
|
5
|
+
|
2
6
|
module Regolith
|
3
7
|
class ServiceClient
|
4
8
|
class << self
|
5
|
-
def get(service_name, path)
|
6
|
-
make_request(service_name, :get, path)
|
9
|
+
def get(service_name, path, params = nil)
|
10
|
+
make_request(service_name, :get, path, nil, params)
|
11
|
+
end
|
12
|
+
|
13
|
+
def post(service_name, path, body = nil, params = nil)
|
14
|
+
make_request(service_name, :post, path, body, params)
|
7
15
|
end
|
8
16
|
|
9
|
-
def
|
10
|
-
make_request(service_name, :
|
17
|
+
def put(service_name, path, body = nil, params = nil)
|
18
|
+
make_request(service_name, :put, path, body, params)
|
11
19
|
end
|
12
20
|
|
13
|
-
def
|
14
|
-
make_request(service_name, :
|
21
|
+
def delete(service_name, path, params = nil)
|
22
|
+
make_request(service_name, :delete, path, nil, params)
|
15
23
|
end
|
16
24
|
|
17
|
-
def
|
18
|
-
|
25
|
+
def health(service_name)
|
26
|
+
get(service_name, 'health')
|
27
|
+
end
|
28
|
+
|
29
|
+
def parsed_body(response)
|
30
|
+
JSON.parse(response.body) rescue {}
|
19
31
|
end
|
20
32
|
|
21
33
|
private
|
22
34
|
|
23
|
-
def make_request(service_name, method, path, body = nil)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
35
|
+
def make_request(service_name, method, path, body = nil, params = nil)
|
36
|
+
with_retries do
|
37
|
+
service_config = Regolith.service_registry[service_name.to_s]
|
38
|
+
|
39
|
+
unless service_config
|
40
|
+
raise "Service '#{service_name}' not found in registry"
|
41
|
+
end
|
42
|
+
|
43
|
+
uri = build_uri(service_name, path, params, service_config)
|
44
|
+
|
45
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
46
|
+
http.read_timeout = Regolith.configuration.timeout
|
47
|
+
http.open_timeout = Regolith.configuration.timeout
|
48
|
+
|
49
|
+
request = build_request(method, uri, body)
|
50
|
+
|
51
|
+
begin
|
52
|
+
http.request(request)
|
53
|
+
rescue => e
|
54
|
+
# Return a mock response for connection errors
|
55
|
+
OpenStruct.new(
|
56
|
+
code: 500,
|
57
|
+
body: { error: e.message, service: service_name }.to_json
|
58
|
+
)
|
59
|
+
end
|
28
60
|
end
|
61
|
+
end
|
29
62
|
|
63
|
+
def build_uri(service_name, path, params, service_config)
|
30
64
|
# In Docker Compose, services can be reached by service name
|
31
65
|
# In development, use localhost with the mapped port
|
32
66
|
host = in_docker? ? service_name.to_s : 'localhost'
|
@@ -34,34 +68,56 @@ module Regolith
|
|
34
68
|
|
35
69
|
uri = URI("http://#{host}:#{port}/#{path}")
|
36
70
|
|
37
|
-
|
38
|
-
|
71
|
+
# Add query parameters if provided
|
72
|
+
if params && !params.empty?
|
73
|
+
query_params = params.map { |k, v| "#{URI.encode_www_form_component(k)}=#{URI.encode_www_form_component(v)}" }
|
74
|
+
uri.query = query_params.join('&')
|
75
|
+
end
|
39
76
|
|
77
|
+
uri
|
78
|
+
end
|
79
|
+
|
80
|
+
def build_request(method, uri, body)
|
40
81
|
case method
|
41
82
|
when :get
|
42
|
-
|
83
|
+
Net::HTTP::Get.new(uri)
|
43
84
|
when :post
|
44
85
|
request = Net::HTTP::Post.new(uri)
|
45
|
-
|
46
|
-
|
86
|
+
if body
|
87
|
+
request.body = body
|
88
|
+
request['Content-Type'] = 'application/json'
|
89
|
+
end
|
90
|
+
request
|
47
91
|
when :put
|
48
92
|
request = Net::HTTP::Put.new(uri)
|
49
|
-
|
50
|
-
|
93
|
+
if body
|
94
|
+
request.body = body
|
95
|
+
request['Content-Type'] = 'application/json'
|
96
|
+
end
|
97
|
+
request
|
51
98
|
when :delete
|
52
|
-
|
99
|
+
Net::HTTP::Delete.new(uri)
|
53
100
|
end
|
101
|
+
end
|
54
102
|
|
103
|
+
def with_retries(max_retries: 2, base_delay: 0.1)
|
104
|
+
attempt = 0
|
55
105
|
begin
|
56
|
-
|
106
|
+
attempt += 1
|
107
|
+
yield
|
57
108
|
rescue => e
|
58
|
-
|
59
|
-
|
109
|
+
if attempt <= max_retries
|
110
|
+
delay = base_delay * (2 ** (attempt - 1)) # Exponential backoff
|
111
|
+
sleep(delay)
|
112
|
+
retry
|
113
|
+
else
|
114
|
+
raise e
|
115
|
+
end
|
60
116
|
end
|
61
117
|
end
|
62
118
|
|
63
119
|
def in_docker?
|
64
|
-
File.exist?('/.dockerenv') || ENV['REGOLITH_SERVICE_NAME']
|
120
|
+
File.exist?('/.dockerenv') || ENV['REGOLITH_SERVICE_NAME']
|
65
121
|
end
|
66
122
|
end
|
67
123
|
end
|
data/lib/regolith/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: regolith
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Regolith Team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-08-
|
11
|
+
date: 2025-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|