Sha256: c86a0d7b3fc2e3bec8674e88a389adbf34e32e29ea80662183ea3cf831973225

Contents?: true

Size: 1.34 KB

Versions: 14

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require 'json'
module Bolt
  class Plugin
    class EnvVar
      class InvalidPluginData < Bolt::Plugin::PluginError
        def initialize(msg, plugin)
          msg = "Invalid Plugin Data for #{plugin}: #{msg}"
          super(msg, 'bolt/invalid-plugin-data')
        end
      end

      def initialize(*_args); end

      def name
        'env_var'
      end

      def hooks
        hook_descriptions.keys
      end

      def hook_descriptions
        {
          resolve_reference: 'Read values stored in environment variables.',
          validate_resolve_reference: nil
        }
      end

      def validate_resolve_reference(opts)
        unless opts['var']
          raise Bolt::ValidationError, "env_var plugin requires that the 'var' is specified"
        end
        return if opts['optional'] || opts['default']
        unless ENV[opts['var']]
          raise Bolt::ValidationError, "env_var plugin requires that the var '#{opts['var']}' be set"
        end
      end

      def resolve_reference(opts)
        reference = ENV[opts['var']]
        if opts['json'] && reference
          begin
            reference = JSON.parse(reference)
          rescue JSON::ParserError => e
            raise InvalidPluginData.new(e.message, name)
          end
        end
        reference || opts['default']
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
bolt-4.0.0 lib/bolt/plugin/env_var.rb
bolt-3.29.0 lib/bolt/plugin/env_var.rb
bolt-3.28.0 lib/bolt/plugin/env_var.rb
bolt-3.27.4 lib/bolt/plugin/env_var.rb
bolt-3.27.2 lib/bolt/plugin/env_var.rb
bolt-3.27.1 lib/bolt/plugin/env_var.rb
bolt-3.26.2 lib/bolt/plugin/env_var.rb
bolt-3.26.1 lib/bolt/plugin/env_var.rb
bolt-3.25.0 lib/bolt/plugin/env_var.rb
bolt-3.24.0 lib/bolt/plugin/env_var.rb
bolt-3.23.1 lib/bolt/plugin/env_var.rb
bolt-3.23.0 lib/bolt/plugin/env_var.rb
bolt-3.22.1 lib/bolt/plugin/env_var.rb
bolt-3.22.0 lib/bolt/plugin/env_var.rb