Class: CycloneLariat::Resources::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/cyclone_lariat/resources/queue.rb

Constant Summary collapse

SNS_SUFFIX =
:queue

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instance:, kind:, region:, dest:, account_id:, publisher:, type:, fifo:, content_based_deduplication: nil, tags: nil, name: nil) ⇒ Queue

Returns a new instance of Queue.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cyclone_lariat/resources/queue.rb', line 12

def initialize(instance:, kind:, region:, dest:, account_id:, publisher:, type:, fifo:, content_based_deduplication: nil, tags: nil, name: nil)
  @instance  = instance
  @kind      = kind
  @region    = region
  @dest      = dest
  @account_id = 
  @publisher = publisher
  @type      = type
  @fifo      = fifo
  @tags      = tags
  @name      = name
  @content_based_deduplication = content_based_deduplication
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



10
11
12
# File 'lib/cyclone_lariat/resources/queue.rb', line 10

def 
  @account_id
end

#content_based_deduplicationObject (readonly)

Returns the value of attribute content_based_deduplication.



10
11
12
# File 'lib/cyclone_lariat/resources/queue.rb', line 10

def content_based_deduplication
  @content_based_deduplication
end

#destObject (readonly)

Returns the value of attribute dest.



10
11
12
# File 'lib/cyclone_lariat/resources/queue.rb', line 10

def dest
  @dest
end

#fifoObject (readonly)

Returns the value of attribute fifo.



10
11
12
# File 'lib/cyclone_lariat/resources/queue.rb', line 10

def fifo
  @fifo
end

#instanceObject (readonly)

Returns the value of attribute instance.



10
11
12
# File 'lib/cyclone_lariat/resources/queue.rb', line 10

def instance
  @instance
end

#kindObject (readonly)

Returns the value of attribute kind.



10
11
12
# File 'lib/cyclone_lariat/resources/queue.rb', line 10

def kind
  @kind
end

#publisherObject (readonly)

Returns the value of attribute publisher.



10
11
12
# File 'lib/cyclone_lariat/resources/queue.rb', line 10

def publisher
  @publisher
end

#regionObject (readonly)

Returns the value of attribute region.



10
11
12
# File 'lib/cyclone_lariat/resources/queue.rb', line 10

def region
  @region
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/cyclone_lariat/resources/queue.rb', line 10

def type
  @type
end

Class Method Details

.from_arn(arn) ⇒ Object

Arn example: “arn:aws:sqs:eu-west-1:247606935658:custom_queue” arn_array => ‘arn’ arn_array => ‘aws’ arn_array => ‘sqs’ arn_array => ‘eu-west-1’ # region arn_array => ‘247606935658’ # account_id arn_array => ‘alexey_test2’ # name

Raises:

  • (ArgumentError)


133
134
135
136
137
138
139
140
141
# File 'lib/cyclone_lariat/resources/queue.rb', line 133

def from_arn(arn)
  arn_array = arn.split(':')

  raise ArgumentError, "Arn `#{arn}` should consists `arn`" unless arn_array[0] == 'arn'
  raise ArgumentError, "Arn `#{arn}` should consists `aws`" unless arn_array[1] == 'aws'
  raise ArgumentError, "Arn `#{arn}` should consists `sqs`" unless arn_array[2] == 'sqs'

  from_name(arn_array[5], region: arn_array[3], account_id: arn_array[4])
end

.from_name(name, region:, account_id:) ⇒ Object

Name example: test-event-queue-cyclone_lariat-note_added.fifo instance: teste kind: event publisher: cyclone_lariat type: note_added dest: nil fifo: true

Raises:

  • (ArgumentError)


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/cyclone_lariat/resources/queue.rb', line 83

