Construct FirewallPolicy and FirewallPolicy instances from passed arguments
967392
def _get_firewall_policy(kwargs):
    '''
    
    '''
    fp_name = kwargs.get('name', None)
    fp_description = kwargs.get('description', None)
    firewallPolicy = FirewallPolicy(
        name=fp_name,
        description=fp_description
    )

    fpr_json = kwargs.get('rules', None)
    jdata = json.loads(fpr_json)
    rules = []
    for fwpr in jdata:
        firewallPolicyRule = FirewallPolicyRule()
        if 'protocol' in fwpr:
            firewallPolicyRule.rule_set['protocol'] = fwpr['protocol']
        if 'port_from' in fwpr:
            firewallPolicyRule.rule_set['port_from'] = fwpr['port_from']
        if 'port_to' in fwpr:
            firewallPolicyRule.rule_set['port_to'] = fwpr['port_to']
        if 'source' in fwpr:
            firewallPolicyRule.rule_set['source'] = fwpr['source']
        if 'action' in fwpr:
            firewallPolicyRule.rule_set['action'] = fwpr['action']
        if 'description' in fwpr:
            firewallPolicyRule.rule_set['description'] = fwpr['description']
        if 'port' in fwpr:
            firewallPolicyRule.rule_set['port'] = fwpr['port']
        rules.append(firewallPolicyRule)

    return {'firewall_policy': firewallPolicy, 'firewall_policy_rules': rules}
880454
private static ImmutableList<String> setCompilePolicyToByFile(ImmutableList<String> args) {
    for (String arg : args) {
      if (arg.startsWith("-XDcompilePolicy")) {
        String value = arg.substring(arg.indexOf('=') + 1);
        checkCompilePolicy(value);
        return args; // don't do anything if a valid policy is already set
      }
    }
    return ImmutableList.<String>builder().addAll(args).add("-XDcompilePolicy=byfile").build();
  }
153918
def from_argparse(cls, args):
        """"""
        settings = vars(args)
        settings['repository_name'] = settings.pop('repository')
        settings['cacert'] = settings.pop('cert')
        return cls(**settings)
384619
function createOwnerAccessPolicy(thingId, subject) {
  const thingOwnerPolicy = {
    id: thingId + "-" + subject + "-clrud-policy",
    effect: "allow",
    actions: [
      "dcd:actions:create",
      "dcd:actions:list",
      "dcd:actions:read",
      "dcd:actions:update",
      "dcd:actions:delete"
    ],
    subjects: [subject],
    resources: [
      "dcd:things:" + thingId,
      "dcd:things:" + thingId + ":properties",
      "dcd:things:" + thingId + ":properties:<.*>"
    ]
  };
  return policies.create(thingOwnerPolicy);
}
335489
def with_known_args(self, **kwargs):
    """"""
    argspec = inspect.getargspec(self.func)
    stored = {}
    for key, arg in six.iteritems(kwargs):
      if key in argspec.args or argspec.keywords:
        stored[key] = arg
    if stored:
      return self.with_args(**stored)
    return self
707997
def clone(self, **kw):
        
        newpolicy = self.__class__.__new__(self.__class__)
        for attr, value in self.__dict__.items():
            object.__setattr__(newpolicy, attr, value)
        for attr, value in kw.items():
            if not hasattr(self, attr):
                raise TypeError(
                    "{!r} is an invalid keyword argument for {}".format(
                        attr, self.__class__.__name__))
            object.__setattr__(newpolicy, attr, value)
        return newpolicy
876689
def get_args(request_args, allowed_int_args=[], allowed_str_args=[]):
    """"""
    args = {}

    for allowed_int_arg in allowed_int_args:
        int_value = request_args.get(allowed_int_arg, default=None, type=None)
        if int_value:
            args[allowed_int_arg] = int(int_value)

    for allowed_str_arg in allowed_str_args:
        str_value = request_args.get(allowed_str_arg, default=None, type=None)
        if str_value:
            args[allowed_str_arg] = str_value

    return args
734466
function validArguments() {
    var conditions = {
      'port and host': function () {
        return port && host;
      },
      'options.target or options.router': function () {
        return options && (options.router ||
          (options.target && options.target.host && options.target.port));
      },
      'or proxy handlers': function () {
        return handlers && handlers.length;
      }
    }

    var missing = Object.keys(conditions).filter(function (name) {
      return !conditions[name]();
    });

    if (missing.length === 3) {
      message = 'Cannot proxy without ' + missing.join(', ');
      return false;
    }

    return true;
  }
1024911
def _build_tmp_access_args(method, ip, ttl, port, direction, comment):
    '''
    
    '''
    opt = _get_opt(method)
    args = '{0} {1} {2}'.format(opt, ip, ttl)
    if port:
        args += ' -p {0}'.format(port)
    if direction:
        args += ' -d {0}'.format(direction)
    if comment:
        args += ' #{0}'.format(comment)
    return args
858277
function createPolicy (params, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const { id, version, name, organizationId, statements } = params

      Joi.validate({ id, version, name, organizationId, statements }, validationRules.createPolicy, function (err) {
        if (err) return cb(Boom.badRequest(err))
        insertPolicies(db, [{
          id: id,
          version: version,
          name: name,
          org_id: organizationId,
          statements: statements
        }], (err, result) => {
          if (utils.isUniqueViolationError(err)) return cb(Boom.conflict('policy already exists'))
          if (err) return cb(Boom.badImplementation(err))

          policyOps.readPolicy({ id: result.rows[0].id, organizationId }, cb)
        })
      })

      return promise
    }
