Class: Smplkit::ManagementClient::ConfigNamespace

Inherits:
Object
  • Object
show all
Defined in:
lib/smplkit/management/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_client) ⇒ ConfigNamespace

Returns a new instance of ConfigNamespace.



537
538
539
540
# File 'lib/smplkit/management/client.rb', line 537

def initialize(api_client)
  @api = SmplkitGeneratedClient::Config::ConfigsApi.new(api_client)
  @buffer = Management::ConfigRegistrationBuffer.new
end

Instance Method Details

#_create_config(config) ⇒ Object



623
624
625
626
# File 'lib/smplkit/management/client.rb', line 623

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



628
629
630
631
# File 'lib/smplkit/management/client.rb', line 628

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



608
609
610
611
# File 'lib/smplkit/management/client.rb', line 608

def delete(key)
  ErrorMapping.call { @api.delete_config(key) }
  true
end

#flushObject

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.



571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
# File 'lib/smplkit/management/client.rb', line 571

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.message}")
  end
end

#get(key) ⇒ Object



603
604
605
606
# File 'lib/smplkit/management/client.rb', line 603

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



595
596
597
598
599
600
601
# File 'lib/smplkit/management/client.rb', line 595

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_allObject

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.



636
637
638
639
# File 'lib/smplkit/management/client.rb', line 636

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



613
614
615
616
617
618
619
620
621
# File 'lib/smplkit/management/client.rb', line 613

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_countObject



564
565
566
# File 'lib/smplkit/management/client.rb', line 564

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.



550
551
552
553
554
555
# File 'lib/smplkit/management/client.rb', line 550

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.



559
560
561
562
# File 'lib/smplkit/management/client.rb', line 559

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