smplkit 3.0.95 → 3.0.97

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.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/smplkit/account/client.rb +128 -0
  3. data/lib/smplkit/account/models.rb +71 -0
  4. data/lib/smplkit/api_support.rb +91 -0
  5. data/lib/smplkit/audit/buffer.rb +3 -1
  6. data/lib/smplkit/audit/categories.rb +21 -10
  7. data/lib/smplkit/audit/client.rb +18 -9
  8. data/lib/smplkit/audit/event_types.rb +26 -10
  9. data/lib/smplkit/audit/events.rb +93 -17
  10. data/lib/smplkit/{management/audit.rb → audit/forwarders.rb} +93 -85
  11. data/lib/smplkit/audit/models.rb +86 -32
  12. data/lib/smplkit/audit/resource_types.rb +21 -9
  13. data/lib/smplkit/buffers.rb +250 -0
  14. data/lib/smplkit/client.rb +161 -70
  15. data/lib/smplkit/config/client.rb +874 -186
  16. data/lib/smplkit/config/helpers.rb +44 -6
  17. data/lib/smplkit/config/models.rb +114 -7
  18. data/lib/smplkit/config_resolution.rb +17 -9
  19. data/lib/smplkit/errors.rb +14 -3
  20. data/lib/smplkit/flags/client.rb +602 -116
  21. data/lib/smplkit/flags/models.rb +110 -8
  22. data/lib/smplkit/flags/types.rb +8 -9
  23. data/lib/smplkit/jobs/client.rb +306 -0
  24. data/lib/smplkit/jobs/models.rb +47 -18
  25. data/lib/smplkit/logging/client.rb +755 -191
  26. data/lib/smplkit/logging/helpers.rb +5 -1
  27. data/lib/smplkit/logging/levels.rb +3 -1
  28. data/lib/smplkit/logging/models.rb +163 -6
  29. data/lib/smplkit/logging/normalize.rb +3 -1
  30. data/lib/smplkit/logging/resolution.rb +4 -4
  31. data/lib/smplkit/logging/sources.rb +1 -1
  32. data/lib/smplkit/platform/client.rb +597 -0
  33. data/lib/smplkit/platform/models.rb +282 -0
  34. data/lib/smplkit/{management → platform}/types.rb +21 -4
  35. data/lib/smplkit/transport.rb +103 -0
  36. data/lib/smplkit/ws.rb +1 -1
  37. data/lib/smplkit.rb +18 -6
  38. metadata +11 -7
  39. data/lib/smplkit/management/buffer.rb +0 -198
  40. data/lib/smplkit/management/client.rb +0 -1074
  41. data/lib/smplkit/management/jobs.rb +0 -226
  42. data/lib/smplkit/management/models.rb +0 -178
