Class: Infra
Class Method Summary collapse
- .create_namespace(user, namespace) ⇒ Object
- .create_project(namespace, project, type) ⇒ Object
- .deploy(project) ⇒ Object
- .generate_client(project, namespace) ⇒ Object
- .generate_edges(project, namespace) ⇒ Object
- .get_logs(project, namespace, since_time) ⇒ Object
- .get_namespace(id) ⇒ Object
- .get_pod_name(project, namespace) ⇒ Object
- .validate_user(email, token) ⇒ Object
Class Method Details
.create_namespace(user, namespace) ⇒ Object
14 15 16 17 |
# File 'lib/api/infra.rb', line 14 def self.create_namespace(user, namespace) res = post('/namespaces', { body: { namespace: { name: namespace, user_id: user } } }) [res.success?, res.parsed_response] end |
.create_project(namespace, project, type) ⇒ Object
24 25 26 27 |
# File 'lib/api/infra.rb', line 24 def self.create_project(namespace, project, type) res = post('/projects', { body: { project: { name: project, namespace_id: namespace, project_type: type} } }) [res.success?, res.parsed_response] end |
.deploy(project) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/api/infra.rb', line 29 def self.deploy(project) zip_path = "/tmp/#{project}_" + SecureRandom.alphanumeric(5) + '.zip' Archive::Zip.archive(zip_path, Dir.getwd + '/.') path = File.(zip_path) res = post("/projects/#{project}/deploy", { body: { content: File.open(path) }}) [res.success?, res.parsed_response] end |
.generate_client(project, namespace) ⇒ Object
39 40 41 42 43 |
# File 'lib/api/infra.rb', line 39 def self.generate_client(project, namespace) res = post("/projects/#{project}/client", { body: { name: project, namespace_id: namespace }}) [res.success?, res.parsed_response] end |
.generate_edges(project, namespace) ⇒ Object
45 46 47 48 49 |
# File 'lib/api/infra.rb', line 45 def self.generate_edges(project, namespace) res = post("/projects/#{project}/edges", { body: { name: project, namespace_id: namespace }}) [res.success?, res.parsed_response] end |
.get_logs(project, namespace, since_time) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/api/infra.rb', line 51 def self.get_logs(project, namespace, since_time) since_time_param = since_time ? "?since_time=#{since_time}" : '' res = get("/namespaces/#{namespace}/projects/#{project}/logs" + since_time_param) [res.success?, res.parsed_response] end |
.get_namespace(id) ⇒ Object
19 20 21 22 |
# File 'lib/api/infra.rb', line 19 def self.get_namespace(id) res = get("/namespaces/#{id}") [res.success?, res.parsed_response] end |
.get_pod_name(project, namespace) ⇒ Object
58 59 60 61 62 |
# File 'lib/api/infra.rb', line 58 def self.get_pod_name(project, namespace) res = post("/namespaces/#{namespace}/projects/#{project}/pod_name", { body: { name: project, namespace_id: namespace }}) [res.success?, res.parsed_response] end |
.validate_user(email, token) ⇒ Object
9 10 11 12 |
# File 'lib/api/infra.rb', line 9 def self.validate_user(email, token) res = get('/users/current', headers: { 'X-User-Email': email, 'X-User-Token': token }) [res.success?, res.parsed_response] end |