Class: LambdaWrap::Environment

Inherits:
Object
  • Object
show all
Defined in:
lib/lambda_wrap/environment.rb

Overview

Environment class to pass to the deploy and teardown

Since:

  • 1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, variables = {}, description = 'Managed by LambdaWrap') ⇒ Environment

Constructor

Parameters:

  • name (String)

    Name of the environment. Corresponds to the Lambda Alias and API Gateway Stage. Must be at least 3 characters, and no more than 20 characters.

  • variables (Hash) (defaults to: {})

    Environment variables to pass to the API Gateway stage. Must be a flat hash. Each key must be Alphanumeric (underscores allowed) and no more than 64 characters. Values can have most special characters, and no more than 512 characters.

  • description (String) (defaults to: 'Managed by LambdaWrap')

    Description of the environment for Stage & Alias descriptions. Must not exceed 256 characters.

Raises:

  • (ArgumentError)

Since:

  • 1.0



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/lambda_wrap/environment.rb', line 28

def initialize(name, variables = {}, description = 'Managed by LambdaWrap')
  raise ArgumentError, 'name must be provided (String)!' unless name && name.is_a?(String)
  # Max Alias Name length is 20 characters.
  raise ArgumentError, "Invalid name format: #{name}" unless /^[a-zA-Z0-9\-\_]{3,20}$/ =~ name
  @name = name

  raise ArgumentError, 'Variables must be a Hash!' unless variables.is_a?(Hash)
  variables.each do |key, value|
    next if /^[0-9a-zA-Z\_]{1,64}$/ =~ key && /^[A-Za-z0-9\-.\_~:\/?#&=,]{1,512}$/ =~ value && value.is_a?(String)
    raise ArgumentError, "Invalid Format of variables hash: #{key} => #{value}"
  end

  variables[:environment] = name unless variables[:environment]
  @variables = variables

  raise ArgumentError, 'Description must be a String!' unless description.is_a?(String)
  raise ArgumentError, 'Description too long (Max 256)' unless description.length < 256
  @description = description
end

Instance Attribute Details

#descriptionString (readonly)

Returns The description of the environment.

Returns:

  • (String)

    The description of the environment.

Since:

  • 1.0



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/lambda_wrap/environment.rb', line 14

class Environment
  attr_reader :name
  attr_reader :description
  attr_reader :variables

  # Constructor
  #
  # @param name [String] Name of the environment. Corresponds to the Lambda Alias and API Gateway Stage.
  #  Must be at least 3 characters, and no more than 20 characters.
  # @param variables [Hash] Environment variables to pass to the API Gateway stage. Must be a flat hash.
  #  Each key must be Alphanumeric (underscores allowed) and no more than 64 characters. Values can have
  #  most special characters, and no more than 512 characters.
  # @param description [String] Description of the environment for Stage & Alias descriptions. Must not
  #  exceed 256 characters.
  def initialize(name, variables = {}, description = 'Managed by LambdaWrap')
    raise ArgumentError, 'name must be provided (String)!' unless name && name.is_a?(String)
    # Max Alias Name length is 20 characters.
    raise ArgumentError, "Invalid name format: #{name}" unless /^[a-zA-Z0-9\-\_]{3,20}$/ =~ name
    @name = name

    raise ArgumentError, 'Variables must be a Hash!' unless variables.is_a?(Hash)
    variables.each do |key, value|
      next if /^[0-9a-zA-Z\_]{1,64}$/ =~ key && /^[A-Za-z0-9\-.\_~:\/?#&=,]{1,512}$/ =~ value && value.is_a?(String)
      raise ArgumentError, "Invalid Format of variables hash: #{key} => #{value}"
    end

    variables[:environment] = name unless variables[:environment]
    @variables = variables

    raise ArgumentError, 'Description must be a String!' unless description.is_a?(String)
    raise ArgumentError, 'Description too long (Max 256)' unless description.length < 256
    @description = description
  end

  def to_s
    return @name if @name && @name.is_a?(String)
    super
  end
end

#nameString (readonly)

Returns The descriptive name of the environment.

Returns:

  • (String)

    The descriptive name of the environment.

Since:

  • 1.0



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/lambda_wrap/environment.rb', line 14

class Environment
  attr_reader :name
  attr_reader :description
  attr_reader :variables

  # Constructor
  #
  # @param name [String] Name of the environment. Corresponds to the Lambda Alias and API Gateway Stage.
  #  Must be at least 3 characters, and no more than 20 characters.
  # @param variables [Hash] Environment variables to pass to the API Gateway stage. Must be a flat hash.
  #  Each key must be Alphanumeric (underscores allowed) and no more than 64 characters. Values can have
  #  most special characters, and no more than 512 characters.
  # @param description [String] Description of the environment for Stage & Alias descriptions. Must not
  #  exceed 256 characters.
  def initialize(name, variables = {}, description = 'Managed by LambdaWrap')
    raise ArgumentError, 'name must be provided (String)!' unless name && name.is_a?(String)
    # Max Alias Name length is 20 characters.
    raise ArgumentError, "Invalid name format: #{name}" unless /^[a-zA-Z0-9\-\_]{3,20}$/ =~ name
    @name = name

    raise ArgumentError, 'Variables must be a Hash!' unless variables.is_a?(Hash)
    variables.each do |key, value|
      next if /^[0-9a-zA-Z\_]{1,64}$/ =~ key && /^[A-Za-z0-9\-.\_~:\/?#&=,]{1,512}$/ =~ value && value.is_a?(String)
      raise ArgumentError, "Invalid Format of variables hash: #{key} => #{value}"
    end

    variables[:environment] = name unless variables[:environment]
    @variables = variables

    raise ArgumentError, 'Description must be a String!' unless description.is_a?(String)
    raise ArgumentError, 'Description too long (Max 256)' unless description.length < 256
    @description = description
  end

  def to_s
    return @name if @name && @name.is_a?(String)
    super
  end
end

#variablesHash (readonly)

Returns The Hash of environment variables to deploy with the environment.

Returns:

  • (Hash)

    The Hash of environment variables to deploy with the environment.

Since:

  • 1.0



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/lambda_wrap/environment.rb', line 14

class Environment
  attr_reader :name
  attr_reader :description
  attr_reader :variables

  # Constructor
  #
  # @param name [String] Name of the environment. Corresponds to the Lambda Alias and API Gateway Stage.
  #  Must be at least 3 characters, and no more than 20 characters.
  # @param variables [Hash] Environment variables to pass to the API Gateway stage. Must be a flat hash.
  #  Each key must be Alphanumeric (underscores allowed) and no more than 64 characters. Values can have
  #  most special characters, and no more than 512 characters.
  # @param description [String] Description of the environment for Stage & Alias descriptions. Must not
  #  exceed 256 characters.
  def initialize(name, variables = {}, description = 'Managed by LambdaWrap')
    raise ArgumentError, 'name must be provided (String)!' unless name && name.is_a?(String)
    # Max Alias Name length is 20 characters.
    raise ArgumentError, "Invalid name format: #{name}" unless /^[a-zA-Z0-9\-\_]{3,20}$/ =~ name
    @name = name

    raise ArgumentError, 'Variables must be a Hash!' unless variables.is_a?(Hash)
    variables.each do |key, value|
      next if /^[0-9a-zA-Z\_]{1,64}$/ =~ key && /^[A-Za-z0-9\-.\_~:\/?#&=,]{1,512}$/ =~ value && value.is_a?(String)
      raise ArgumentError, "Invalid Format of variables hash: #{key} => #{value}"
    end

    variables[:environment] = name unless variables[:environment]
    @variables = variables

    raise ArgumentError, 'Description must be a String!' unless description.is_a?(String)
    raise ArgumentError, 'Description too long (Max 256)' unless description.length < 256
    @description = description
  end

  def to_s
    return @name if @name && @name.is_a?(String)
    super
  end
end

Instance Method Details

#to_sObject

Since:

  • 1.0



48
49
50
51
# File 'lib/lambda_wrap/environment.rb', line 48

def to_s
  return @name if @name && @name.is_a?(String)
  super
end