963296
def _add_common_args(parser, is_create=True):
    
    parser.add_argument(
        '--name',
        help=_('Name for the firewall rule.'))
    parser.add_argument(
        '--description',
        help=_('Description for the firewall rule.'))
    parser.add_argument(
        '--source-ip-address',
        help=_('Source IP address or subnet.'))
    parser.add_argument(
        '--destination-ip-address',
        help=_('Destination IP address or subnet.'))
    parser.add_argument(
        '--source-port',
        help=_('Source port (integer in [1, 65535] or range in a:b).'))
    parser.add_argument(
        '--destination-port',
        help=_('Destination port (integer in [1, 65535] or range in '
               'a:b).'))
    utils.add_boolean_argument(
        parser, '--enabled', dest='enabled',
        help=_('Whether to enable or disable this rule.'))
    parser.add_argument(
        '--protocol', choices=['tcp', 'udp', 'icmp', 'any'],
        required=is_create,
        type=utils.convert_to_lowercase,
        help=_('Protocol for the firewall rule.'))
    parser.add_argument(
        '--action',
        required=is_create,
        type=utils.convert_to_lowercase,
        choices=['allow', 'deny', 'reject'],
        help=_('Action for the firewall rule.'))
548634
function parseArguments(args) {
        var defaultConfig = {
            stateKey: 'instances',
            instanceKey: 'id'
        };

        if (typeof args[0] === 'function') {
            return {
                callback: args[0],
                config: defaultConfig
            };
        } else {
            return {
                callback: args[1],
                config: Object.assign({}, defaultConfig, args[0])
            };
        }
    }
570108
def get_construct_args
      args = []

      argument_map do |pspec, argument_class, argument_instance|
        flags = argument_class[:flags]
        if (flags & ARGUMENT_CONSTRUCT) != 0
          # names can include - as punctuation, but we always use _ in
          # Ruby
          name = pspec[:name].tr("-", "_")

          args << [name, flags]
        end
      end

      return args
    end
1074355
def create_fwrule(kwargs=None, call=None):
    '''
    
    '''
    if call != 'function':
        raise SaltCloudSystemExit(
            'The create_fwrule function must be called with -f or --function.'
        )

    if not kwargs or 'name' not in kwargs:
        log.error(
            'A name must be specified when creating a firewall rule.'
        )
        return False
    if 'allow' not in kwargs:
        log.error(
            'Must use "allow" to specify allowed protocols/ports.'
        )
        return False

    name = kwargs['name']
    network_name = kwargs.get('network', 'default')
    allow = _parse_allow(kwargs['allow'])
    src_range = kwargs.get('src_range', '0.0.0.0/0')
    src_tags = kwargs.get('src_tags', None)
    dst_tags = kwargs.get('dst_tags', None)

    if src_range:
        src_range = src_range.split(',')
    if src_tags:
        src_tags = src_tags.split(',')
    if dst_tags:
        dst_tags = dst_tags.split(',')
    conn = get_conn()

    __utils__['cloud.fire_event'](
        'event',
        'create firewall',
        'salt/cloud/firewall/creating',
        args={
            'name': name,
            'network': network_name,
            'allow': kwargs['allow'],
        },
        sock_dir=__opts__['sock_dir'],
        transport=__opts__['transport']
    )

    fwrule = conn.ex_create_firewall(
        name, allow,
        network=network_name,
        source_ranges=src_range,
        source_tags=src_tags,
        target_tags=dst_tags
    )

    __utils__['cloud.fire_event'](
        'event',
        'created firewall',
        'salt/cloud/firewall/created',
        args={
            'name': name,
            'network': network_name,
            'allow': kwargs['allow'],
        },
        sock_dir=__opts__['sock_dir'],
        transport=__opts__['transport']
    )
    return _expand_item(fwrule)
963562
def passing(self, *args, **kwargs):
        
        self.args = args
        self.kwargs = kwargs
        return self
778201
function loadPolicies() {
  const policyConfigsPath = path.join(process.cwd(), plugin.config.policiesPath);

  // This event allows to inject code before loading all APIs
  return plugin.myrmex.fire('beforePoliciesLoad')
  .then(() => {
    // Retrieve configuration path of all API specifications
    return fs.readdirAsync(policyConfigsPath);
  })
  .then(policyConfigFiles => {
    // Load all the policy configurations
    const policyPromises = [];
    _.forEach(policyConfigFiles, (filename) => {
      const policyConfigPath = path.join(policyConfigsPath, filename);
      const policyName = path.parse(filename).name;
      policyPromises.push(loadPolicy(policyConfigPath, policyName));
    });
    return Promise.all(policyPromises);
  })
  .then(policies => {
    // This event allows to inject code to add or delete or alter policy configurations
    return plugin.myrmex.fire('afterPoliciesLoad', policies);
  })
  .spread(policies => {
    return Promise.resolve(policies);
  })
  .catch(e => {
    if (e.code === 'ENOENT' && path.basename(e.path) === 'policies') {
      return Promise.resolve([]);
    }
    return Promise.reject(e);
  });
}
419064
function get_args( args, fn_curr, fn_prev ) {
		if ( args.length && OP.toString.call( args[0] ) === '[object Arguments]' ) {
			if ( args.length < 2 && arguments.length > 1 ) {
				if ( fn_curr in internal_method_names )
					return get_args( args[0] );
				if ( fn_prev && fn_curr === fn_prev )
					return args[0];
			}
		}
		return args;
	}