Class: Morpheus::DeploymentsInterface
- Inherits:
-
RestInterface
- Object
- RestInterface
- Morpheus::DeploymentsInterface
- Defined in:
- lib/morpheus/api/deployments_interface.rb
Instance Method Summary collapse
- #base_path ⇒ Object
- #create_version(deployment_id, payload, params = {}) ⇒ Object
-
#destroy_file(deployment_id, id, destination, params = {}) ⇒ Object
upload a file without multipart local_file is the full absolute local filename destination should be the full remote file path, including the file name.
- #destroy_version(deployment_id, id, params = {}) ⇒ Object
- #get_version(deployment_id, id, params = {}) ⇒ Object
- #list_files(deployment_id, id, params = {}) ⇒ Object
- #list_versions(deployment_id, params = {}) ⇒ Object
- #update_version(deployment_id, id, payload, params = {}) ⇒ Object
-
#upload_file(deployment_id, id, local_file, destination, params = {}) ⇒ Object
upload a file without multipart local_file is the full absolute local filename destination should be the full remote file path, including the file name.
Instance Method Details
#base_path ⇒ Object
5 6 7 |
# File 'lib/morpheus/api/deployments_interface.rb', line 5 def base_path "/api/deployments" end |
#create_version(deployment_id, payload, params = {}) ⇒ Object
18 19 20 |
# File 'lib/morpheus/api/deployments_interface.rb', line 18 def create_version(deployment_id, payload, params={}) execute(method: :post, url: "#{base_path}/#{deployment_id}/versions", params: params, payload: payload.to_json) end |
#destroy_file(deployment_id, id, destination, params = {}) ⇒ Object
upload a file without multipart local_file is the full absolute local filename destination should be the full remote file path, including the file name.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/morpheus/api/deployments_interface.rb', line 64 def destroy_file(deployment_id, id, destination, params={}) if destination.empty? || destination == "/" || destination == "." || destination.include?("../") raise "#{self.class}.upload_file() passed a bad destination: '#{destination}'" end # url = "#{@base_url}/#{base_path}/#{deployment_id}/versions/#{id}/files" url = "#{base_path}/#{deployment_id}/versions/#{id}/files" if !destination.to_s.empty? url += "/#{destination}" end # use URI to escape path uri = URI.parse(url) url = uri.path execute(method: :delete, url: url, params: params) end |
#destroy_version(deployment_id, id, params = {}) ⇒ Object
27 28 29 30 |
# File 'lib/morpheus/api/deployments_interface.rb', line 27 def destroy_version(deployment_id, id, params = {}) validate_id!(id) execute(method: :delete, url: "#{base_path}/#{deployment_id}/versions/#{id}", params: params) end |
#get_version(deployment_id, id, params = {}) ⇒ Object
13 14 15 16 |
# File 'lib/morpheus/api/deployments_interface.rb', line 13 def get_version(deployment_id, id, params={}) validate_id!(id) execute(method: :get, url: "#{base_path}/#{deployment_id}/versions/#{id}", params: params) end |
#list_files(deployment_id, id, params = {}) ⇒ Object
32 33 34 |
# File 'lib/morpheus/api/deployments_interface.rb', line 32 def list_files(deployment_id, id, params={}) execute(method: :get, url: "#{base_path}/#{deployment_id}/versions/#{id}/files", params: params) end |
#list_versions(deployment_id, params = {}) ⇒ Object
9 10 11 |
# File 'lib/morpheus/api/deployments_interface.rb', line 9 def list_versions(deployment_id, params={}) execute(method: :get, url: "#{base_path}/#{deployment_id}/versions", params: params) end |
#update_version(deployment_id, id, payload, params = {}) ⇒ Object
22 23 24 25 |
# File 'lib/morpheus/api/deployments_interface.rb', line 22 def update_version(deployment_id, id, payload, params={}) validate_id!(id) execute(method: :put, url: "#{base_path}/#{deployment_id}/versions/#{id}", params: params, payload: payload.to_json) end |
#upload_file(deployment_id, id, local_file, destination, params = {}) ⇒ Object
upload a file without multipart local_file is the full absolute local filename destination should be the full remote file path, including the file name.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/morpheus/api/deployments_interface.rb', line 39 def upload_file(deployment_id, id, local_file, destination, params={}) if destination.empty? || destination == "/" || destination == "." || destination.include?("../") raise "#{self.class}.upload_file() passed a bad destination: '#{destination}'" end # url = "#{@base_url}/#{base_path}/#{deployment_id}/versions/#{id}/files" url = "#{base_path}/#{deployment_id}/versions/#{id}/files" if !destination.to_s.empty? url += "/#{destination}" end # use URI to escape path uri = URI.parse(url) url = uri.path # params[:filename] = File.basename(destination) if !local_file.kind_of?(File) local_file = File.new(local_file, 'rb') end payload = local_file headers = {'Content-Type' => 'application/octet-stream'} headers['Content-Length'] = local_file.size # File.size(local_file) execute(method: :post, url: url, headers: headers, payload: payload, params: params, timeout: 172800) end |