Class: LogStash::Util::CloudSettingId
- Inherits:
-
Object
- Object
- LogStash::Util::CloudSettingId
- Defined in:
- lib/logstash/util/cloud_setting_id.rb
Constant Summary collapse
- DOT_SEPARATOR =
"."
- CLOUD_PORT =
"443"
Instance Attribute Summary collapse
-
#decoded ⇒ Object
readonly
Returns the value of attribute decoded.
-
#elasticsearch_host ⇒ Object
readonly
Returns the value of attribute elasticsearch_host.
-
#elasticsearch_port ⇒ Object
readonly
Returns the value of attribute elasticsearch_port.
-
#elasticsearch_scheme ⇒ Object
readonly
Returns the value of attribute elasticsearch_scheme.
-
#kibana_host ⇒ Object
readonly
Returns the value of attribute kibana_host.
-
#kibana_port ⇒ Object
readonly
Returns the value of attribute kibana_port.
-
#kibana_scheme ⇒ Object
readonly
Returns the value of attribute kibana_scheme.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#other_identifiers ⇒ Object
readonly
Returns the value of attribute other_identifiers.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(value) ⇒ CloudSettingId
constructor
The constructor is expecting a ‘cloud.id’, a string in 2 variants.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ CloudSettingId
The constructor is expecting a ‘cloud.id’, a string in 2 variants. 1 part example: ‘dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyRub3RhcmVhbCRpZGVudGlmaWVy’ 2 part example: ‘foobar:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyRub3RhcmVhbCRpZGVudGlmaWVy’ The two part variant has a ‘label’ prepended with a colon separator. The label is not encoded. The 1 part (or second section of the 2 part variant) is base64 encoded. The original string before encoding has three segments separated by a dollar sign. e.g. ‘us-east-1.aws.found.io$notareal$identifier’ The first segment is the cloud base url, e.g. ‘us-east-1.aws.found.io’ The second segment is the elasticsearch host identifier, e.g. ‘notareal’ The third segment is the kibana host identifier, e.g. ‘identifier’ The ‘cloud.id’ value decoded into the #attr_reader ivars.
28 29 30 31 32 33 34 35 36 37 38 39 40 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/logstash/util/cloud_setting_id.rb', line 28 def initialize(value) return if value.nil? unless value.is_a?(String) raise ArgumentError.new("Cloud Id must be String. Received: #{value.class}") end @original = value @label, colon, encoded = @original.partition(":") if encoded.empty? @decoded = Base64.urlsafe_decode64(@label) rescue "" @label = "" else @decoded = Base64.urlsafe_decode64(encoded) rescue "" end @decoded = @decoded.encode(Encoding::UTF_8, :invalid => :replace, :undef => :replace) if @decoded.count("$") < 2 raise ArgumentError.new("Cloud Id, after decoding, is invalid. Format: '<segment1>$<segment2>$<segment3>'. Received: \"#{@decoded}\".") end segments = @decoded.split("$") if segments.any?(&:empty?) raise ArgumentError.new("Cloud Id, after decoding, is invalid. Format: '<segment1>$<segment2>$<segment3>'. Received: \"#{@decoded}\".") end cloud_base = segments.shift cloud_host = "#{DOT_SEPARATOR}#{cloud_base}" cloud_host, cloud_port = cloud_host.split(":") cloud_port ||= CLOUD_PORT @elasticsearch_host, @kibana_host, *@other_identifiers = segments @elasticsearch_host, @elasticsearch_port = @elasticsearch_host.split(":") @kibana_host, @kibana_port = @kibana_host.split(":") if @kibana_host @elasticsearch_port ||= cloud_port @kibana_port ||= cloud_port @other_identifiers ||= [] if @elasticsearch_host == "undefined" raise ArgumentError.new("Cloud Id, after decoding, elasticsearch segment is 'undefined', literally.") end @elasticsearch_scheme = "https" @elasticsearch_host.concat(cloud_host) @elasticsearch_host.concat(":#{@elasticsearch_port}") if @kibana_host == "undefined" raise ArgumentError.new("Cloud Id, after decoding, the kibana segment is 'undefined', literally. You may need to enable Kibana in the Cloud UI.") end @kibana_scheme = "https" @kibana_host ||= String.new # non-sense really to have '.my-host:443' but we're mirroring others @kibana_host.concat(cloud_host) @kibana_host.concat(":#{@kibana_port}") end |
Instance Attribute Details
#decoded ⇒ Object (readonly)
Returns the value of attribute decoded.
12 13 14 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 12 def decoded @decoded end |
#elasticsearch_host ⇒ Object (readonly)
Returns the value of attribute elasticsearch_host.
13 14 15 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 13 def elasticsearch_host @elasticsearch_host end |
#elasticsearch_port ⇒ Object (readonly)
Returns the value of attribute elasticsearch_port.
13 14 15 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 13 def elasticsearch_port @elasticsearch_port end |
#elasticsearch_scheme ⇒ Object (readonly)
Returns the value of attribute elasticsearch_scheme.
13 14 15 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 13 def elasticsearch_scheme @elasticsearch_scheme end |
#kibana_host ⇒ Object (readonly)
Returns the value of attribute kibana_host.
14 15 16 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 14 def kibana_host @kibana_host end |
#kibana_port ⇒ Object (readonly)
Returns the value of attribute kibana_port.
14 15 16 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 14 def kibana_port @kibana_port end |
#kibana_scheme ⇒ Object (readonly)
Returns the value of attribute kibana_scheme.
14 15 16 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 14 def kibana_scheme @kibana_scheme end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
12 13 14 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 12 def label @label end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
12 13 14 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 12 def original @original end |
#other_identifiers ⇒ Object (readonly)
Returns the value of attribute other_identifiers.
15 16 17 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 15 def other_identifiers @other_identifiers end |
Class Method Details
.cloud_id_encode(*args) ⇒ Object
6 7 8 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 6 def self.cloud_id_encode(*args) Base64.urlsafe_encode64(args.join("$")) end |
Instance Method Details
#inspect ⇒ Object
86 87 88 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 86 def inspect to_s end |
#to_s ⇒ Object
82 83 84 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 82 def to_s @decoded.to_s end |