@@ -1,226 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Smplkit
4
- module Management
5
- # Smpl Jobs management surface — accessed via +mgmt.jobs+.
6
- #
7
- # Unlike Config/Flags/Logging, Jobs has no live "phone-home" agent — no
8
- # environment registration, no WebSocket — so its entire surface lives on
9
- # the management client. Defining a job, triggering a run, and reading run
10
- # history are all plain request/response calls here:
11
- #
12
- # mgmt.jobs.{new,get,list,delete,run,usage}
13
- # mgmt.jobs.runs.{list,get,cancel,rerun}
14
- # Job#{save,delete}
15
- #
16
- # The active-record entry point is {#new}: instantiate a draft, mutate
17
- # fields, then call {Smplkit::Jobs::Job#save}. Run history and the
18
- # cancel / rerun run actions live on {#runs}.
19
- class JobsNamespace
20
- # @return [RunsNamespace] Run history and run actions (+mgmt.jobs.runs+).
21
- attr_reader :runs
22
-
23
- def initialize(api_client)
24
- @api = SmplkitGeneratedClient::Jobs::JobsApi.new(api_client)
25
- @runs = RunsNamespace.new(
26
- SmplkitGeneratedClient::Jobs::RunsApi.new(api_client)
27
- )
28
- @usage_api = SmplkitGeneratedClient::Jobs::UsageApi.new(api_client)
29
- end
30
-
31
- # Construct an unsaved {Smplkit::Jobs::Job} bound to this namespace. Call
32
- # +#save+ on the returned instance to create it.
33
- #
34
- # @param id [String] Caller-supplied unique identifier for the job.
35
- # Unique within the account and immutable; the service returns 409 if
36
- # another live job already uses this id.
37
- # @param name [String] Human-readable name for the job.
38
- # @param schedule [String] An ISO-8601 datetime, a 5-field UTC cron
39
- # expression, or the literal +"now"+.
40
- # @param configuration [Smplkit::Jobs::HttpConfig] The HTTP request the
41
- # job performs.
42
- # @param description [String, nil] Optional free-text description.
43
- # @param enabled [Boolean] Whether the job schedules runs. Defaults +true+.
44
- # @param concurrency_policy [String] How overlapping runs are handled.
45
- # Defaults to +"ALLOW"+.
46
- # @return [Smplkit::Jobs::Job]
47
- def new(id, name:, schedule:, configuration:, description: nil,
48
- enabled: true, concurrency_policy: "ALLOW")
49
- Smplkit::Jobs::Job.new(
50
- self,
51
- id: id,
52
- name: name,
53
- schedule: schedule,
54
- configuration: configuration,
55
- description: description,
56
- enabled: enabled,
57
- concurrency_policy: concurrency_policy
58
- )
59
- end
60
-
61
- # List jobs for the authenticated account.
62
- #
63
- # @param enabled [Boolean, nil] Filter to jobs matching this enabled state.
64
- # @param page_number [Integer, nil] 1-based page number to return.
65
- # @param page_size [Integer, nil] Items per page.
66
- # @return [Array<Smplkit::Jobs::Job>]
67
- def list(enabled: nil, page_number: nil, page_size: nil)
68
- opts = {}
69
- opts[:filter_enabled] = enabled unless enabled.nil?
70
- opts[:page_number] = page_number unless page_number.nil?
71
- opts[:page_size] = page_size unless page_size.nil?
72
-
73
- resp = Smplkit::Jobs.call_api { @api.list_jobs(opts) }
74
- (resp.data || []).map { |r| Smplkit::Jobs::Job.from_resource(r, client: self) }
75
- end
76
-
77
- # Fetch a single job by id. The returned instance is bound to this
78
- # namespace, so +job.save+ and +job.delete+ work.
79
- #
80
- # @param id [String]
81
- # @return [Smplkit::Jobs::Job]
82
- def get(id)
83
- resp = Smplkit::Jobs.call_api { @api.get_job(id) }
84
- Smplkit::Jobs::Job.from_resource(resp.data, client: self)
85
- end
86
-
87
- # Soft-delete a job.
88
- #
89
- # @param id [String]
90
- # @return [nil]
91
- def delete(id)
92
- Smplkit::Jobs.call_api { @api.delete_job(id) }
93
- nil
94
- end
95
-
96
- # Trigger one immediate +MANUAL+ run of the job.
97
- #
98
- # @param id [String]
99
- # @return [Smplkit::Jobs::Run]
100
- def run(id)
101
- resp = Smplkit::Jobs.call_api { @api.run_job_now(id) }
102
- Smplkit::Jobs::Run.from_resource(resp.data)
103
- end
104
-
105
- # Current-period usage counters for the account.
106
- #
107
- # @return [Smplkit::Jobs::Usage]
108
- def usage
109
- resp = Smplkit::Jobs.call_api { @usage_api.get_usage }
110
- Smplkit::Jobs::Usage.from_resource(resp.data)
111
- end
112
-
113
- # @api private — POST a new job. Called by {Smplkit::Jobs::Job#save} on
114
- # unsaved instances. The jobs service requires a caller-supplied
115
- # +data.id+ on create and 409s on conflict.
116
- def _create_job(job)
117
- raise ArgumentError, "Job.id is required on create (caller-supplied key)" if job.id.nil? || job.id.empty?
118
-
119
- resp = Smplkit::Jobs.call_api { @api.create_job(build_create_body(job)) }
120
- Smplkit::Jobs::Job.from_resource(resp.data, client: self)
121
- end
122
-
123
- # @api private — Full-replace PUT for an existing job. Called by
124
- # {Smplkit::Jobs::Job#save} on instances with +created_at+.
125
- #
126
- # Header values must be re-supplied as plaintext; the GET path redacts
127
- # them, so a PUT body containing the redacted placeholder would persist
128
- # that literal. Track real header values client-side and round-trip them.
129
- def _update_job(job)
130
- raise ArgumentError, "cannot update a Job with no id" if job.id.nil?
131
-
132
- resp = Smplkit::Jobs.call_api { @api.update_job(job.id, build_body(job)) }
133
- Smplkit::Jobs::Job.from_resource(resp.data, client: self)
134
- end
135
-
136
- private
137
-
138
- def build_attrs(job)
139
- SmplkitGeneratedClient::Jobs::Job.new(
140
- name: job.name,
141
- description: job.description,
142
- enabled: job.enabled,
143
- type: job.type,
144
- schedule: job.schedule,
145
- configuration: Smplkit::Jobs::HttpConfig.to_wire(job.configuration),
146
- concurrency_policy: job.concurrency_policy
147
- )
148
- end
149
-
150
- def build_create_body(job)
151
- # Create uses the distinct JobCreateRequest envelope; the jobs service
152
- # requires data.id (the caller-supplied key) on create and 409s on
153
- # conflict.
154
- resource = SmplkitGeneratedClient::Jobs::JobCreateResource.new(
155
- id: job.id.to_s,
156
- type: "job",
157
- attributes: build_attrs(job)
158
- )
159
- SmplkitGeneratedClient::Jobs::JobCreateRequest.new(data: resource)
160
- end
161
-
162
- def build_body(job)
163
- # Update path uses the generic JobRequest envelope.
164
- resource = SmplkitGeneratedClient::Jobs::JobResource.new(
165
- id: job.id.to_s,
166
- type: "job",
167
- attributes: build_attrs(job)
168
- )
169
- SmplkitGeneratedClient::Jobs::JobRequest.new(data: resource)
170
- end
171
- end
172
-
173
- # +mgmt.jobs.runs.*+ — read-only run history plus the cancel / rerun run
174
- # actions.
175
- class RunsNamespace
176
- def initialize(api)
177
- @api = api
178
- end
179
-
180
- # List runs for the authenticated account, newest first. Cursor
181
- # paginated (ADR-014): pass +page_size+ and the +after+ cursor from the
182
- # prior page. Pass +job+ to scope to a single job's history.
183
- #
184
- # @param job [String, nil] Filter to a single job's run history, by job id.
185
- # @param page_size [Integer, nil] Items per page (cursor pagination).
186
- # @param after [String, nil] Opaque cursor token from a prior page.
187
- # @return [Array<Smplkit::Jobs::Run>]
188
- def list(job: nil, page_size: nil, after: nil)
189
- opts = {}
190
- opts[:filter_job] = job unless job.nil?
191
- opts[:page_size] = page_size unless page_size.nil?
192
- opts[:page_after] = after unless after.nil?
193
-
194
- resp = Smplkit::Jobs.call_api { @api.list_runs(opts) }
195
- (resp.data || []).map { |r| Smplkit::Jobs::Run.from_resource(r) }
196
- end
197
-
198
- # Fetch a single run by id.
199
- #
200
- # @param run_id [String]
201
- # @return [Smplkit::Jobs::Run]
202
- def get(run_id)
203
- resp = Smplkit::Jobs.call_api { @api.get_run(run_id) }
204
- Smplkit::Jobs::Run.from_resource(resp.data)
205
- end
206
-
207
- # Cancel a pending run.
208
- #
209
- # @param run_id [String]
210
- # @return [Smplkit::Jobs::Run]
211
- def cancel(run_id)
212
- resp = Smplkit::Jobs.call_api { @api.cancel_run(run_id) }
213
- Smplkit::Jobs::Run.from_resource(resp.data)
214
- end
215
-
216
- # Re-run a prior run, spawning a new +RERUN+ run.
217
- #
218
- # @param run_id [String]
219
- # @return [Smplkit::Jobs::Run]
220
- def rerun(run_id)
221
- resp = Smplkit::Jobs.call_api { @api.rerun_run(run_id) }
222
- Smplkit::Jobs::Run.from_resource(resp.data)
223
- end
224
- end
225
- end
226
- end
@@ -1,178 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Smplkit
4
- module Management
5
- # An environment resource — a customer-defined deploy target (production,
6
- # staging, etc.) for which configs and flags can have overrides.
7
- class Environment
8
- attr_accessor :id, :key, :name, :color, :classification, :description, :created_at, :updated_at
9
-
10
- def initialize(client = nil, key:, id: nil, name: nil, color: nil,
11
- classification: EnvironmentClassification::STANDARD,
12
- description: nil, created_at: nil, updated_at: nil)
13
- @client = client
14
- @id = id
15
- @key = key
16
- @name = name
17
- @color = color
18
- @classification = classification
19
- @description = description
20
- @created_at = created_at
21
- @updated_at = updated_at
22
- end
23
-
24
- def save
25
- raise "Environment was constructed without a client; cannot save" if @client.nil?
26
-
27
- updated =
28
- if @created_at.nil?
29
- @client._create_environment(self)
30
- else
31
- @client._update_environment(self)
32
- end
33
- _apply(updated)
34
- self
35
- end
36
- alias save! save
37
-
38
- def delete
39
- raise "Environment was constructed without a client; cannot delete" if @client.nil?
40
-
41
- @client.delete(@key)
42
- end
43
- alias delete! delete
44
-
45
- def _apply(other)
46
- @id = other.id
47
- @key = other.key
48
- @name = other.name
49
- @color = other.color
50
- @classification = other.classification
51
- @description = other.description
52
- @created_at = other.created_at
53
- @updated_at = other.updated_at
54
- end
55
- end
56
-
57
- # A context type resource (e.g. "user", "account").
58
- class ContextType
59
- attr_accessor :id, :key, :name, :description, :created_at, :updated_at
60
-
61
- def initialize(client = nil, key:, id: nil, name: nil, description: nil,
62
- created_at: nil, updated_at: nil)
63
- @client = client
64
- @id = id
65
- @key = key
66
- @name = name
67
- @description = description
68
- @created_at = created_at
69
- @updated_at = updated_at
70
- end
71
-
72
- def save
73
- raise "ContextType was constructed without a client; cannot save" if @client.nil?
74
-
75
- updated =
76
- if @created_at.nil?
77
- @client._create_context_type(self)
78
- else
79
- @client._update_context_type(self)
80
- end
81
- _apply(updated)
82
- self
83
- end
84
- alias save! save
85
-
86
- def delete
87
- raise "ContextType was constructed without a client; cannot delete" if @client.nil?
88
-
89
- @client.delete(@key)
90
- end
91
- alias delete! delete
92
-
93
- def _apply(other)
94
- @id = other.id
95
- @key = other.key
96
- @name = other.name
97
- @description = other.description
98
- @created_at = other.created_at
99
- @updated_at = other.updated_at
100
- end
101
- end
102
-
103
- # A service resource — a backend application or microservice in the
104
- # customer's stack that contexts can be evaluated against.
105
- class Service
106
- attr_accessor :id, :key, :name, :created_at, :updated_at
107
-
108
- def initialize(client = nil, key:, id: nil, name: nil,
109
- created_at: nil, updated_at: nil)
110
- @client = client
111
- @id = id
112
- @key = key
113
- @name = name
114
- @created_at = created_at
115
- @updated_at = updated_at
116
- end
117
-
118
- def save
119
- raise "Service was constructed without a client; cannot save" if @client.nil?
120
-
121
- updated =
122
- if @created_at.nil?
123
- @client._create_service(self)
124
- else
125
- @client._update_service(self)
126
- end
127
- _apply(updated)
128
- self
129
- end
130
- alias save! save
131
-
132
- def delete
133
- raise "Service was constructed without a client; cannot delete" if @client.nil?
134
-
135
- @client.delete(@key)
136
- end
137
- alias delete! delete
138
-
139
- def _apply(other)
140
- @id = other.id
141
- @key = other.key
142
- @name = other.name
143
- @created_at = other.created_at
144
- @updated_at = other.updated_at
145
- end
146
- end
147
-
148
- # An account-wide settings resource.
149
- class AccountSettings
150
- attr_accessor :id, :environment_order, :default_environment, :updated_at
151
-
152
- def initialize(client = nil, id: nil, environment_order: nil,
153
- default_environment: nil, updated_at: nil)
154
- @client = client
155
- @id = id
156
- @environment_order = environment_order || []
157
- @default_environment = default_environment
158
- @updated_at = updated_at
159
- end
160
-
161
- def save
162
- raise "AccountSettings was constructed without a client; cannot save" if @client.nil?
163
-
164
- updated = @client._update_account_settings(self)
165
- _apply(updated)
166
- self
167
- end
168
- alias save! save
169
-
170
- def _apply(other)
171
- @id = other.id
172
- @environment_order = other.environment_order
173
- @default_environment = other.default_environment
174
- @updated_at = other.updated_at
175
- end
176
- end
177
- end
178
- end