File: describe_tasks.rb

package info (click to toggle)
ruby-fog-aws 3.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 8,092 kB
  • sloc: ruby: 72,795; javascript: 14; makefile: 9; sh: 4
file content (65 lines) | stat: -rw-r--r-- 2,130 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
module Fog
  module AWS
    class ECS
      class Real
        require 'fog/aws/parsers/ecs/describe_tasks'

        # Describes a specified task or tasks.
        # http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeTasks.html
        # ==== Parameters
        # * cluster <~String> - short name or full Amazon Resource Name (ARN) of the cluster that hosts the task you want to describe
        # * tasks <~Array> - space-separated list of task UUIDs or full Amazon Resource Name (ARN) entries
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'tasks' <~Array> - The list of tasks
        #     * 'failures' <~Array> - The list of failures (if any)
        def describe_tasks(params={})
          if tasks = params.delete('tasks')
            params.merge!(Fog::AWS.indexed_param('tasks.member', [*tasks]))
          end

          request({
            'Action'  => 'DescribeTasks',
            :parser   => Fog::Parsers::AWS::ECS::DescribeTasks.new
          }.merge(params))
        end
      end

      class Mock
        def describe_tasks(params={})
          response = Excon::Response.new
          response.status = 200

          unless tasks = params.delete('tasks')
            msg = 'InvalidParameterException => Tasks cannot be empty.'
            raise Fog::AWS::ECS::Error, msg
          end

          cluster = params.delete('cluster') || 'default'

          result = []
          [*tasks].each do |tid|
            if match = tid.match(/^arn:aws:ecs:.+:\d{1,12}:task\/(.+)$/)
              result = self.data[:tasks].select { |t| t['taskArn'].eql?(tid) }
            else
              result = self.data[:tasks].select { |t| t['taskArn'].match(/#{tid}$/) }
            end
          end

          tasks = result
          response.body = {
            'DescribeTasksResult' => {
              'failures' => [],
              'tasks' => tasks
            },
            'ResponseMetadata' => {
              'RequestId' => Fog::AWS::Mock.request_id
            }
          }
          response
        end
      end
    end
  end
end