find usage for security groups
194627
def _find_usage_security_groups(self):
        """"""
        vpc_count = 0

        paginator = self.conn.get_paginator('describe_db_security_groups')
        for page in paginator.paginate():
            for group in page['DBSecurityGroups']:
                if 'VpcId' in group and group['VpcId'] is not None:
                    vpc_count += 1
                self.limits['Max auths per security group']._add_current_usage(
                    len(group["EC2SecurityGroups"]) + len(group["IPRanges"]),
                    aws_type='AWS::RDS::DBSecurityGroup',
                    resource_id=group['DBSecurityGroupName']
                )

        self.limits['VPC Security Groups']._add_current_usage(
            vpc_count,
            aws_type='AWS::RDS::DBSecurityGroup',
        )
56430
def _find_usage_ACLs(self):
        """"""
        # Network ACLs per VPC
        acls = defaultdict(int)
        for acl in self.conn.describe_network_acls()['NetworkAcls']:
            acls[acl['VpcId']] += 1
            # Rules per network ACL
            self.limits['Rules per network ACL']._add_current_usage(
                len(acl['Entries']),
                aws_type='AWS::EC2::NetworkAcl',
                resource_id=acl['NetworkAclId']
            )
        for vpc_id in acls:
            self.limits['Network ACLs per VPC']._add_current_usage(
                acls[vpc_id],
                aws_type='AWS::EC2::VPC',
                resource_id=vpc_id,
            )
1124299
def find_secgroup(self, name):
        
        groups = self.nova.security_groups.findall(name=name)
        if groups:
            return NovaSecGroup(groups[0])
1338389
def _get_sg_ids(self):
        
        try:
            lambda_extras = self.settings['security_groups']['lambda_extras']
        except KeyError:
            lambda_extras = []

        security_groups = [self.app_name] + lambda_extras
        sg_ids = []
        for security_group in security_groups:
            sg_id = get_security_group_id(name=security_group, env=self.env, region=self.region)
            sg_ids.append(sg_id)
        return sg_ids
1333988
def cli(env, group_id, name, description):
    """"""
    mgr = SoftLayer.NetworkManager(env.client)
    data = {}
    if name:
        data['name'] = name
    if description:
        data['description'] = description

    if not mgr.edit_securitygroup(group_id, **data):
        raise exceptions.CLIAbort("Failed to edit security group")
1126515
def show_security_group(self, security_group, **_params):
        """"""
        return self.get(self.security_group_path % (security_group),
                        params=_params)
252468
def get_default_group(user):
    '''
    
    '''
    return grp.getgrgid(pwd.getpwnam(user).pw_gid).gr_name \
        if HAS_GRP and HAS_PWD \
        else None
888212
def file_groups(self):
        
        return [el.get('USE') for el in self._tree.getroot().findall('.//mets:fileGrp', NS)]
957689
def FindAnomalies(self):
    """"""
    for grp_name, group in iteritems(self.entry):
      shadow = self.shadow.get(grp_name)
      gshadows = self.gshadow_members.get(grp_name, [])
      if shadow is not None:
        diff = self.MemberDiff(group.members, "group", gshadows, "gshadow")
        if diff:
          msg = "Group/gshadow members differ in group: %s" % grp_name
          yield self._Anomaly(msg, diff)

    diff = self.MemberDiff(self.entry, "group", self.gshadow_members, "gshadow")
    if diff:
      yield self._Anomaly("Mismatched group and gshadow files.", diff)
454525
def get_group_permissions(self):
        
        if self._group_permissions is None:
            self._group_permissions = set()

            if self.settings.FIND_GROUP_PERMS:
                try:
                    self._load_group_permissions()
                except ldap.LDAPError as e:
                    results = ldap_error.send(self.backend.__class__,
                                              context='get_group_permissions',
                                              exception=e)
                    if len(results) == 0:
                        logger.warning("Caught LDAPError loading group permissions: %s",
                                       pprint.pformat(e))

        return self._group_permissions
