当前位置: 首页>>代码示例>>Java>>正文


Java AuthorizeSecurityGroupIngressRequest类代码示例

本文整理汇总了Java中com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest的典型用法代码示例。如果您正苦于以下问题:Java AuthorizeSecurityGroupIngressRequest类的具体用法?Java AuthorizeSecurityGroupIngressRequest怎么用?Java AuthorizeSecurityGroupIngressRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AuthorizeSecurityGroupIngressRequest类属于com.amazonaws.services.ec2.model包,在下文中一共展示了AuthorizeSecurityGroupIngressRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createSecurityGroupByClusterName

import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest; //导入依赖的package包/类
private void createSecurityGroupByClusterName(String GROUP_NAME) {
	System.out.println("Creating security group for cluster "+name);
	CreateSecurityGroupRequest csgr = new CreateSecurityGroupRequest();

	csgr.withGroupName(GROUP_NAME).withDescription("AWS Cluster toolkit security group");
	CreateSecurityGroupResult createSecurityGroupResult =ec2.createSecurityGroup(csgr);

	IpPermission ipPermission =
			new IpPermission();

	IpRange ipRange1 = new IpRange().withCidrIp("0.0.0.0/0");


	ipPermission.withIpv4Ranges(Arrays.asList(new IpRange[] {ipRange1}))
	.withIpProtocol("tcp")
	.withFromPort(0)
	.withToPort(65535);
	AuthorizeSecurityGroupIngressRequest authorizeSecurityGroupIngressRequest =
			new AuthorizeSecurityGroupIngressRequest();

	authorizeSecurityGroupIngressRequest.withGroupName(GROUP_NAME)
	.withIpPermissions(ipPermission);
	ec2.authorizeSecurityGroupIngress(authorizeSecurityGroupIngressRequest);
	System.out.println("Created new security group "+GROUP_NAME+" with /usr/bin/ssh enabled.");

}
 
开发者ID:spagnuolocarmine,项目名称:aws-cluster-toolkit,代码行数:27,代码来源:AwsClusterManager.java

示例2: addIngressRules

