latitude-api 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +283 -0
- data/Rakefile +13 -0
- data/lib/latitude/api/api_object.rb +105 -0
- data/lib/latitude/api/api_resource.rb +260 -0
- data/lib/latitude/api/attributes.rb +64 -0
- data/lib/latitude/api/client.rb +80 -0
- data/lib/latitude/api/configuration.rb +88 -0
- data/lib/latitude/api/errors.rb +134 -0
- data/lib/latitude/api/json_api.rb +40 -0
- data/lib/latitude/api/list_object.rb +129 -0
- data/lib/latitude/api/objects.rb +216 -0
- data/lib/latitude/api/operations/action.rb +41 -0
- data/lib/latitude/api/operations/create.rb +22 -0
- data/lib/latitude/api/operations/delete.rb +22 -0
- data/lib/latitude/api/operations/list.rb +54 -0
- data/lib/latitude/api/operations/nested.rb +53 -0
- data/lib/latitude/api/operations/retrieve.rb +22 -0
- data/lib/latitude/api/operations/update.rb +22 -0
- data/lib/latitude/api/request_executor.rb +217 -0
- data/lib/latitude/api/request_options.rb +86 -0
- data/lib/latitude/api/request_params.rb +70 -0
- data/lib/latitude/api/resources/api_key.rb +61 -0
- data/lib/latitude/api/resources/billing_usage.rb +51 -0
- data/lib/latitude/api/resources/elastic_ip.rb +96 -0
- data/lib/latitude/api/resources/event.rb +55 -0
- data/lib/latitude/api/resources/firewall.rb +129 -0
- data/lib/latitude/api/resources/ip.rb +110 -0
- data/lib/latitude/api/resources/kubernetes_cluster.rb +184 -0
- data/lib/latitude/api/resources/plan.rb +658 -0
- data/lib/latitude/api/resources/project.rb +179 -0
- data/lib/latitude/api/resources/region.rb +41 -0
- data/lib/latitude/api/resources/role.rb +20 -0
- data/lib/latitude/api/resources/server.rb +251 -0
- data/lib/latitude/api/resources/ssh_key.rb +44 -0
- data/lib/latitude/api/resources/storage_filesystem.rb +36 -0
- data/lib/latitude/api/resources/storage_object.rb +85 -0
- data/lib/latitude/api/resources/storage_volume.rb +64 -0
- data/lib/latitude/api/resources/tag.rb +34 -0
- data/lib/latitude/api/resources/team.rb +169 -0
- data/lib/latitude/api/resources/traffic.rb +215 -0
- data/lib/latitude/api/resources/user_data.rb +38 -0
- data/lib/latitude/api/resources/user_profile.rb +51 -0
- data/lib/latitude/api/resources/user_team.rb +90 -0
- data/lib/latitude/api/resources/virtual_machine.rb +146 -0
- data/lib/latitude/api/resources/virtual_network.rb +162 -0
- data/lib/latitude/api/resources/vpn_session.rb +80 -0
- data/lib/latitude/api/singleton_api_resource.rb +22 -0
- data/lib/latitude/api/util.rb +64 -0
- data/lib/latitude/api/version.rb +7 -0
- data/lib/latitude/api.rb +147 -0
- data/lib/latitude/metadata/errors.rb +18 -0
- data/lib/latitude/metadata/session.rb +109 -0
- data/lib/latitude/metadata.rb +43 -0
- data/lib/latitude.rb +4 -0
- metadata +132 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Latitude
|
|
4
|
+
module API
|
|
5
|
+
module Resources
|
|
6
|
+
# @!attribute [rw] name
|
|
7
|
+
# @return [String]
|
|
8
|
+
# @!attribute [rw] status
|
|
9
|
+
# @return [String]
|
|
10
|
+
# @!attribute [r] created_at
|
|
11
|
+
# @return [Time]
|
|
12
|
+
# @!attribute [rw] primary_ipv4
|
|
13
|
+
# @return [String]
|
|
14
|
+
# @!attribute [rw] operating_system
|
|
15
|
+
# @return [OperatingSystem]
|
|
16
|
+
# @!attribute [rw] site
|
|
17
|
+
# @return [String]
|
|
18
|
+
# @!attribute [rw] billing
|
|
19
|
+
# @return [String]
|
|
20
|
+
# @!attribute [rw] plan
|
|
21
|
+
# @return [Plan]
|
|
22
|
+
# @!attribute [rw] specs
|
|
23
|
+
# @return [Spec]
|
|
24
|
+
# @!attribute [rw] team
|
|
25
|
+
# @return [Latitude::API::Objects::Team]
|
|
26
|
+
# @!attribute [rw] project
|
|
27
|
+
# @return [Latitude::API::Objects::Project]
|
|
28
|
+
# @!attribute [rw] credentials
|
|
29
|
+
# @return [Credential]
|
|
30
|
+
class VirtualMachine < APIResource
|
|
31
|
+
# @!attribute [r] raid
|
|
32
|
+
# @return [Boolean]
|
|
33
|
+
# @!attribute [r] ssh_keys
|
|
34
|
+
# @return [Boolean]
|
|
35
|
+
# @!attribute [r] user_data
|
|
36
|
+
# @return [Boolean]
|
|
37
|
+
class Feature < APIObject
|
|
38
|
+
attribute :raid, :boolean, read_only: true
|
|
39
|
+
attribute :ssh_keys, :boolean, read_only: true
|
|
40
|
+
attribute :user_data, :boolean, read_only: true
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# @!attribute [r] name
|
|
44
|
+
# @return [String]
|
|
45
|
+
# @!attribute [r] slug
|
|
46
|
+
# @return [String]
|
|
47
|
+
# @!attribute [r] series
|
|
48
|
+
# @return [String]
|
|
49
|
+
class Distro < APIObject
|
|
50
|
+
attribute :name, :string, read_only: true
|
|
51
|
+
attribute :slug, :string, read_only: true
|
|
52
|
+
attribute :series, :string, read_only: true
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# @!attribute [r] name
|
|
56
|
+
# @return [String]
|
|
57
|
+
# @!attribute [r] slug
|
|
58
|
+
# @return [String]
|
|
59
|
+
# @!attribute [r] version
|
|
60
|
+
# @return [String]
|
|
61
|
+
# @!attribute [r] features
|
|
62
|
+
# @return [Feature]
|
|
63
|
+
# @!attribute [r] distro
|
|
64
|
+
# @return [Distro]
|
|
65
|
+
class OperatingSystem < APIObject
|
|
66
|
+
attribute :name, :string, read_only: true
|
|
67
|
+
attribute :slug, :string, read_only: true
|
|
68
|
+
attribute :version, :string, read_only: true
|
|
69
|
+
attribute :features, Feature, read_only: true
|
|
70
|
+
attribute :distro, Distro, read_only: true
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# @!attribute [r] id
|
|
74
|
+
# @return [String]
|
|
75
|
+
# @!attribute [r] name
|
|
76
|
+
# @return [String]
|
|
77
|
+
class Plan < APIObject
|
|
78
|
+
attribute :id, :string, read_only: true
|
|
79
|
+
attribute :name, :string, read_only: true
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# @!attribute [r] vcpu
|
|
83
|
+
# @return [Integer]
|
|
84
|
+
# @!attribute [r] ram
|
|
85
|
+
# @return [String]
|
|
86
|
+
# @!attribute [r] storage
|
|
87
|
+
# @return [String]
|
|
88
|
+
# @!attribute [r] nic
|
|
89
|
+
# @return [String]
|
|
90
|
+
# @!attribute [r] gpu
|
|
91
|
+
# @return [String]
|
|
92
|
+
class Spec < APIObject
|
|
93
|
+
attribute :vcpu, :integer, read_only: true
|
|
94
|
+
attribute :ram, :string, read_only: true
|
|
95
|
+
attribute :storage, :string, read_only: true
|
|
96
|
+
attribute :nic, :string, read_only: true
|
|
97
|
+
attribute :gpu, :string, read_only: true
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# @!attribute [r] username
|
|
101
|
+
# @return [String]
|
|
102
|
+
# @!attribute [r] host
|
|
103
|
+
# @return [String]
|
|
104
|
+
# @!attribute [r] password
|
|
105
|
+
# @return [String]
|
|
106
|
+
# @!attribute [r] ssh_keys
|
|
107
|
+
# @return [Array]
|
|
108
|
+
class Credential < APIObject
|
|
109
|
+
attribute :username, :string, read_only: true
|
|
110
|
+
attribute :host, :string, read_only: true
|
|
111
|
+
attribute :password, :string, read_only: true
|
|
112
|
+
attribute :ssh_keys, :array, read_only: true
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
attribute :name, :string
|
|
116
|
+
attribute :status, :string
|
|
117
|
+
attribute :created_at, :time, read_only: true
|
|
118
|
+
attribute :primary_ipv4, :string
|
|
119
|
+
attribute :operating_system, OperatingSystem
|
|
120
|
+
attribute :site, :string
|
|
121
|
+
attribute :billing, :string
|
|
122
|
+
attribute :plan, Plan
|
|
123
|
+
attribute :specs, Spec
|
|
124
|
+
attribute :team, Objects::Team
|
|
125
|
+
attribute :project, Objects::Project
|
|
126
|
+
attribute :credentials, Credential
|
|
127
|
+
|
|
128
|
+
resource_type "virtual_machines"
|
|
129
|
+
resource_path "/virtual_machines"
|
|
130
|
+
id_prefix "vm_"
|
|
131
|
+
|
|
132
|
+
extend Operations::List
|
|
133
|
+
extend Operations::Create
|
|
134
|
+
extend Operations::Retrieve
|
|
135
|
+
extend Operations::Update
|
|
136
|
+
extend Operations::Delete
|
|
137
|
+
extend Operations::Action
|
|
138
|
+
|
|
139
|
+
action :power_action, path: "actions", type: "actions", accepts: %i[action]
|
|
140
|
+
action :reboot, path: "actions", type: "actions", attributes: { action: "reboot" }
|
|
141
|
+
action :power_on, path: "actions", type: "actions", attributes: { action: "power_on" }
|
|
142
|
+
action :power_off, path: "actions", type: "actions", attributes: { action: "power_off" }
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Latitude
|
|
4
|
+
module API
|
|
5
|
+
module Resources
|
|
6
|
+
# @!attribute [rw] tags
|
|
7
|
+
# @return [Array<Latitude::API::Objects::Tag>]
|
|
8
|
+
# @!attribute [rw] vid
|
|
9
|
+
# @return [Integer]
|
|
10
|
+
# @!attribute [rw] name
|
|
11
|
+
# @return [String]
|
|
12
|
+
# @!attribute [rw] description
|
|
13
|
+
# @return [String]
|
|
14
|
+
# @!attribute [rw] site
|
|
15
|
+
# @return [String]
|
|
16
|
+
# @!attribute [r] created_at
|
|
17
|
+
# @return [Time]
|
|
18
|
+
# @!attribute [rw] region
|
|
19
|
+
# @return [Region]
|
|
20
|
+
# @!attribute [rw] project
|
|
21
|
+
# @return [Latitude::API::Objects::Project]
|
|
22
|
+
# @!attribute [rw] assignments_count
|
|
23
|
+
# @return [Integer]
|
|
24
|
+
class VirtualNetwork < APIResource
|
|
25
|
+
# @!attribute [r] id
|
|
26
|
+
# @return [String]
|
|
27
|
+
# @!attribute [r] name
|
|
28
|
+
# @return [String]
|
|
29
|
+
# @!attribute [r] slug
|
|
30
|
+
# @return [String]
|
|
31
|
+
# @!attribute [r] facility
|
|
32
|
+
# @return [String]
|
|
33
|
+
class Site < APIObject
|
|
34
|
+
attribute :id, :string, read_only: true
|
|
35
|
+
attribute :name, :string, read_only: true
|
|
36
|
+
attribute :slug, :string, read_only: true
|
|
37
|
+
attribute :facility, :string, read_only: true
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# @!attribute [r] city
|
|
41
|
+
# @return [String]
|
|
42
|
+
# @!attribute [r] country
|
|
43
|
+
# @return [String]
|
|
44
|
+
# @!attribute [r] site
|
|
45
|
+
# @return [Site]
|
|
46
|
+
class Region < APIObject
|
|
47
|
+
attribute :city, :string, read_only: true
|
|
48
|
+
attribute :country, :string, read_only: true
|
|
49
|
+
attribute :site, Site, read_only: true
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
attribute :tags, [Objects::Tag]
|
|
53
|
+
attribute :vid, :integer
|
|
54
|
+
attribute :name, :string
|
|
55
|
+
attribute :description, :string
|
|
56
|
+
attribute :site, :string
|
|
57
|
+
attribute :created_at, :time, read_only: true
|
|
58
|
+
attribute :region, Region
|
|
59
|
+
attribute :project, Objects::Project
|
|
60
|
+
attribute :assignments_count, :integer
|
|
61
|
+
|
|
62
|
+
resource_type "virtual_networks"
|
|
63
|
+
resource_path "/virtual_networks"
|
|
64
|
+
id_prefix "vlan_"
|
|
65
|
+
|
|
66
|
+
extend Operations::List
|
|
67
|
+
extend Operations::Create
|
|
68
|
+
extend Operations::Retrieve
|
|
69
|
+
extend Operations::Update
|
|
70
|
+
extend Operations::Delete
|
|
71
|
+
|
|
72
|
+
# @!attribute [rw] virtual_network_id
|
|
73
|
+
|
|
74
|
+
# @return [String]
|
|
75
|
+
|
|
76
|
+
# @!attribute [rw] vid
|
|
77
|
+
|
|
78
|
+
# @return [Integer]
|
|
79
|
+
|
|
80
|
+
# @!attribute [rw] description
|
|
81
|
+
|
|
82
|
+
# @return [String]
|
|
83
|
+
|
|
84
|
+
# @!attribute [rw] status
|
|
85
|
+
|
|
86
|
+
# @return [String]
|
|
87
|
+
|
|
88
|
+
# @!attribute [rw] server
|
|
89
|
+
|
|
90
|
+
# @return [Server]
|
|
91
|
+
|
|
92
|
+
# @!attribute [rw] server_id
|
|
93
|
+
|
|
94
|
+
# @return [String]
|
|
95
|
+
|
|
96
|
+
class Assignment < APIResource
|
|
97
|
+
|
|
98
|
+
# @!attribute [r] id
|
|
99
|
+
|
|
100
|
+
# @return [String]
|
|
101
|
+
|
|
102
|
+
# @!attribute [r] hostname
|
|
103
|
+
|
|
104
|
+
# @return [String]
|
|
105
|
+
|
|
106
|
+
# @!attribute [r] label
|
|
107
|
+
|
|
108
|
+
# @return [String]
|
|
109
|
+
|
|
110
|
+
# @!attribute [r] locked
|
|
111
|
+
|
|
112
|
+
# @return [Boolean]
|
|
113
|
+
|
|
114
|
+
# @!attribute [r] status
|
|
115
|
+
|
|
116
|
+
# @return [String]
|
|
117
|
+
|
|
118
|
+
class Server < APIObject
|
|
119
|
+
|
|
120
|
+
attribute :id, :string, read_only: true
|
|
121
|
+
|
|
122
|
+
attribute :hostname, :string, read_only: true
|
|
123
|
+
|
|
124
|
+
attribute :label, :string, read_only: true
|
|
125
|
+
|
|
126
|
+
attribute :locked, :boolean, read_only: true
|
|
127
|
+
|
|
128
|
+
attribute :status, :string, read_only: true
|
|
129
|
+
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
attribute :virtual_network_id, :string
|
|
134
|
+
|
|
135
|
+
attribute :vid, :integer
|
|
136
|
+
|
|
137
|
+
attribute :description, :string
|
|
138
|
+
|
|
139
|
+
attribute :status, :string
|
|
140
|
+
|
|
141
|
+
attribute :server, Server
|
|
142
|
+
|
|
143
|
+
attribute :server_id, :string
|
|
144
|
+
|
|
145
|
+
resource_type "virtual_network_assignment"
|
|
146
|
+
resource_path "/virtual_networks/assignments"
|
|
147
|
+
|
|
148
|
+
extend Operations::List
|
|
149
|
+
extend Operations::Delete
|
|
150
|
+
|
|
151
|
+
class << self
|
|
152
|
+
def create(params = {}, opts = {})
|
|
153
|
+
body = JSONAPI.encode(type: resource_type, attributes: params)
|
|
154
|
+
parsed = execute_request(method: :post, path: resource_path, body: body, opts: opts)
|
|
155
|
+
construct_from(parsed, opts: opts)
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Latitude
|
|
4
|
+
module API
|
|
5
|
+
module Resources
|
|
6
|
+
# @!attribute [rw] user_name
|
|
7
|
+
# @return [String]
|
|
8
|
+
# @!attribute [rw] password
|
|
9
|
+
# @return [String]
|
|
10
|
+
# @!attribute [rw] port
|
|
11
|
+
# @return [String]
|
|
12
|
+
# @!attribute [rw] host
|
|
13
|
+
# @return [String]
|
|
14
|
+
# @!attribute [rw] region
|
|
15
|
+
# @return [Region]
|
|
16
|
+
# @!attribute [rw] expires_at
|
|
17
|
+
# @return [Time]
|
|
18
|
+
# @!attribute [r] created_at
|
|
19
|
+
# @return [Time]
|
|
20
|
+
# @!attribute [r] updated_at
|
|
21
|
+
# @return [Time]
|
|
22
|
+
class VPNSession < APIResource
|
|
23
|
+
# @!attribute [r] id
|
|
24
|
+
# @return [String]
|
|
25
|
+
# @!attribute [r] name
|
|
26
|
+
# @return [String]
|
|
27
|
+
# @!attribute [r] slug
|
|
28
|
+
# @return [String]
|
|
29
|
+
# @!attribute [r] facility
|
|
30
|
+
# @return [String]
|
|
31
|
+
class Site < APIObject
|
|
32
|
+
attribute :id, :string, read_only: true
|
|
33
|
+
attribute :name, :string, read_only: true
|
|
34
|
+
attribute :slug, :string, read_only: true
|
|
35
|
+
attribute :facility, :string, read_only: true
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# @!attribute [r] city
|
|
39
|
+
# @return [String]
|
|
40
|
+
# @!attribute [r] country
|
|
41
|
+
# @return [String]
|
|
42
|
+
# @!attribute [r] site
|
|
43
|
+
# @return [Site]
|
|
44
|
+
class Region < APIObject
|
|
45
|
+
attribute :city, :string, read_only: true
|
|
46
|
+
attribute :country, :string, read_only: true
|
|
47
|
+
attribute :site, Site, read_only: true
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
attribute :user_name, :string
|
|
51
|
+
attribute :password, :string
|
|
52
|
+
attribute :port, :string
|
|
53
|
+
attribute :host, :string
|
|
54
|
+
attribute :region, Region
|
|
55
|
+
attribute :expires_at, :time
|
|
56
|
+
attribute :created_at, :time, read_only: true
|
|
57
|
+
attribute :updated_at, :time, read_only: true
|
|
58
|
+
|
|
59
|
+
resource_type "vpn_sessions"
|
|
60
|
+
resource_path "/vpn_sessions"
|
|
61
|
+
id_prefix "vpn_"
|
|
62
|
+
|
|
63
|
+
extend Operations::List
|
|
64
|
+
extend Operations::Create
|
|
65
|
+
extend Operations::Delete
|
|
66
|
+
|
|
67
|
+
class << self
|
|
68
|
+
def refresh_password(id, opts = {})
|
|
69
|
+
parsed = execute_request(method: :patch, path: "#{instance_url(id)}/refresh_password", opts: opts)
|
|
70
|
+
construct_from(parsed, opts: opts)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def refresh_password(opts = {})
|
|
75
|
+
self.class.refresh_password(id, opts)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Latitude
|
|
4
|
+
module API
|
|
5
|
+
class SingletonAPIResource < APIResource
|
|
6
|
+
class << self
|
|
7
|
+
def retrieve(opts = {})
|
|
8
|
+
parsed = execute_request(method: :get, path: resource_path, opts: opts)
|
|
9
|
+
construct_from(parsed, opts: opts)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def instance_url(_id = nil, path_params: {})
|
|
13
|
+
class_url(path_params: path_params)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def resource_url
|
|
18
|
+
self.class.resource_path
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Latitude
|
|
4
|
+
module API
|
|
5
|
+
module Util
|
|
6
|
+
module_function
|
|
7
|
+
|
|
8
|
+
def symbolize_keys(obj)
|
|
9
|
+
case obj
|
|
10
|
+
when Hash
|
|
11
|
+
obj.each_with_object({}) { |(k, v), h| h[k.to_sym] = symbolize_keys(v) }
|
|
12
|
+
when Array
|
|
13
|
+
obj.map { |v| symbolize_keys(v) }
|
|
14
|
+
else
|
|
15
|
+
obj
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def stringify_keys(obj)
|
|
20
|
+
case obj
|
|
21
|
+
when Hash
|
|
22
|
+
obj.each_with_object({}) { |(k, v), h| h[k.to_s] = stringify_keys(v) }
|
|
23
|
+
when Array
|
|
24
|
+
obj.map { |v| stringify_keys(v) }
|
|
25
|
+
else
|
|
26
|
+
obj
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def deep_merge(a, b)
|
|
31
|
+
a.merge(b) do |_key, av, bv|
|
|
32
|
+
if av.is_a?(Hash) && bv.is_a?(Hash)
|
|
33
|
+
deep_merge(av, bv)
|
|
34
|
+
else
|
|
35
|
+
bv
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def present?(value)
|
|
41
|
+
!blank?(value)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def blank?(value)
|
|
45
|
+
value.nil? || (value.respond_to?(:empty?) && value.empty?)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def redact(hash, sensitive_fields)
|
|
49
|
+
return hash unless hash.is_a?(Hash)
|
|
50
|
+
|
|
51
|
+
keys = sensitive_fields.map { |k| k.to_s.downcase }
|
|
52
|
+
hash.each_with_object({}) do |(k, v), out|
|
|
53
|
+
out[k] = if keys.include?(k.to_s.downcase)
|
|
54
|
+
"[FILTERED]"
|
|
55
|
+
elsif v.is_a?(Hash)
|
|
56
|
+
redact(v, sensitive_fields)
|
|
57
|
+
else
|
|
58
|
+
v
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
data/lib/latitude/api.rb
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "net/http"
|
|
5
|
+
require "openssl"
|
|
6
|
+
require "securerandom"
|
|
7
|
+
require "time"
|
|
8
|
+
require "uri"
|
|
9
|
+
require "forwardable"
|
|
10
|
+
require "logger"
|
|
11
|
+
|
|
12
|
+
require "latitude/api/version"
|
|
13
|
+
require "latitude/api/errors"
|
|
14
|
+
require "latitude/api/util"
|
|
15
|
+
require "latitude/api/configuration"
|
|
16
|
+
require "latitude/api/request_params"
|
|
17
|
+
require "latitude/api/request_options"
|
|
18
|
+
require "latitude/api/json_api"
|
|
19
|
+
require "latitude/api/attributes"
|
|
20
|
+
require "latitude/api/api_object"
|
|
21
|
+
require "latitude/api/objects"
|
|
22
|
+
require "latitude/api/list_object"
|
|
23
|
+
require "latitude/api/request_executor"
|
|
24
|
+
require "latitude/api/operations/list"
|
|
25
|
+
require "latitude/api/operations/create"
|
|
26
|
+
require "latitude/api/operations/retrieve"
|
|
27
|
+
require "latitude/api/operations/update"
|
|
28
|
+
require "latitude/api/operations/delete"
|
|
29
|
+
require "latitude/api/operations/action"
|
|
30
|
+
require "latitude/api/operations/nested"
|
|
31
|
+
require "latitude/api/api_resource"
|
|
32
|
+
require "latitude/api/singleton_api_resource"
|
|
33
|
+
require "latitude/api/client"
|
|
34
|
+
|
|
35
|
+
require "latitude/api/resources/server"
|
|
36
|
+
require "latitude/api/resources/region"
|
|
37
|
+
require "latitude/api/resources/role"
|
|
38
|
+
require "latitude/api/resources/event"
|
|
39
|
+
require "latitude/api/resources/ip"
|
|
40
|
+
require "latitude/api/resources/plan"
|
|
41
|
+
require "latitude/api/resources/billing_usage"
|
|
42
|
+
require "latitude/api/resources/traffic"
|
|
43
|
+
require "latitude/api/resources/user_profile"
|
|
44
|
+
require "latitude/api/resources/user_team"
|
|
45
|
+
require "latitude/api/resources/project"
|
|
46
|
+
require "latitude/api/resources/ssh_key"
|
|
47
|
+
require "latitude/api/resources/user_data"
|
|
48
|
+
require "latitude/api/resources/tag"
|
|
49
|
+
require "latitude/api/resources/team"
|
|
50
|
+
require "latitude/api/resources/api_key"
|
|
51
|
+
require "latitude/api/resources/elastic_ip"
|
|
52
|
+
require "latitude/api/resources/virtual_network"
|
|
53
|
+
require "latitude/api/resources/firewall"
|
|
54
|
+
require "latitude/api/resources/vpn_session"
|
|
55
|
+
require "latitude/api/resources/storage_filesystem"
|
|
56
|
+
require "latitude/api/resources/storage_volume"
|
|
57
|
+
require "latitude/api/resources/storage_object"
|
|
58
|
+
require "latitude/api/resources/virtual_machine"
|
|
59
|
+
require "latitude/api/resources/kubernetes_cluster"
|
|
60
|
+
|
|
61
|
+
module Latitude
|
|
62
|
+
class << self
|
|
63
|
+
extend Forwardable
|
|
64
|
+
|
|
65
|
+
def config
|
|
66
|
+
@config ||= API::Configuration.new
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def configure
|
|
70
|
+
yield config
|
|
71
|
+
config
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def reset_config!
|
|
75
|
+
@config = API::Configuration.new
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def_delegators :config,
|
|
79
|
+
:api_key, :api_key=,
|
|
80
|
+
:api_base, :api_base=,
|
|
81
|
+
:api_version, :api_version=,
|
|
82
|
+
:open_timeout, :open_timeout=,
|
|
83
|
+
:read_timeout, :read_timeout=,
|
|
84
|
+
:write_timeout, :write_timeout=,
|
|
85
|
+
:max_network_retries, :max_network_retries=,
|
|
86
|
+
:initial_network_retry_delay, :initial_network_retry_delay=,
|
|
87
|
+
:max_network_retry_delay, :max_network_retry_delay=,
|
|
88
|
+
:proxy, :proxy=,
|
|
89
|
+
:verify_ssl_certs, :verify_ssl_certs=,
|
|
90
|
+
:ca_bundle_path, :ca_bundle_path=,
|
|
91
|
+
:ca_store, :ca_store=,
|
|
92
|
+
:logger, :logger=,
|
|
93
|
+
:log_level, :log_level=,
|
|
94
|
+
:app_info, :app_info=,
|
|
95
|
+
:enable_telemetry, :enable_telemetry=,
|
|
96
|
+
:sensitive_fields, :sensitive_fields=
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
module API
|
|
100
|
+
Error = Latitude::Error
|
|
101
|
+
ConfigurationError = Latitude::ConfigurationError
|
|
102
|
+
ConnectionError = Latitude::ConnectionError
|
|
103
|
+
APIError = Latitude::APIError
|
|
104
|
+
BadRequestError = Latitude::BadRequestError
|
|
105
|
+
AuthenticationError = Latitude::AuthenticationError
|
|
106
|
+
PermissionError = Latitude::PermissionError
|
|
107
|
+
NotFoundError = Latitude::NotFoundError
|
|
108
|
+
ConflictError = Latitude::ConflictError
|
|
109
|
+
UnprocessableEntityError = Latitude::UnprocessableEntityError
|
|
110
|
+
RateLimitError = Latitude::RateLimitError
|
|
111
|
+
ServerError = Latitude::ServerError
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
Server = API::Resources::Server
|
|
115
|
+
Region = API::Resources::Region
|
|
116
|
+
Role = API::Resources::Role
|
|
117
|
+
Event = API::Resources::Event
|
|
118
|
+
IP = API::Resources::IP
|
|
119
|
+
Plan = API::Resources::Plan
|
|
120
|
+
BillingUsage = API::Resources::BillingUsage
|
|
121
|
+
Traffic = API::Resources::Traffic
|
|
122
|
+
UserProfile = API::Resources::UserProfile
|
|
123
|
+
UserTeam = API::Resources::UserTeam
|
|
124
|
+
Project = API::Resources::Project
|
|
125
|
+
SSHKey = API::Resources::SSHKey
|
|
126
|
+
UserData = API::Resources::UserData
|
|
127
|
+
Tag = API::Resources::Tag
|
|
128
|
+
Team = API::Resources::Team
|
|
129
|
+
APIKey = API::Resources::APIKey
|
|
130
|
+
ElasticIP = API::Resources::ElasticIP
|
|
131
|
+
VirtualNetwork = API::Resources::VirtualNetwork
|
|
132
|
+
Firewall = API::Resources::Firewall
|
|
133
|
+
VPNSession = API::Resources::VPNSession
|
|
134
|
+
VirtualMachine = API::Resources::VirtualMachine
|
|
135
|
+
KubernetesCluster = API::Resources::KubernetesCluster
|
|
136
|
+
|
|
137
|
+
module Storage
|
|
138
|
+
Filesystem = API::Resources::Storage::Filesystem
|
|
139
|
+
Volume = API::Resources::Storage::Volume
|
|
140
|
+
Object = API::Resources::Storage::Object
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
module User
|
|
144
|
+
Profile = API::Resources::UserProfile
|
|
145
|
+
Team = API::Resources::UserTeam
|
|
146
|
+
end
|
|
147
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Latitude
|
|
4
|
+
module Metadata
|
|
5
|
+
class Error < StandardError; end
|
|
6
|
+
class Unavailable < Error; end
|
|
7
|
+
class TokenError < Error; end
|
|
8
|
+
class RequestError < Error
|
|
9
|
+
attr_reader :http_status, :http_body
|
|
10
|
+
|
|
11
|
+
def initialize(message = nil, http_status: nil, http_body: nil)
|
|
12
|
+
super(message)
|
|
13
|
+
@http_status = http_status
|
|
14
|
+
@http_body = http_body
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|