Method: Fog::AWS::RDS::Mock#authorize_db_security_group_ingress

Defined in:
lib/fog/aws/requests/rds/authorize_db_security_group_ingress.rb

#authorize_db_security_group_ingress(name, opts = {}) ⇒ Object

[View source]

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fog/aws/requests/rds/authorize_db_security_group_ingress.rb', line 35

def authorize_db_security_group_ingress(name, opts = {})
  unless opts.key?('CIDRIP') || (opts.key?('EC2SecurityGroupName') && opts.key?('EC2SecurityGroupOwnerId'))
    raise ArgumentError, 'Must specify CIDRIP, or both EC2SecurityGroupName and EC2SecurityGroupOwnerId'
  end
  
  response = Excon::Response.new
  
  if sec_group = self.data[:security_groups][name]
    if opts.key?('CIDRIP')
      if sec_group['IPRanges'].detect{|h| h['CIDRIP'] == opts['CIDRIP']}
        raise Fog::AWS::RDS::AuthorizationAlreadyExists.new("AuthorizationAlreadyExists => #{opts['CIDRIP']} is alreay defined")
      end
      sec_group['IPRanges'] << opts.merge({"Status" => 'authorizing'})
    else
      if sec_group['EC2SecurityGroups'].detect{|h| h['EC2SecurityGroupName'] == opts['EC2SecurityGroupName']}
        raise Fog::AWS::RDS::AuthorizationAlreadyExists.new("AuthorizationAlreadyExists => #{opts['EC2SecurityGroupName']} is alreay defined")
      end
      sec_group['EC2SecurityGroups'] << opts.merge({"Status" => 'authorizing'})
    end
    response.status = 200
    response.body = {
      "ResponseMetadata"=>{ "RequestId"=> Fog::AWS::Mock.request_id },
      'AuthorizeDBSecurityGroupIngressResult' => {          
        'DBSecurityGroup' => sec_group
      }
    }
    response
  else
    raise Fog::AWS::RDS::NotFound.new("DBSecurityGroupNotFound => #{name} not found")
  end
  
end