import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest; //导入依赖的package包/类
public void addIngressRules(String groupId, List<IpPermission> rules) {
    if (CollectionUtils.isNotEmpty(rules)) {
        AuthorizeSecurityGroupIngressRequest req = new AuthorizeSecurityGroupIngressRequest()
                .withGroupId(groupId).withIpPermissions(rules);
        try {
            this.client.authorizeSecurityGroupIngress(req);
        } catch (AmazonEC2Exception e) {
            if (e.getErrorCode().equals(SECURITY_GROUP_RULE_DUPLICATE)) {
                Utils.log(AWSUtils.class, AWSUtils.class.getSimpleName(),
                        Level.WARNING, () -> String
                                .format("Ingress rules already exist: %s", Utils.toString(e)));
            } else {
                throw e;
            }
        }
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:18,代码来源:AWSSecurityGroupClient.java

示例3: authorizeTcpAndSshIngressTraffic

import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest; //导入依赖的package包/类
protected void authorizeTcpAndSshIngressTraffic(String groupName)
{
    LOG.debug("Adding a TCP ingress rule for the security group [{}].", groupName);
    
    AuthorizeSecurityGroupIngressRequest authorizeSecurityGroupIngressRequest = new AuthorizeSecurityGroupIngressRequest()
            .withFromPort(0)
            .withToPort(65535)
            .withIpProtocol("tcp")
            .withGroupName(groupName)
            .withCidrIp("0.0.0.0/0");
    
    ec2_.authorizeSecurityGroupIngress(authorizeSecurityGroupIngressRequest);
    
    LOG.debug("The following ingress rule was created. Security group [{}], protocol [{}] from port [{}] to port [{}] and " +
    		"CIDR IP address [{}], region [{}]",
            authorizeSecurityGroupIngressRequest.getGroupName(),
            authorizeSecurityGroupIngressRequest.getIpProtocol(),
            authorizeSecurityGroupIngressRequest.getFromPort(), 
            authorizeSecurityGroupIngressRequest.getToPort(),
            authorizeSecurityGroupIngressRequest.getCidrIp(),
            DEFAULT_API_REGION.getName());
    
    authorizeSecurityGroupIngressRequest.withFromPort(22).withToPort(22);
    ec2_.authorizeSecurityGroupIngress(authorizeSecurityGroupIngressRequest);
    
}
 
开发者ID:alessandroleite,项目名称:dohko,代码行数:27,代码来源:EC2.java

示例4: addPermissionsToSecurityGroup

import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest; //导入依赖的package包/类
/***
 * Open firewall for a security group
 *
 * @param groupName Open firewall for this security group
 * @param ipRanges Open firewall for this IP range
 * @param ipProtocol Open firewall for this protocol type (eg. tcp, udp)
 * @param fromPort Open firewall for port range starting at this port
 * @param toPort Open firewall for port range ending at this port
 */
public void addPermissionsToSecurityGroup(String groupName,
    String ipRanges,
    String ipProtocol,
    Integer fromPort,
    Integer toPort) {

  final AmazonEC2 amazonEC2 = getEc2Client();

  final IpPermission ipPermission = new IpPermission()
      .withIpRanges(ipRanges)
      .withIpProtocol(ipProtocol)
      .withFromPort(fromPort)
      .withToPort(toPort);
  final AuthorizeSecurityGroupIngressRequest authorizeSecurityGroupIngressRequest =
      new AuthorizeSecurityGroupIngressRequest()
          .withGroupName(groupName)
          .withIpPermissions(ipPermission);
  amazonEC2.authorizeSecurityGroupIngress(authorizeSecurityGroupIngressRequest);

  LOGGER.info("Added permissions: " + ipPermission + " to security group: " + groupName);
}
 
开发者ID:apache,项目名称:incubator-gobblin,代码行数:31,代码来源:AWSSdkClient.java

示例5: addRules

import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest; //导入依赖的package包/类
@Override
public void addRules( final String name, final Collection<String> ipRanges, final String protocol,
                      final int fromPort, final int toPort ) {

    IpPermission ipPermission = new IpPermission();

    ipPermission.withIpRanges( ipRanges )
                .withIpProtocol( protocol )
                .withFromPort( fromPort )
                .withToPort( toPort );

    try {
        AuthorizeSecurityGroupIngressRequest request = new AuthorizeSecurityGroupIngressRequest();
        request = request.withGroupName( name ).withIpPermissions( ipPermission );
        client.authorizeSecurityGroupIngress( request );
    }
    catch ( Exception e ) {
        LOG.error( "Error whilt adding rule to security group: {}", name, e );
    }
}
 
开发者ID:apache,项目名称:usergrid,代码行数:21,代码来源:AmazonIpRuleManager.java

示例6: addIngressRulesAsync

import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest; //导入依赖的package包/类
public DeferredResult<Void> addIngressRulesAsync(String groupId, List<IpPermission> rules) {
    if (CollectionUtils.isNotEmpty(rules)) {
        AuthorizeSecurityGroupIngressRequest req = new AuthorizeSecurityGroupIngressRequest()
                .withGroupId(groupId).withIpPermissions(rules);

        String message = "Create Ingress Rules on AWS Security Group with id [" + groupId +
                "].";

        AWSDeferredResultAsyncHandler<AuthorizeSecurityGroupIngressRequest,
                AuthorizeSecurityGroupIngressResult>
                handler = new AWSDeferredResultAsyncHandler<AuthorizeSecurityGroupIngressRequest,
                AuthorizeSecurityGroupIngressResult>(this.service, message) {

                    @Override
                    protected Exception consumeError(Exception e) {
                        if (e instanceof AmazonEC2Exception &&
                                ((AmazonEC2Exception)e).getErrorCode().equals
                                        (SECURITY_GROUP_RULE_DUPLICATE)) {
                            Utils.log(AWSUtils.class, AWSUtils.class.getSimpleName(),
                                    Level.WARNING, () -> String
                                            .format("Ingress rules already exist: %s",
                                                    Utils.toString(e)));
                            return null;
                        } else {
                            return e;
                        }
                    }
                };
        this.client.authorizeSecurityGroupIngressAsync(req, handler);
        return handler.toDeferredResult()
                .thenApply(r -> (Void)null);
    } else {
        return DeferredResult.completed(null);
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:36,代码来源:AWSSecurityGroupClient.java

示例7: addInnerIngressRule

import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest; //导入依赖的package包/类
public DeferredResult<Void> addInnerIngressRule(String securityGroupId) {
    AuthorizeSecurityGroupIngressRequest req = new AuthorizeSecurityGroupIngressRequest()
            .withGroupId(securityGroupId)
            .withIpPermissions(Collections.singletonList(buildInnerRule(securityGroupId)));

    String message = "Create internal Ingress Rule on AWS Security Group with id [" +
            securityGroupId + "].";

    AWSDeferredResultAsyncHandler<AuthorizeSecurityGroupIngressRequest,
            AuthorizeSecurityGroupIngressResult>
            handler = new AWSDeferredResultAsyncHandler<AuthorizeSecurityGroupIngressRequest,
            AuthorizeSecurityGroupIngressResult>(this.service, message) {

                @Override
                protected Exception consumeError(Exception e) {
                    if (e instanceof AmazonEC2Exception &&
                            ((AmazonEC2Exception)e).getErrorCode().equals
                                    (SECURITY_GROUP_RULE_DUPLICATE)) {
                        Utils.log(AWSUtils.class, AWSUtils.class.getSimpleName(),
                                Level.WARNING, () -> String
                                        .format("Ingress rule already exists: %s",
                                                Utils.toString(e)));
                        return null;
                    } else {
                        return e;
                    }
                }
            };
    this.client.authorizeSecurityGroupIngressAsync(req, handler);
    return handler.toDeferredResult()
            .thenApply(r -> (Void)null);
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:33,代码来源:AWSSecurityGroupClient.java

示例8: run

import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest; //导入依赖的package包/类
@Override
public void run(final WhitelistCidrForVpcAccessCommand command) {
    final BaseOutputs baseStackOutputs = configStore.getBaseStackOutputs();

    logger.info("Revoking the previous ingress rules...");
    final DescribeSecurityGroupsResult securityGroupsResult = ec2Client.describeSecurityGroups(
            new DescribeSecurityGroupsRequest().withGroupIds(baseStackOutputs.getToolsIngressSgId()));
    securityGroupsResult.getSecurityGroups().forEach(securityGroup -> {
        if (!securityGroup.getIpPermissions().isEmpty()) {
            RevokeSecurityGroupIngressRequest revokeIngressRequest = new RevokeSecurityGroupIngressRequest()
                    .withGroupId(baseStackOutputs.getToolsIngressSgId())
                    .withIpPermissions(securityGroup.getIpPermissions());
            ec2Client.revokeSecurityGroupIngress(revokeIngressRequest);
        }
    });
    logger.info("Done.");

    logger.info("Authorizing the new ingress rules...");
    final List<IpPermission> ipPermissionList = Lists.newArrayListWithCapacity(command.getPorts().size());
    command.getPorts().forEach(port -> {
        IpPermission ipPermission = new IpPermission()
                .withIpRanges(command.getCidrs())
                .withIpProtocol("tcp")
                .withFromPort(port)
                .withToPort(port);

        ipPermissionList.add(ipPermission);
    });

    AuthorizeSecurityGroupIngressRequest ingressRequest = new AuthorizeSecurityGroupIngressRequest()
            .withGroupId(baseStackOutputs.getToolsIngressSgId())
            .withIpPermissions(ipPermissionList);
    ec2Client.authorizeSecurityGroupIngress(ingressRequest);
    logger.info("Done.");
}
 
开发者ID:Nike-Inc,项目名称:cerberus-lifecycle-cli,代码行数:36,代码来源:WhitelistCidrForVpcAccessOpertaion.java

示例9: createSGIngressRules

import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest; //导入依赖的package包/类
public void createSGIngressRules(String securityGroupId, List<IpPermission> rules) {
    logger.info("create ingress sg rules, sgId={}, rules={}", securityGroupId, rules);

    ec2.authorizeSecurityGroupIngress(new AuthorizeSecurityGroupIngressRequest()
        .withGroupId(securityGroupId)
        .withIpPermissions(rules));
}
 
开发者ID:neowu,项目名称:cmn-project,代码行数:8,代码来源:EC2.java

示例10: openPort

import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest; //导入依赖的package包/类
public void openPort(String securityGroup, int port) {
  IpPermission permission = new IpPermission().withIpProtocol("tcp") //$NON-NLS-1$
      .withFromPort(port).withToPort(port).withIpRanges("0.0.0.0/0"); //$NON-NLS-1$

  AuthorizeSecurityGroupIngressRequest request =
      new AuthorizeSecurityGroupIngressRequest().withGroupName(securityGroup).withIpPermissions(
          permission);

  getClient().authorizeSecurityGroupIngress(request);
}
 
开发者ID:tuhrig,项目名称:DeployMan,代码行数:11,代码来源:Ec2.java

示例11: authorizeIngressRules

import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest; //导入依赖的package包/类
@Test
public void authorizeIngressRules() {
  amazonEc2.setRegion(region);
  amazonEc2.authorizeSecurityGroupIngress(new AuthorizeSecurityGroupIngressRequest(
      "securityGroupName", ImmutableList.of(ipPermission(7000, "1.1.1.1/32", "2.2.2.2/32"))));
  replayAll();
  service().authorizeIngressRules("securityGroupName", "dc1",
      groupPermission(7000, "1.1.1.1/32", "2.2.2.2/32"));
}
 
开发者ID:signal,项目名称:agathon,代码行数:10,代码来源:Ec2SecurityGroupServiceTest.java

示例12: authorizeIngressRules

import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest; //导入依赖的package包/类
private void authorizeIngressRules(AmazonEC2 client, String groupName, Set<IpPermission> ipPermissions) {
    if (!ipPermissions.isEmpty()) {
        LOG.info(">> Authorizing Security Group Ingress Rules {} for {}", ipPermissions, groupName);

        AuthorizeSecurityGroupIngressRequest request = new AuthorizeSecurityGroupIngressRequest()
            .withGroupName(groupName).withIpPermissions(ipPermissions);
        client.authorizeSecurityGroupIngress(request);
    }
}
 
开发者ID:apache,项目名称:incubator-provisionr,代码行数:10,代码来源:EnsureSecurityGroupExists.java

示例13: authorizeSecurityGroupIngress

import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest; //导入依赖的package包/类
/**
 * Authorize SecurityGroup Ingress.
 * @param groupId the group id
 * @param ipProtocol ipProtocol for Ingress.
 * @param port portRange for Ingress.
 * @param cidrIp cidr Ip for Ingress
 * @return true if deleted, otherwise false.
 */
protected final boolean authorizeSecurityGroupIngress(final String groupId, final String ipProtocol, final Integer port, final String cidrIp) {
	AuthorizeSecurityGroupIngressRequest req = new AuthorizeSecurityGroupIngressRequest();
    req.setGroupId(groupId);
    req.setCidrIp(cidrIp);
    req.setFromPort(port);
    req.setToPort(port);
    req.setIpProtocol(ipProtocol);
    AuthorizeSecurityGroupIngressResult result = amazonEC2Client.authorizeSecurityGroupIngress(req);
    if (result != null) {
        return true;
    }

    return false;
}
 
开发者ID:treelogic-swe,项目名称:aws-mock,代码行数:23,代码来源:BaseTest.java

示例14: authorizeSecurityGroupIngress

import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest; //导入依赖的package包/类
@Override
public void authorizeSecurityGroupIngress(AuthorizeSecurityGroupIngressRequest authorizeSecurityGroupIngressRequest) throws AmazonServiceException, AmazonClientException {
    throw new UnsupportedOperationException("Not supported in mock");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:AmazonEC2Mock.java

示例15: main

import com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest; //导入依赖的package包/类
public static void main(String[] args)
{
    final String USAGE =
        "To run this example, supply a group name, group description and vpc id\n" +
        "Ex: CreateSecurityGroup <group-name> <group-description> <vpc-id>\n";

    if (args.length != 3) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String group_name = args[0];
    String group_desc = args[1];
    String vpc_id = args[2];

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    CreateSecurityGroupRequest create_request = new
        CreateSecurityGroupRequest()
            .withGroupName(group_name)
            .withDescription(group_desc)
            .withVpcId(vpc_id);

    CreateSecurityGroupResult create_response =
        ec2.createSecurityGroup(create_request);

    System.out.printf(
        "Successfully created security group named %s",
        group_name);

    IpRange ip_range = new IpRange()
        .withCidrIp("0.0.0.0/0");

    IpPermission ip_perm = new IpPermission()
        .withIpProtocol("tcp")
        .withToPort(80)
        .withFromPort(80)
        .withIpv4Ranges(ip_range);

    IpPermission ip_perm2 = new IpPermission()
        .withIpProtocol("tcp")
        .withToPort(22)
        .withFromPort(22)
        .withIpv4Ranges(ip_range);

    AuthorizeSecurityGroupIngressRequest auth_request = new
        AuthorizeSecurityGroupIngressRequest()
            .withGroupName(group_name)
            .withIpPermissions(ip_perm, ip_perm2);

    AuthorizeSecurityGroupIngressResult auth_response =
        ec2.authorizeSecurityGroupIngress(auth_request);

    System.out.printf(
        "Successfully added ingress policy to security group %s",
        group_name);
}
 
开发者ID:awsdocs,项目名称:aws-doc-sdk-examples,代码行数:58,代码来源:CreateSecurityGroup.java


注:本文中的com.amazonaws.services.ec2.model.AuthorizeSecurityGroupIngressRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。