Module: Ey::Core::Mock::Resources

Included in:
Client::Mock
Defined in:
lib/ey-core/mock/resources.rb

Instance Method Summary collapse

Instance Method Details

#find(collection, id_or_url) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ey-core/mock/resources.rb', line 39

def find(collection, id_or_url)
  id = resource_identity(id_or_url)

  # polymorphic associations suck
  if collection.is_a?(Array)
    resource = collection.map do |key|
      data = self.data[key][id] || self.data[key][id.to_i]
      [key.to_s.tr('_', '-'), data] if data
    end.compact.first
    resource || response(status: 404, body: "Couldn't find #{collection.last} with #{id}")
  else
    self.data[collection][id] || self.data[collection][id.to_i] || response(status: 404, body: "Couldn't find #{collection} with [#{id}]")
  end
end

#mock_account_setup(resource_id, resource) ⇒ Object



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
81
82
# File 'lib/ey-core/mock/resources.rb', line 54

def (resource_id, resource)
  resource["support_plan"] ||= "standard"
   = url_for("/accounts/#{resource_id}")
  resource.merge!({
    "id"               => resource_id,
    "account_trial"    => "#{}/trial",
    "addons"           => "#{}/addons",
    "addresses"        => "#{}/addressses",
    "applications"     => "#{}/applications",
    "cancelled_at"     => nil,
    "costs"            => "#{}/costs",
    "created_at"       => Time.now.to_s,
    "deis_clusters"    => "#{}/deis-clusters",
    "environments"     => "#{}/environments",
    "features"         => "#{}/features",
    "memberships"      => "#{}/memberships",
    "notes"            => "#{}/notes",
    "owners"           => "#{}/owners",
    "providers"        => "#{}/providers",
    "referrals"        => "#{}/referrals",
    "requests"         => "#{}/requests",
    "resource_url"     => ,
    "ssl_certificates" => "#{}/ssl-certificates",
    "support_trial"    => nil,
    "updated_at"       => Time.now.to_s,
    "users"            => "#{}/users",
  })
  resource
end

#mock_ssh_keyObject



84
85
86
87
88
89
90
# File 'lib/ey-core/mock/resources.rb', line 84

def mock_ssh_key
  {
    public_key: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC05RVR8BF6gm1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F0PIxHjPt\naYHvqrECgYEA5YV7iQdKi07Cip99Y6MeyFjvp7oYHsSlrPko5y7VmDdAZlvZQ6KI\nNlJ7Vbl3GHtRYyPgh6WZMGDH+1EnSON0c/7IJk30BScMl5pAPHSy3cr2QWLlC9tE\ngyTzJC2GwSyN8ObSl9Mv71L1+y1SAS9ZuG984Y8r/EJLaiMwDNv8TVUCgYEAycN/\n4DjBGLvt9WfuXAQdKuUHvxp4LJOz1cAU60hucGYAY9/kmOsdfMUL+kh1diijmT35\nrr5zC665zq2FyVOnbUPkwKDnLW1o13rhxZYX9se1CFMUbskxCbc39CJmmyEX4bOm\n2Wwt2cJpfCnv+D+rMxXldQOFf46XkMiDjhusBq0CgYEAnDpkoRweaH5+ux7embCR\npmurDS8FdgQChZ+/cMUXTJnnMwU3+Oqr7tXr76jjYP2no2TrU0mr4RsvZGiT5fA0\n9zOohzIudEdlMdgj+0Kv8XpSbqVjJNPmaaIAAlMe02SBZUWoeQGeMjf1CTiLBhV1\n662vglUS6o0xihhTf51JulUCgYEAtgxVDH6JFIU0/3Hoa1Q28SY4KCF8/1PCNwKa\nnXT8WSRgA73X6HZ0Y8jztr+8ZIHko3d9G0OyUH82HhsJlQ+LCRbyhzBnhuCqcYrp\nvbthIgUt/jXgQNn+CjMsJHcJt71TbA4KZTGr6Uj2ntbENG1WTsDaCgvEX8TMUxHp\nSccEH/0CgYBULXDEqtCv85sAiJlgQ0uUI/LhAG48B/G8xUgZkSI+hId/dfrZuSqs\nJvms2/3P58fb15rE5fWtn9iPwA6wU2jlJg6KEnCawiEfhTZgy8XRhgQm0XK0HAHz\n4EWoM5VwYbdIs+LyuVQK/yNRJlP3gtODs6ADAZyzVyj8H2VBduzn9w==\n-----END RSA PRIVATE KEY-----\n".freeze,
    fingerprint: 16.times.map {rand(16**2).to_s(16).rjust(2,'0')}.join(":"), # => "8a:56:9a:b3:90:b1:3e:21:33:8d:a8:ee:61:69:c5:bc"
  }
end

#resource_identity(params) ⇒ Object

Attempt to determine the identity of the resource. Used to make the mock requests DRYer

Parameters:

  • params (nil)

    returns nil

  • params (Integer)

    id of the resource

  • params (String)

    id or url of the resource

  • params (Hash)

    description of resource

Options Hash (params):

  • url (String)

    url of the resource

  • id (String)

    id of the resource

Returns:

  • identity of the resource



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
# File 'lib/ey-core/mock/resources.rb', line 12

def resource_identity(params)
  id = nil
  url = nil

  case params
  when Hash
    id  = params["id"]
    url = params["url"]
  when String
    if params.start_with?(@url)
      url = params
    else
      id = params
    end
  when Integer
    id = params
  when nil
    return
  else
    raise ArgumentError, "Cannot determine resource identity of #{params.inspect}"
  end

  id ||= url && URI.parse(url).path.split("/")[2]

  Integer(id) rescue id
end