Class: PdkSync::Configuration
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- PdkSync::Configuration
- Defined in:
- lib/pdksync/configuration.rb
Constant Summary collapse
- SUPPORTED_SCM_PLATFORMS =
[:github, :gitlab].freeze
- PDKSYNC_FILE_NAME =
'pdksync.yml'.freeze
- DEFAULT_CONFIG =
Any key value added to the default config or custom config will automatically be a new configuration item and referenced via Configuration.new.<key_name> ie. c = Configuration.new c.api_endpoint
{ namespace: 'puppetlabs', pdksync_dir: 'modules_pdksync', pdksync_gem_dir: 'gems_pdksync', push_file_destination: 'origin', create_pr_against: 'main', managed_modules: 'managed_modules.yml', pdksync_label: 'maintenance', git_platform: :github, git_base_uri: 'https://github.com', gitlab_api_endpoint: 'https://gitlab.com/api/v4', api_endpoint: nil, pdk_templates_prefix: nil, pdk_templates_ref: PDK::VERSION, pdk_templates_url: 'https://github.com/puppetlabs/pdk-templates.git', jenkins_platform: :jenkins, jenkins_base_uri: 'https://jenkins.io', jenkins_api_endpoint: '', jenkins_server_url: '', module_is_authoritive: true }.freeze
Instance Method Summary collapse
-
#custom_config(path = nil) ⇒ Hash
The custom configuration as a hash.
-
#gemfury_access_settings ⇒ Hash
-
returns the access settings for gemfury account.
-
-
#git_platform_access_settings ⇒ Hash
-
returns the access settings for git scm.
-
-
#initialize(config_path = ) ⇒ Configuration
constructor
A new instance of Configuration.
- #jenkins_platform_access_settings ⇒ Object
-
#locate_config_path(custom_file = nil) ⇒ String
The path the pdksync config file, nil if not found.
-
#templates ⇒ String
Return a rendered string for pdk to use the templates.
Constructor Details
#initialize(config_path = ) ⇒ Configuration
Returns a new instance of Configuration.
44 45 46 47 48 49 50 51 |
# File 'lib/pdksync/configuration.rb', line 44 def initialize(config_path = ENV['PDKSYNC_CONFIG_PATH']) @config_path = locate_config_path(config_path) @custom_config = DEFAULT_CONFIG.merge(custom_config(@config_path)) @custom_config[:pdk_templates_ref] = "#{@custom_config[:pdk_templates_prefix]}#{@custom_config[:pdk_templates_ref]}" super(@custom_config) valid_scm?(git_platform) valid_access_token? end |
Instance Method Details
#custom_config(path = nil) ⇒ Hash
Returns the custom configuration as a hash.
84 85 86 87 88 89 90 |
# File 'lib/pdksync/configuration.rb', line 84 def custom_config(path = nil) return {} unless path return {} unless File.exist?(path) c = (YAML.load_file(path) || {}).transform_keys_to_symbols c[:git_base_uri] ||= 'https://gitlab.com' if c[:git_platform].eql?(:gitlab) c end |
#gemfury_access_settings ⇒ Hash
Returns - returns the access settings for gemfury account.
72 73 74 75 |
# File 'lib/pdksync/configuration.rb', line 72 def gemfury_access_settings valid_access_token_gem_fury? @gemfury_access_token = access_token_gem_fury end |
#git_platform_access_settings ⇒ Hash
Returns - returns the access settings for git scm.
54 55 56 57 58 59 60 61 |
# File 'lib/pdksync/configuration.rb', line 54 def git_platform_access_settings @git_platform_access_settings ||= { access_token: access_token, gitlab_api_endpoint: gitlab_api_endpoint || api_endpoint, api_endpoint: api_endpoint } end |
#jenkins_platform_access_settings ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/pdksync/configuration.rb', line 63 def jenkins_platform_access_settings @jenkins_platform_access_settings ||= { jenkins_username: ENV['JENKINS_USERNAME'].freeze, jenkins_password: ENV['JENKINS_PASSWORD'].freeze, jenkins_api_endpoint: '' } end |
#locate_config_path(custom_file = nil) ⇒ String
Returns the path the pdksync config file, nil if not found.
93 94 95 96 97 98 99 100 |
# File 'lib/pdksync/configuration.rb', line 93 def locate_config_path(custom_file = nil) files = [ custom_file, PDKSYNC_FILE_NAME, File.join(ENV['HOME'], PDKSYNC_FILE_NAME) ] files.find { |file| file && File.exist?(file) } end |
#templates ⇒ String
Return a rendered string for pdk to use the templates
78 79 80 |
# File 'lib/pdksync/configuration.rb', line 78 def templates "--template-url=#{pdk_templates_url} --template-ref=#{pdk_templates_ref}" end |