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_scheme ⇒ Object
readonly
Returns the value of attribute elasticsearch_scheme.
-
#kibana_host ⇒ Object
readonly
Returns the value of attribute kibana_host.
-
#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.
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.
26 27 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 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 26 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) unless @decoded.count("$") == 2 raise ArgumentError.new("Cloud Id does not decode. You may need to enable Kibana in the Cloud UI. 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_PORT}" @elasticsearch_host, @kibana_host = segments 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) 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.concat(cloud_host) end |
Instance Attribute Details
#decoded ⇒ Object (readonly)
Returns the value of attribute decoded.
13 14 15 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 13 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_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.
13 14 15 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 13 def kibana_host @kibana_host end |
#kibana_scheme ⇒ Object (readonly)
Returns the value of attribute kibana_scheme.
13 14 15 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 13 def kibana_scheme @kibana_scheme end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
13 14 15 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 13 def label @label end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
13 14 15 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 13 def original @original end |
Class Method Details
.cloud_id_encode(*args) ⇒ Object
7 8 9 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 7 def self.cloud_id_encode(*args) Base64.urlsafe_encode64(args.join("$")) end |
Instance Method Details
#inspect ⇒ Object
72 73 74 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 72 def inspect to_s end |
#to_s ⇒ Object
68 69 70 |
# File 'lib/logstash/util/cloud_setting_id.rb', line 68 def to_s @decoded.to_s end |