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
-
#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
-
#list_all ⇒ Object
Walk every page of
list_configsso an account with more thanRUNTIME_PAGE_SIZEconfigs still resolves to the complete set. - #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
540 541 542 543 |
# File 'lib/smplkit/management/client.rb', line 540 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
545 546 547 548 |
# File 'lib/smplkit/management/client.rb', line 545 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
525 526 527 528 |
# File 'lib/smplkit/management/client.rb', line 525 def delete(key) ErrorMapping.call { @api.delete_config(key) } true 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.
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 |
# File 'lib/smplkit/management/client.rb', line 488 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
520 521 522 523 |
# File 'lib/smplkit/management/client.rb', line 520 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
512 513 514 515 516 517 518 |
# File 'lib/smplkit/management/client.rb', line 512 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 |
#list_all ⇒ Object
Walk every page of list_configs so an account with more than RUNTIME_PAGE_SIZE configs still resolves to the complete set. Used by the runtime client to refresh the resolved cache.
553 554 555 556 |
# File 'lib/smplkit/management/client.rb', line 553 def list_all rows = PaginatedFetch.collect { |opts| @api.list_configs(opts) } rows.map { |r| Smplkit::Config::Helpers.config_from_json(self, ResourceShim.from_model(r)) } end |
#new_config(key, name: nil, description: nil, parent: nil) ⇒ Object
530 531 532 533 534 535 536 537 538 |
# File 'lib/smplkit/management/client.rb', line 530 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
481 482 483 |
# File 'lib/smplkit/management/client.rb', line 481 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 from ConfigClient#bind and ConfigClient#get(id, key, default). Threshold-flushes on a background thread once the pending buffer reaches the flush size.
467 468 469 470 471 472 |
# File 'lib/smplkit/management/client.rb', line 467 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.
476 477 478 479 |
# File 'lib/smplkit/management/client.rb', line 476 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 |