Class: Fog::AWS::DataPipeline::Mock
- Inherits:
-
Object
- Object
- Fog::AWS::DataPipeline::Mock
show all
- Includes:
- CredentialFetcher::ConnectionMethods, Shared
- Defined in:
- lib/fog/aws/data_pipeline.rb,
lib/fog/aws/requests/data_pipeline/query_objects.rb,
lib/fog/aws/requests/data_pipeline/list_pipelines.rb,
lib/fog/aws/requests/data_pipeline/create_pipeline.rb,
lib/fog/aws/requests/data_pipeline/delete_pipeline.rb,
lib/fog/aws/requests/data_pipeline/describe_objects.rb,
lib/fog/aws/requests/data_pipeline/activate_pipeline.rb,
lib/fog/aws/requests/data_pipeline/describe_pipelines.rb,
lib/fog/aws/requests/data_pipeline/deactivate_pipeline.rb,
lib/fog/aws/requests/data_pipeline/get_pipeline_definition.rb,
lib/fog/aws/requests/data_pipeline/put_pipeline_definition.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#activate_pipeline(id) ⇒ Object
-
#create_pipeline(unique_id, name, description = nil, tags = nil) ⇒ Object
-
#data ⇒ Object
-
#deactivate_pipeline(id, cancel_active = true) ⇒ Object
-
#delete_pipeline(id) ⇒ Object
-
#describe_objects(id, objects, options = {}) ⇒ Object
-
#describe_pipelines(ids) ⇒ Object
-
#find_pipeline(id) ⇒ Object
-
#get_pipeline_definition(id) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
-
#list_pipelines(options = {}) ⇒ Object
-
#put_pipeline_definition(id, pipeline_objects, _options = {}) ⇒ Object
-
#query_objects(id, sphere, options = {}) ⇒ Object
-
#reset ⇒ Object
-
#stringify_keys(object) ⇒ Object
Methods included from Shared
#transform_objects
#refresh_credentials_if_expired
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
53
54
55
56
57
|
# File 'lib/fog/aws/data_pipeline.rb', line 53
def initialize(options={})
@region = options[:region] || "us-east-1"
@aws_access_key_id = options[:aws_access_key_id]
@aws_secret_access_key = options[:aws_secret_access_key]
end
|
Instance Attribute Details
#region ⇒ Object
Returns the value of attribute region.
51
52
53
|
# File 'lib/fog/aws/data_pipeline.rb', line 51
def region
@region
end
|
Class Method Details
.data ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/fog/aws/data_pipeline.rb', line 28
def self.data
@data ||= Hash.new do |hash, region|
hash[region] = Hash.new do |region_hash, key|
region_hash[key] = {
:pipelines => {},
:pipeline_definitions => {},
}
end
end
end
|
.reset ⇒ Object
39
40
41
|
# File 'lib/fog/aws/data_pipeline.rb', line 39
def self.reset
@data = nil
end
|
Instance Method Details
#activate_pipeline(id) ⇒ Object
23
24
25
26
27
28
29
30
31
|
# File 'lib/fog/aws/requests/data_pipeline/activate_pipeline.rb', line 23
def activate_pipeline(id)
response = Excon::Response.new
pipeline = find_pipeline(id)
pipeline[:active] = true
response.body = {}
response
end
|
#create_pipeline(unique_id, name, description = nil, tags = nil) ⇒ Object
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
|
# File 'lib/fog/aws/requests/data_pipeline/create_pipeline.rb', line 31
def create_pipeline(unique_id, name, description=nil, tags=nil)
response = Excon::Response.new
if existing_pipeline = self.data[:pipelines][unique_id]
{"pipelineId" => existing_pipeline["pipelineId"]}
else
pipeline_id = Fog::AWS::Mock.data_pipeline_id
mapped_tags = if tags
tags.map { |k,v| {"key" => k.to_s, "value" => v.to_s}}
else
[]
end
pipeline = {
"name" => name,
"description" => description,
"fields" => mapped_tags,
"pipelineId" => pipeline_id,
}
self.data[:pipelines][unique_id] = pipeline
response.body = {"pipelineId" => pipeline_id}
end
response
end
|
#data ⇒ Object
43
44
45
|
# File 'lib/fog/aws/data_pipeline.rb', line 43
def data
self.class.data[@region][@aws_access_key_id]
end
|
#deactivate_pipeline(id, cancel_active = true) ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/fog/aws/requests/data_pipeline/deactivate_pipeline.rb', line 24
def deactivate_pipeline(id, cancel_active=true)
response = Excon::Response.new
pipeline = find_pipeline(id)
pipeline[:active] = false
response.body = {}
response
end
|
#delete_pipeline(id) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/fog/aws/requests/data_pipeline/delete_pipeline.rb', line 24
def delete_pipeline(id)
response = Excon::Response.new
pipeline = find_pipeline(id)
pipeline[:deleted] = true
true
end
|
#describe_objects(id, objects, options = {}) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/fog/aws/requests/data_pipeline/describe_objects.rb', line 30
def describe_objects(id, objects, options={})
response = Excon::Response.new
find_pipeline(id)
pipeline_objects = self.data[:pipeline_definitions][id]["pipelineObjects"].select { |o| objects.include?(o["id"]) }
response.body = {
"hasMoreResults" => false,
"marker" => options[:marker],
"pipelineObjects" => [
{
"fields" => pipeline_objects
}
]
}
response
end
|
#describe_pipelines(ids) ⇒ Object
24
25
26
27
28
|
# File 'lib/fog/aws/requests/data_pipeline/describe_pipelines.rb', line 24
def describe_pipelines(ids)
response = Excon::Response.new
response.body = {"pipelineDescriptionList" => self.data[:pipelines].values.select { |p| !p[:deleted] && ids.include?(p["pipelineId"]) } }
response
end
|
#find_pipeline(id) ⇒ Object
70
71
72
73
74
75
76
77
78
|
# File 'lib/fog/aws/data_pipeline.rb', line 70
def find_pipeline(id)
pipeline = self.data[:pipelines].values.detect { |p| p["pipelineId"] == id }
if pipeline.nil? || pipeline[:deleted]
raise Fog::AWS::DataPipeline::NotFound.new("Pipeline with id: #{id} does not exist")
end
pipeline
end
|
#get_pipeline_definition(id) ⇒ Object
25
26
27
28
29
30
31
32
|
# File 'lib/fog/aws/requests/data_pipeline/get_pipeline_definition.rb', line 25
def get_pipeline_definition(id)
response = Excon::Response.new
pipeline = find_pipeline(id)
response.body = self.data[:pipeline_definitions][id] || {"pipelineObjects" => []}
response
end
|
#list_pipelines(options = {}) ⇒ Object
24
25
26
27
28
|
# File 'lib/fog/aws/requests/data_pipeline/list_pipelines.rb', line 24
def list_pipelines(options={})
response = Excon::Response.new
response.body = {"pipelineIdList" => self.data[:pipelines].values.map { |p| {"id" => p["pipelineId"], "name" => p["name"]} } }
response
end
|
#put_pipeline_definition(id, pipeline_objects, _options = {}) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/fog/aws/requests/data_pipeline/put_pipeline_definition.rb', line 73
def put_pipeline_definition(id, pipeline_objects, _options={})
response = Excon::Response.new
options = _options.dup
pipeline = find_pipeline(id)
stringified_objects = if pipeline_objects.any?
transform_objects(stringify_keys(pipeline_objects))
else
options.each { |k,v| options[k] = transform_objects(stringify_keys(v)) }
end
if stringified_objects.is_a?(Array)
stringified_objects = {"pipelineObjects" => stringified_objects}
end
self.data[:pipeline_definitions][id] = stringified_objects
response.body = {"errored" => false, "validationErrors" => [], "validationWarnings" => []}
response
end
|
#query_objects(id, sphere, options = {}) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/fog/aws/requests/data_pipeline/query_objects.rb', line 30
def query_objects(id, sphere, options={})
response = Excon::Response.new
find_pipeline(id)
response.body = {"hasMoreResults" => false, "ids" => ["Default"]}
response
end
|
#reset ⇒ Object
47
48
49
|
# File 'lib/fog/aws/data_pipeline.rb', line 47
def reset
self.class.reset
end
|
#stringify_keys(object) ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/fog/aws/data_pipeline.rb', line 59
def stringify_keys(object)
case object
when Hash
object.inject({}) { |h,(k,v)| h[k.to_s] = stringify_keys(v); h }
when Array
object.map { |v| stringify_keys(v) }
else
object
end
end
|