Class: JenkinsPipelineBuilder::CLI::Helper
- Inherits:
-
Object
- Object
- JenkinsPipelineBuilder::CLI::Helper
- Defined in:
- lib/jenkins_pipeline_builder/cli/helper.rb
Overview
This is the helper class that sets up the credentials from the command line parameters given and initializes the Jenkins Pipeline Builder.
Constant Summary collapse
- DEFAULT_FILE_FORMATS =
%w[rb json yml yaml].freeze
Class Attribute Summary collapse
-
.jenkins_api_creds ⇒ Object
Returns the value of attribute jenkins_api_creds.
Class Method Summary collapse
- .process_cli_creds(options) ⇒ Object
- .process_creds(options) ⇒ Object
- .process_creds_file(file) ⇒ Object
-
.setup(options) ⇒ JenkinsPipelineBuilder::Generator
Sets up the credentials and initializes the Jenkins Pipeline Builder.
- .valid_cli_creds?(options) ⇒ Boolean
Class Attribute Details
.jenkins_api_creds ⇒ Object
Returns the value of attribute jenkins_api_creds.
38 39 40 |
# File 'lib/jenkins_pipeline_builder/cli/helper.rb', line 38 def jenkins_api_creds @jenkins_api_creds end |
Class Method Details
.process_cli_creds(options) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/jenkins_pipeline_builder/cli/helper.rb', line 87 def self.process_cli_creds() self.jenkins_api_creds = {}.with_indifferent_access.merge if jenkins_api_creds[:server] =~ Resolv::AddressRegex jenkins_api_creds[:server_ip] = jenkins_api_creds.delete :server elsif jenkins_api_creds[:server] =~ URI::DEFAULT_PARSER.make_regexp jenkins_api_creds[:server_url] = jenkins_api_creds.delete :server else msg = "server given (#{jenkins_api_creds[:server]}) is neither a URL nor an IP." msg << ' Please pass either a valid IP address or valid URI' warn msg exit 1 end end |
.process_creds(options) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/jenkins_pipeline_builder/cli/helper.rb', line 58 def self.process_creds() default_file = find_default_file if [:debug] self.jenkins_api_creds = { username: :foo, password: :bar, server_ip: :baz } elsif valid_cli_creds? process_cli_creds() elsif [:creds_file] process_creds_file [:creds_file] elsif default_file process_creds_file default_file else msg = 'Credentials are not set. Please pass them as parameters or' msg << ' set them in the default credentials file' warn msg exit 1 end end |
.process_creds_file(file) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/jenkins_pipeline_builder/cli/helper.rb', line 80 def self.process_creds_file(file) return load File.(file) if file.end_with? 'rb' return self.jenkins_api_creds = JSON.parse(IO.read(File.(file))) if file.end_with? 'json' self.jenkins_api_creds = YAML.load_file(File.(file)) end |
.setup(options) ⇒ JenkinsPipelineBuilder::Generator
Sets up the credentials and initializes the Jenkins Pipeline Builder
49 50 51 52 53 54 55 56 |
# File 'lib/jenkins_pipeline_builder/cli/helper.rb', line 49 def self.setup() process_creds JenkinsPipelineBuilder.credentials = jenkins_api_creds generator = JenkinsPipelineBuilder.generator JenkinsPipelineBuilder.debug! if [:debug] generator end |
.valid_cli_creds?(options) ⇒ Boolean
76 77 78 |
# File 'lib/jenkins_pipeline_builder/cli/helper.rb', line 76 def self.valid_cli_creds?() [:username] && [:server] && ([:password] || [:password_base64]) end |