def from_name(name, region:, account_id:)
  is_fifo_array  = name.split('.')
  full_name      = is_fifo_array[0]
  fifo_suffix    = is_fifo_array[-1]
  suffix_exists  = fifo_suffix != full_name

  if suffix_exists && fifo_suffix != 'fifo'
    raise ArgumentError, "Queue name #{name} consists unexpected suffix #{fifo_suffix}"
  end

  fifo        = suffix_exists
  queue_array = full_name.split('-')

  raise ArgumentError, "Topic name should consists `#{SNS_SUFFIX}`" unless queue_array[2] != SNS_SUFFIX

  queue_array.clear if queue_array.size < 5

  new(
    instance: queue_array[0], kind: queue_array[1], region: region, dest: queue_array[5],
    account_id: , publisher: queue_array[3], type: queue_array[4], fifo: fifo, name: name
  )
end

.from_url(url) ⇒ Object

URL example: sqs.eu-west-1.amazonaws.com/247606935658/test-event-queue-cyclone_lariat-note_added.fifo url_array => https host_array => sqs host_array => eu-west-1 url_array => 247606935658 # account_id url_array => test-event-queue-cyclone_lariat-note_added.fifo # name

Raises:

  • (ArgumentError)


113
114
115
116
117
118
119
120
121
122
123
# File 'lib/cyclone_lariat/resources/queue.rb', line 113

def from_url(url)
  raise ArgumentError, 'Url is not http format' unless url =~ URI::DEFAULT_PARSER.make_regexp

  url_array = url.split('/')
  raise ArgumentError, 'Url should start from https' unless url_array[0] == 'https:'

  host_array = url_array[2].split('.')
  raise ArgumentError, 'It is not queue url' unless host_array[0] == 'sqs'

  from_name(url_array[4], region: host_array[1], account_id: url_array[3])
end

Instance Method Details

#arnObject



26
27
28
# File 'lib/cyclone_lariat/resources/queue.rb', line 26

def arn
  ['arn', 'aws', 'sqs', region, , name].join ':'
end

#attributesObject



67
68
69
70
71
72
# File 'lib/cyclone_lariat/resources/queue.rb', line 67

def attributes
  attrs = {}
  attrs['FifoQueue']                 = 'true' if fifo
  attrs['ContentBasedDeduplication'] = 'true' if content_based_deduplication
  attrs
end

#custom?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/cyclone_lariat/resources/queue.rb', line 37

def custom?
  !standard?
end

#nameObject Also known as: to_s



45
46
47
48
49
50
51
# File 'lib/cyclone_lariat/resources/queue.rb', line 45

def name
  @name ||= begin
    name = [instance, kind, SNS_SUFFIX, publisher, type, dest].compact.join '-'
    name += '.fifo' if fifo
    name
  end
end

#protocolObject



63
64
65
# File 'lib/cyclone_lariat/resources/queue.rb', line 63

def protocol
  'sqs'
end

#queue?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/cyclone_lariat/resources/queue.rb', line 59

def queue?
  true
end

#standard?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/cyclone_lariat/resources/queue.rb', line 41

def standard?
  instance && kind && publisher && type && true
end

#tagsObject



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/cyclone_lariat/resources/queue.rb', line 144

def tags
  @tags ||= begin
    if standard?
      {
        'standard' => 'true',
        'instance' => String(instance),
        'kind' => String(kind),
        'publisher' => String(publisher),
        'type' => String(type),
        'dest' => dest ? String(dest) : 'undefined',
        'fifo' => fifo ? 'true' : 'false'
      }
    else
      {
        'standard' => 'false',
        'name' => String(name),
        'fifo' => fifo ? 'true' : 'false'
      }
    end
  end
end

#topic?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/cyclone_lariat/resources/queue.rb', line 55

def topic?
  false
end

#urlObject

Url example:

https://sqs.eu-west-1.amazonaws.com/247606935658/stage-event-queue


33
34
35
# File 'lib/cyclone_lariat/resources/queue.rb', line 33

def url
  "https://sqs.#{region}.amazonaws.com/#{}/#{name}"
end