466417
def securitygroupid(vm_):
    '''
    
    '''
    securitygroupid_set = set()
    securitygroupid_list = config.get_cloud_config_value(
        'securitygroupid',
        vm_,
        __opts__,
        search_global=False
    )
    # If the list is None, then the set will remain empty
    # If the list is already a set then calling 'set' on it is a no-op
    # If the list is a string, then calling 'set' generates a one-element set
    # If the list is anything else, stacktrace
    if securitygroupid_list:
        securitygroupid_set = securitygroupid_set.union(set(securitygroupid_list))

    securitygroupname_list = config.get_cloud_config_value(
        'securitygroupname', vm_, __opts__, search_global=False
    )
    if securitygroupname_list:
        if not isinstance(securitygroupname_list, list):
            securitygroupname_list = [securitygroupname_list]
        params = {'Action': 'DescribeSecurityGroups'}
        for sg in aws.query(params, location=get_location(),
                            provider=get_provider(), opts=__opts__, sigver='4'):
            if sg['groupName'] in securitygroupname_list:
                log.debug(
                    'AWS SecurityGroup ID of %s is %s',
                    sg['groupName'], sg['groupId']
                )
                securitygroupid_set.add(sg['groupId'])
    return list(securitygroupid_set)
707772
def _find_usage_vpcs(self):
        """"""
        # overall number of VPCs
        vpcs = self.conn.describe_vpcs()
        self.limits['VPCs']._add_current_usage(
            len(vpcs['Vpcs']),
            aws_type='AWS::EC2::VPC'
        )
821088
def _get_securitygroupname_id(securitygroupname_list):
    '''
    
    '''
    securitygroupid_set = set()
    if not isinstance(securitygroupname_list, list):
        securitygroupname_list = [securitygroupname_list]
    params = {'Action': 'DescribeSecurityGroups'}
    for sg in aws.query(params, location=get_location(),
                        provider=get_provider(), opts=__opts__, sigver='4'):
        if sg['groupName'] in securitygroupname_list:
            log.debug(
                'AWS SecurityGroup ID of %s is %s',
                sg['groupName'], sg['groupId']
            )
            securitygroupid_set.add(sg['groupId'])
    return list(securitygroupid_set)
1266576
def get_security_zones_activation(self) -> (bool, bool):
        
        internal_active = False
        external_active = False
        for g in self.groups:
            if isinstance(g, SecurityZoneGroup):
                if g.label == "EXTERNAL":
                    external_active = g.active
                elif g.label == "INTERNAL":
                    internal_active = g.active
        return internal_active, external_active
199524
function groupMembershipMiddleware(groups) {
		if (typeof groups === 'string') {
			groups = [groups];
		}
		return function hasGroupMembership(req, res, next) {
			if (req.locals.user) {
				const userGroups = req.locals.user.groups || [];
				for (let group of groups) {
					if (userGroups.indexOf(group) !== -1) {
						debug(`User has the '${group}' Group.`);
						return next();
					}
				}
			}
			debug(`User is not a member of one of [${groups.join(',')}] Group(s).`);
			next(new restifyErrors.ForbiddenError('No execute permissions on endpoint'));
		}
	}
1359308
def get_security_group_id(self, name):
        
        # Memoize entire list of groups
        if not hasattr(self, '_security_groups'):
            self._security_groups = {}
            for group in self.get_all_security_groups():
                self._security_groups[group.name] = group.id
        return self._security_groups[name]
501766
def list_security_groups_in_vpc(self, vpc_id=None):
        
        log = logging.getLogger(self.cls_logger + '.list_security_groups_in_vpc')
        if vpc_id is None and self.vpc_id is not None:
            vpc_id = self.vpc_id
        else:
            msg = 'Unable to determine VPC ID to use to create the Security Group'
            log.error(msg)
            raise EC2UtilError(msg)

        # Create a filter on the VPC ID
        filters = [
            {
                'Name': 'vpc-id',
                'Values': [vpc_id]
            }
        ]

        # Get a list of security groups in the VPC
        log.info('Querying for a list of security groups in VPC ID: {v}'.format(v=vpc_id))
        try:
            security_groups = self.client.describe_security_groups(DryRun=False, Filters=filters)
        except ClientError:
            _, ex, trace = sys.exc_info()
            msg = 'Unable to query AWS for a list of security groups in VPC ID: {v}\n{e}'.format(
                v=vpc_id, e=str(ex))
            raise AWSAPIError, msg, trace
        return security_groups