Class: SecretProperty

Inherits:
Object
  • Object
show all
Defined in:
lib/ibm_appconfiguration_ruby_sdk/configurations/models/secret_property.rb

Overview

Defines the SecretProperty model.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property_id) ⇒ SecretProperty

Initialize a new SecretProperty instance

Parameters:

  • property_id (String)

    Property identifier



28
29
30
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/secret_property.rb', line 28

def initialize(property_id)
  @property_id = property_id
end

Instance Attribute Details

#property_idObject (readonly)

Returns the value of attribute property_id.



23
24
25
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/secret_property.rb', line 23

def property_id
  @property_id
end

Instance Method Details

#get_current_value(entity_id, entity_attributes = {}) ⇒ Object?

Evaluate the value of the secret property.

The returned value will be the actual secret value of the evaluated secret reference. The response contains the body, the headers, the status code, and the status text. If an error occurs, it will be raised as an exception.

Parameters:

  • entity_id (String)

    Id of the Entity.

  • entity_attributes (Hash) (defaults to: {})

    A hash consisting of the attribute name and their values that defines the specified entity.

Returns:

  • (Object, nil)

    returns the response from the secret manager or nil if entity_id is invalid.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/ibm_appconfiguration_ruby_sdk/configurations/models/secret_property.rb', line 41

def get_current_value(entity_id, entity_attributes = {})
  logger = Logger.instance

  if entity_id.nil? || entity_id.to_s.strip.empty?
    logger.error("SecretProperty evaluation: #{Constants::INVALID_ENTITY_ID} get_current_value")
    return nil
  end

  require_relative "../configuration_handler"
  configuration_handler_instance = ConfigurationHandler.instance

  # Get the property object
  property_obj = configuration_handler_instance.get_property(@property_id)
  return nil unless property_obj

  # Get the current value of the property (which contains the secret reference)
  property_current_val = property_obj.get_current_value(entity_id, entity_attributes)
  return nil unless property_current_val

  # Check if the property value contains a secret id
  if property_current_val[:value].is_a?(Hash) && property_current_val[:value].key?(:id)
    secret_id = property_current_val[:value][:id]

    # Get the secrets map from configuration handler
    secret_map = configuration_handler_instance.get_secrets_map
    secret_manager_obj = secret_map[@property_id]

    return secret_manager_obj.get_secret(id: secret_id) if secret_manager_obj

    # Call the get_secret method on the secret manager object
    # The caller is responsible for handling any exceptions

    logger.error("SecretProperty Evaluation: Secret manager not configured for property: #{property_obj.get_property_name}")
    return nil

  end

  logger.error("SecretProperty Evaluation: Secret Id is missing from the Property: #{property_obj.get_property_name}")
  nil
end