Class: Smplkit::ManagementClient::ConfigNamespace
- Inherits:
-
Object
- Object
- Smplkit::ManagementClient::ConfigNamespace
- Defined in:
- lib/smplkit/management/client.rb
Instance Method Summary collapse
- #_create_config(config) ⇒ Object
- #_update_config(config) ⇒ Object
- #delete(key) ⇒ Object
-
#fetch_chain(target_key) ⇒ Object
Build the parent-chain for a given config, walking
parent_idpointers across the full config list. -
#flush ⇒ Object
Send any pending config declarations to POST /api/v1/configs/bulk.
- #get(key) ⇒ Object
-
#initialize(api_client) ⇒ ConfigNamespace
constructor
A new instance of ConfigNamespace.
- #list(page_number: nil, page_size: nil) ⇒ Object
- #new_config(key, name: nil, description: nil, parent: nil) ⇒ Object
- #pending_count ⇒ Object
-
#register_config(config_id, service:, environment:, parent: nil, name: nil, description: nil) ⇒ Object
Queue a configuration declaration for bulk-discovery upload.
-
#register_config_item(config_id, item_key, item_type, default, description = nil) ⇒ Object
Queue a config item declaration.
Constructor Details
#initialize(api_client) ⇒ ConfigNamespace
Returns a new instance of ConfigNamespace.
454 455 456 457 |
# File 'lib/smplkit/management/client.rb', line 454 def initialize(api_client) @api = SmplkitGeneratedClient::Config::ConfigsApi.new(api_client) @buffer = Management::ConfigRegistrationBuffer.new end |
Instance Method Details
#_create_config(config) ⇒ Object
539 540 541 542 |
# File 'lib/smplkit/management/client.rb', line 539 def _create_config(config) response = ErrorMapping.call { @api.create_config(config_body(config)) } Smplkit::Config::Helpers.config_from_json(self, ResourceShim.from_model(response.data)) end |
#_update_config(config) ⇒ Object
544 545 546 547 |
# File 'lib/smplkit/management/client.rb', line 544 def _update_config(config) response = ErrorMapping.call { @api.update_config(config.key, config_body(config)) } Smplkit::Config::Helpers.config_from_json(self, ResourceShim.from_model(response.data)) end |
#delete(key) ⇒ Object
524 525 526 527 |
# File 'lib/smplkit/management/client.rb', line 524 def delete(key) ErrorMapping.call { @api.delete_config(key) } true end |
#fetch_chain(target_key) ⇒ Object
Build the parent-chain for a given config, walking parent_id pointers across the full config list. Mirrors the Python SDK’s client-side resolution — there is no server /chain endpoint.
Walks every page of list_configs so an account with more than RUNTIME_PAGE_SIZE configs still resolves chains correctly.
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 |
# File 'lib/smplkit/management/client.rb', line 555 def fetch_chain(target_key) all_configs = fetch_all_configs by_key = all_configs.to_h { |c| [c.key, c] } by_id = all_configs.to_h { |c| [c.id, c] } current = by_key[target_key] return [] unless current chain = [] loop do chain << config_to_chain_entry(current) parent_id = current.parent_id break if parent_id.nil? || parent_id == "" parent = by_id[parent_id] break unless parent current = parent end chain end |
#flush ⇒ Object
Send any pending config declarations to POST /api/v1/configs/bulk. Per ADR-024 §2.9 the bulk endpoint is plan-limit-exempt; failures here never propagate to customer code.
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/smplkit/management/client.rb', line 487 def flush batch = @buffer.drain return if batch.empty? items = batch.map do |entry| SmplkitGeneratedClient::Config::ConfigBulkItem.new( id: entry["id"], service: entry["service"], environment: entry["environment"], parent: entry["parent"], name: entry["name"], description: entry["description"], items: bulk_items_to_wire(entry["items"]) ) end body = SmplkitGeneratedClient::Config::ConfigBulkRequest.new(configs: items) begin ErrorMapping.call { @api.bulk_register_configs(body) } rescue StandardError => e # Fire-and-forget per ADR-024 §2.9. Smplkit.debug("registration", "config bulk register failed: #{e.class}: #{e.}") end end |
#get(key) ⇒ Object
519 520 521 522 |
# File 'lib/smplkit/management/client.rb', line 519 def get(key) response = ErrorMapping.call { @api.get_config(key) } Smplkit::Config::Helpers.config_from_json(self, ResourceShim.from_model(response.data)) end |
#list(page_number: nil, page_size: nil) ⇒ Object
511 512 513 514 515 516 517 |
# File 'lib/smplkit/management/client.rb', line 511 def list(page_number: nil, page_size: nil) opts = {} opts[:page_number] = page_number unless page_number.nil? opts[:page_size] = page_size unless page_size.nil? response = ErrorMapping.call { @api.list_configs(opts) } (response.data || []).map { |r| Smplkit::Config::Helpers.config_from_json(self, ResourceShim.from_model(r)) } end |
#new_config(key, name: nil, description: nil, parent: nil) ⇒ Object
529 530 531 532 533 534 535 536 537 |
# File 'lib/smplkit/management/client.rb', line 529 def new_config(key, name: nil, description: nil, parent: nil) Smplkit::Config::Config.new( self, key: key, name: name || Smplkit::Helpers.key_to_display_name(key), description: description, parent_id: parent.is_a?(Smplkit::Config::Config) ? parent.key : parent ) end |
#pending_count ⇒ Object
480 481 482 |
# File 'lib/smplkit/management/client.rb', line 480 def pending_count @buffer.pending_count end |
#register_config(config_id, service:, environment:, parent: nil, name: nil, description: nil) ⇒ Object
Queue a configuration declaration for bulk-discovery upload. Called by ConfigClient#get_or_create. Threshold-flushes on a background thread once the pending buffer reaches the flush size.
466 467 468 469 470 471 |
# File 'lib/smplkit/management/client.rb', line 466 def register_config(config_id, service:, environment:, parent: nil, name: nil, description: nil) @buffer.declare(config_id, service: service, environment: environment, parent: parent, name: name, description: description) trigger_background_flush_if_needed end |
#register_config_item(config_id, item_key, item_type, default, description = nil) ⇒ Object
Queue a config item declaration. register_config must have run first; items added without a prior declaration are dropped.
475 476 477 478 |
# File 'lib/smplkit/management/client.rb', line 475 def register_config_item(config_id, item_key, item_type, default, description = nil) @buffer.add_item(config_id, item_key, item_type, default, description) trigger_background_flush_if_needed end |