class PdkSync::Configuration
Constants
- 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- PDKSYNC_FILE_NAME
- SUPPORTED_SCM_PLATFORMS
Public Class Methods
@param config_path [String] - the path to the pdk config file
# 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
Public Instance Methods
@param path [String] path to the pdksync config file in yaml format @return [Hash] the custom configuration as a hash
# 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
@return [Hash] - returns the access settings for gemfury account
# File lib/pdksync/configuration.rb, line 72 def gemfury_access_settings valid_access_token_gem_fury? @gemfury_access_token = access_token_gem_fury end
@return [Hash] - returns the access settings for git scm
# 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
# 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
@return [String] the path the pdksync config file, nil if not found
# 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
@return [String] return a rendered string for pdk to use the templates
# File lib/pdksync/configuration.rb, line 78 def templates "--template-url=#{pdk_templates_url} --template-ref=#{pdk_templates_ref}" end
Private Instance Methods
@return [String] the platform specific access token
# File lib/pdksync/configuration.rb, line 133 def access_token case git_platform when :github ENV['GITHUB_TOKEN'].freeze when :gitlab ENV['GITLAB_TOKEN'].freeze end end
@return [String] the gem_fury access token
# File lib/pdksync/configuration.rb, line 143 def access_token_gem_fury ENV['GEMFURY_TOKEN'].freeze end
@return [Boolean] true if the access token for the scm platform was supplied
# File lib/pdksync/configuration.rb, line 115 def valid_access_token? if access_token.nil? raise ArgumentError, "Git platform access token for #{git_platform.capitalize} not set"\ " - use 'export #{git_platform.upcase}_TOKEN=\"<your token>\"' to set" end true end
@return [Boolean] true if the access token for the gemfury was supplied
# File lib/pdksync/configuration.rb, line 124 def valid_access_token_gem_fury? if access_token_gem_fury.nil? raise 'Gemfury access token not set'\ " - use 'export GEMFURY_TOKEN=\"<your token>\"' to set" end true end
@return [Boolean] true if the supported platforms were specified correctly @param scm [Symbol] - the scm type (:github or :gitlab)
# File lib/pdksync/configuration.rb, line 106 def valid_scm?(scm) unless SUPPORTED_SCM_PLATFORMS.include?(scm) raise ArgumentError, "Unsupported Git hosting platform '#{scm}'."\ " Supported platforms are: #{SUPPORTED_SCM_PLATFORMS.join(', ')}" end true end