Class: Jenkins2::API::Credentials::Store::Domain::Proxy
- Inherits:
-
ResourceProxy
- Object
- ResourceProxy
- Jenkins2::API::Credentials::Store::Domain::Proxy
- Includes:
- RUD
- Defined in:
- lib/jenkins2/api/credentials.rb
Constant Summary collapse
- BOUNDARY =
'----Jenkins2RubyMultipartClient' + rand(1_000_000).to_s
Instance Attribute Summary
Attributes inherited from ResourceProxy
Instance Method Summary collapse
- #create(config_xml) ⇒ Object
- #create_(body, content_type = 'application/x-www-form-urlencoded') ⇒ Object
-
#create_secret_file(filename:, content:, **args) ⇒ Object
Creates a secret file credential.
-
#create_secret_text(**args) ⇒ Object
Creates a secret text credential.
-
#create_ssh(private_key:, **args) ⇒ Object
Creates ssh username with private key credentials.
-
#create_username_password(**args) ⇒ Object
Creates username and password credential.
-
#credential(id, params = {}) ⇒ Object
Returns credential as json.
Methods included from RUD
Methods inherited from ResourceProxy
#initialize, #method_missing, #raw, #respond_to_missing?, #subject
Constructor Details
This class inherits a constructor from Jenkins2::ResourceProxy
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Jenkins2::ResourceProxy
Instance Method Details
#create(config_xml) ⇒ Object
128 129 130 131 132 |
# File 'lib/jenkins2/api/credentials.rb', line 128 def create(config_xml) connection.post(build_path('createCredentials'), config_xml) do |req| req['Content-Type'] = 'text/xml' end.code == '200' end |
#create_(body, content_type = 'application/x-www-form-urlencoded') ⇒ Object
122 123 124 125 126 |
# File 'lib/jenkins2/api/credentials.rb', line 122 def create_(body, content_type='application/x-www-form-urlencoded') connection.post(build_path('createCredentials'), body) do |req| req['Content-Type'] = content_type end.code == '302' end |
#create_secret_file(filename:, content:, **args) ⇒ Object
Creates a secret file credential. Jenkins must have plain-credentials plugin installed, to use this functionality. Accepts hash with the following parameters.
scope
-
Scope of the credential. GLOBAL or SYSTEM
id
-
Id of the credential. Will be Generated by Jenkins, if not provided.
description
-
Human readable text, what this credential is used for.
filename
-
Name of the file.
content
-
File content.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/jenkins2/api/credentials.rb', line 87 def create_secret_file(filename:, content:, **args) body = "--#{BOUNDARY}\r\n"\ "Content-Disposition: form-data; name=\"file0\"; filename=\"#{filename}\"\r\n"\ "Content-Type: application/octet-stream\r\n\r\n"\ "#{content}\r\n"\ "--#{BOUNDARY}\r\n"\ "Content-Disposition: form-data; name=\"json\"\r\n\r\n"\ "#{{ '' => '2', credentials: args.merge( '$class' => 'org.jenkinsci.plugins.plaincredentials.impl.FileCredentialsImpl', 'file' => 'file0' ) }.to_json}"\ "\r\n\r\n--#{BOUNDARY}--\r\n" create_(body, "multipart/form-data, boundary=#{BOUNDARY}") end |
#create_secret_text(**args) ⇒ Object
Creates a secret text credential. Jenkins must have plain-credentials plugin installed, to use this functionality. Accepts hash with the following parameters.
scope
-
Scope of the credential. GLOBAL or SYSTEM
id
-
Id of the credential. Will be Generated by Jenkins, if not provided.
description
-
Human readable text, what this credential is used for.
secret
-
Some secret text.
70 71 72 73 74 75 76 77 78 |
# File 'lib/jenkins2/api/credentials.rb', line 70 def create_secret_text(**args) json_body = { '' => '3', credentials: args.merge( '$class' => 'org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl' ) }.to_json create_("json=#{::CGI.escape json_body}") end |
#create_ssh(private_key:, **args) ⇒ Object
Creates ssh username with private key credentials. Jenkins must have ssh-credentials plugin installed, to use this functionality. Accepts the following key-word parameters.
scope
-
Scope of the credential. GLOBAL or SYSTEM
id
-
Id of the credential. Will be Generated by Jenkins, if not provided.
description
-
Human readable text, what this credential is used for.
username
-
Ssh username.
private_key
-
Ssh private key, with new lines replaced by
\n
sequence. passphrase
-
Passphrase for the private key. Empty string, if not provided.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/jenkins2/api/credentials.rb', line 47 def create_ssh(private_key:, **args) json_body = { '' => '1', credentials: args.merge( privateKeySource: { value: '0', privateKey: private_key, 'stapler-class' => 'com.cloudbees.jenkins.plugins.sshcredentials.impl.'\ 'BasicSSHUserPrivateKey$DirectEntryPrivateKeySource' }, '$class' => 'com.cloudbees.jenkins.plugins.sshcredentials.impl.'\ 'BasicSSHUserPrivateKey' ) }.to_json create_("json=#{::CGI.escape json_body}") end |
#create_username_password(**args) ⇒ Object
Creates username and password credential. Accepts hash with the following parameters.
scope
-
Scope of the credential. GLOBAL or SYSTEM
id
-
Id of the credential. Will be Generated by Jenkins, if not provided.
description
-
Human readable text, what this credential is used for.
username
-
Username.
password
-
Password in plain text.
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/jenkins2/api/credentials.rb', line 111 def create_username_password(**args) json_body = { '' => '0', credentials: args.merge( '$class' => 'com.cloudbees.plugins.credentials.impl.'\ 'UsernamePasswordCredentialsImpl' ) }.to_json create_("json=#{::CGI.escape json_body}") end |
#credential(id, params = {}) ⇒ Object
Returns credential as json. Raises Net::HTTPNotFound, if no such credential
id
-
Credential’s id
136 137 138 139 |
# File 'lib/jenkins2/api/credentials.rb', line 136 def credential(id, params={}) path = build_path 'credential', id Credential::Proxy.new connection, path, params end |