Module: Fog::Bouncer

Defined in:
lib/fog/bouncer.rb,
lib/fog/bouncer/cli.rb,
lib/fog/bouncer/group.rb,
lib/fog/bouncer/source.rb,
lib/fog/bouncer/sources.rb,
lib/fog/bouncer/version.rb,
lib/fog/bouncer/cli/diff.rb,
lib/fog/bouncer/security.rb,
lib/fog/bouncer/protocols.rb,
lib/fog/bouncer/group_manager.rb,
lib/fog/bouncer/ip_permissions.rb,
lib/fog/bouncer/source_manager.rb

Defined Under Namespace

Modules: CLI, IPPermissions, Logger, Protocols, Sources Classes: DefinitionNotFound, Group, GroupManager, Protocol, Security, Source, SourceBlockRequired, SourceManager

Constant Summary collapse

VERSION =
"0.2.7"

Class Method Summary collapse

Class Method Details

.aws_account_idObject

Public: An AWS account ID

Example

Fog::Bouncer.
# => "1234567890"

Returns a String



29
30
31
# File 'lib/fog/bouncer.rb', line 29

def self.
  ENV['AWS_ACCOUNT_ID']
end

.doorlistsObject

Public: The available doorlists

Example

Fog::Bouncer.doorlists
# => { :doorlist => Fog::Bouncer::Security }

Returns a Hash



41
42
43
# File 'lib/fog/bouncer.rb', line 41

def self.doorlists
  @doorlists ||= {}
end

.fogObject

Public: An establised fog AWS compute connection

Example

Fog::Bouncer.fog
# => Fog::AWS::Compute

Returns a Fog::AWS::Compute object



53
54
55
56
57
58
59
60
# File 'lib/fog/bouncer.rb', line 53

def self.fog
  @fog ||= Fog::Compute.new(
    :provider => "AWS",
    :region => (ENV['PROVIDER_REGION'] || 'us-east-1'),
    :aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'],
    :aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
  )
end

.instrument_with(logger) ⇒ Object

Public: Allows the user to specify a logger for the log messages that Fog::Bouncer produces.

logger = The object you want logs to be sent too

Examples

Fog::Bouncer.instrument_with(STDOUT.method(:puts))
# => #<Method: IO#puts>

Returns the logger object



73
74
75
# File 'lib/fog/bouncer.rb', line 73

def self.instrument_with(logger)
  @logger = logger
end

.load(file) ⇒ Object

Public: Load a file for evaluation

Example

Fog::Bouncer.load('/tmp/doorlist.rb')
# => Fog::Bouncer::Security

Returns a Fog::Bouncer::Security object



102
103
104
105
106
107
108
# File 'lib/fog/bouncer.rb', line 102

def self.load(file)
  if file && File.exists?(file)
    Fog::Bouncer.log(load: true, file: file) do
      instance_eval(File.read(file))
    end
  end
end

.log(data, &blk) ⇒ Object

Internal: Top level log method for use by Fog::Bouncer

data = Logging data (typically a hash) blk = block to execute

Returns the response from calling the logger with the arguments



83
84
85
# File 'lib/fog/bouncer.rb', line 83

def self.log(data, &blk)
  logger.call({ 'fog-bouncer' => true, 'pretending' => pretending? }.merge(data), &blk)
end

.loggerObject

Public: The logging location

Returns an Object



90
91
92
# File 'lib/fog/bouncer.rb', line 90

def self.logger
  @logger || Fog::Bouncer::Logger.method(:log)
end

.pretendObject

Public: Check the pretend state

Returns false or true if pretending



113
114
115
# File 'lib/fog/bouncer.rb', line 113

def self.pretend
  @pretend ||= false
end

.pretend!Object

Public: Start pretending

Returns true



142
143
144
# File 'lib/fog/bouncer.rb', line 142

def self.pretend!
  @pretend = true
end

.pretend=(value) ⇒ Object

Public: Set the pretend state

Returns the given state



135
136
137
# File 'lib/fog/bouncer.rb', line 135

def self.pretend=(value)
  @pretend = value
end

.pretending?Boolean

Public: Evaluate the pretend state

Returns true if pretending or false if not

Returns:

  • (Boolean)


149
150
151
# File 'lib/fog/bouncer.rb', line 149

def self.pretending?
  !!pretend
end

.resetObject

Public: Empty the doorlists

Returns an empty Hash



156
157
158
# File 'lib/fog/bouncer.rb', line 156

def self.reset
  @doorlists = {}
end

.security(name, &block) ⇒ Object

Public: Create a doorlist

Example

Fog::Bouncer.security :private do
  group "name", "description" do
    ...
  end
end
# => Fog::Bouncer::Security

Returns a Fog::Bouncer::Security object



172
173
174
175
176
# File 'lib/fog/bouncer.rb', line 172

def self.security(name, &block)
  Fog::Bouncer.log(security: true, name: name) do
    doorlists[name] = Fog::Bouncer::Security.new(name, specific_groups, &block)
  end
end

.specific_groupsObject



178
179
180
# File 'lib/fog/bouncer.rb', line 178

def self.specific_groups
  @specific_groups ||= []
end

.specific_groups=(groups) ⇒ Object



182
183
184
# File 'lib/fog/bouncer.rb', line 182

def self.specific_groups=(groups)
  @specific_groups = Array(groups)
end

.while_pretending(&block) ⇒ Object

Public: Pretend while evaluating the given block

Example

Fog::Bouncer.while_pretending do
  ...
end

Returns nothing



126
127
128
129
130
# File 'lib/fog/bouncer.rb', line 126

def self.while_pretending(&block)
  @pretend = true
  yield
  @pretend = false
end