//package com.ruoyi.aicall.aliyun;
//
//import com.aliyun.cloudfw20171207.models.*;
//import com.aliyun.teaopenapi.models.*;
//import lombok.extern.slf4j.Slf4j;
//
///**
// * 云防火墙策略管理工具类
// */
//@Slf4j
//public class AliyunFirewallPolicyManager {
//
//    /**
//     * 使用AK&SK初始化账号Client
//     * @param accessKeyId
//     * @param accessKeySecret
//     * @param regionId
//     * @return Client
//     * @throws Exception
//     */
//    public static com.aliyun.cloudfw20171207.Client createClient(String accessKeyId, String accessKeySecret, String regionId) throws Exception {
//        Config config = new Config();
//        // 您的AccessKey ID
//        config.accessKeyId = accessKeyId;
//        // 您的AccessKey Secret
//        config.accessKeySecret = accessKeySecret;
//        // 您的可用区ID
//        config.regionId = regionId;
//        return new com.aliyun.cloudfw20171207.Client(config);
//    }
//
//    /**
//     * 创建集群
//     * @param client
//     * @return AddControlPolicyResponse
//     * @throws Exception
//     */
//    public static AddControlPolicyResponse addControlPolicy(com.aliyun.cloudfw20171207.Client client, String direction, String sourceType, String source, String destinationType, String destination, String proto, String destPortType, String destPort, String destPortGroup, String applicationName, String aclAction, String description, String ipVersion, String newOrder, String release) throws Exception {
//        AddControlPolicyRequest addControlPolicyRequest = new AddControlPolicyRequest()
//                // 枚举值: in/out, 分别代表"外对内"/"内对外"
//                .setDirection(direction)
//                // 源类型, 枚举值, net/group/location, 分表代表 "IP"/"地址簿"/"区域"
//                .setSourceType(sourceType)
//                // 如果源为 net, source 就是 CIDR, 如 8.8.8.8/32, 如果是 gorup, source 就是 groupId
//                .setSource(source)
//                // 目的类型, 枚举值, net/group, 分表代表 "IP"/"地址簿"
//                .setDestinationType(destinationType)
//                // 如果目的类型为 net, destination 就是 CIDR, 如 8.8.8.8/32, 如果是 gorup, destination 就是 groupId
//                .setDestination(destination)
//                // 协议类型, TCP/UDP/ICMP/ANY
//                .setProto(proto)
//                // 目的端口类型, 枚举值, port/group, 分别代表: "端口"/"端口地址簿"
//                .setDestPortType(destPortType)
//                // destPortType 为 port时, destPort值必填, destPortGroup不填
//                .setDestPort(destPort)
//                // destPortType 为 group, destPortGroup值必填, destPort不填
//                .setDestPortGroup(destPortGroup)
//                // 应用名:
//                .setApplicationName(applicationName)
//                // 拦截策略: log/accept/drop
//                .setAclAction(aclAction)
//                // 描述
//                .setDescription(description)
//                // 4/6
//                .setIpVersion(ipVersion)
//                // 新的排序, -1, 放最后
//                .setNewOrder(newOrder)
//                // 是否生效, true/false
//                .setRelease(release);
//        return client.addControlPolicy(addControlPolicyRequest);
//    }
//
//
//
//    /**
//     * 获取策略
//     * @param client
//     * @return DescribeControlPolicyResponse
//     * @throws Exception
//     */
//    public static DescribeControlPolicyResponse describeControlPolicy(com.aliyun.cloudfw20171207.Client client, String pageNo, String pageSize, String direction, String ipVersion) throws Exception {
//        DescribeControlPolicyRequest describeControlPolicyRequest = new DescribeControlPolicyRequest()
//                // 第几页
//                .setCurrentPage(pageNo)
//                // 每页多少条
//                .setPageSize(pageSize)
//                // 方向, 枚举值, in/out
//                .setDirection(direction)
//                // IP版本, 枚举值, 4/6
//                .setIpVersion(ipVersion);
//        return client.describeControlPolicy(describeControlPolicyRequest);
//    }
//
//
//    /**
//     * 删除策略
//     * @param client
//     * @return DeleteControlPolicyResponse
//     * @throws Exception
//     */
//    public static DeleteControlPolicyResponse deleteControlPolicy(com.aliyun.cloudfw20171207.Client client, String aclUuid, String direction) throws Exception {
//        DeleteControlPolicyRequest deleteControlPolicyRequest = new DeleteControlPolicyRequest()
//                // 唯一 id, 请参见创建的返回值
//                .setAclUuid(aclUuid)
//                // 枚举值: in/out, 分别代表"外对内"/"内对外"
//                .setDirection(direction);
//        return client.deleteControlPolicy(deleteControlPolicyRequest);
//    }
//
//
//    public static void main(String[] args_) throws Exception {
//        String accessKeyId = "";
//        String accessKeySecret = "";
//
//        // 0. 初始化客户端
//        com.aliyun.cloudfw20171207.Client client = AliyunFirewallPolicyManager.createClient(accessKeyId, accessKeySecret, "cn-hangzhou");
//        // 1. 获取访问策略列表
//        String pageNo = "1";
//        String pageSize = "100";
//        String direction = "";
//        String ipVersion = "";
//        DescribeControlPolicyResponse describeControlPolicyResponse = AliyunFirewallPolicyManager.describeControlPolicy(client, pageNo, pageSize, direction, ipVersion);
//        DescribeControlPolicyResponseBody body = describeControlPolicyResponse.body;
//        log.info("Describe Control Policy, TotalCount: " + body.totalCount + ".");
//        for (DescribeControlPolicyResponseBody.DescribeControlPolicyResponseBodyPolicys policy : body.policys) {
//            log.info("aclUuid: " + policy.aclUuid + ", aclAction: " + policy.aclAction + "!");
//        }
////        // 2. 创建访问策略
////        direction = "in";
////        String sourceType = "accept";
////        String source = "36.7.79.15";
////        String destinationType = "net";
////        String destination = "";
////        String proto = "UDP";
////        String destPortType = "port";
////        String destPort = "5060";
////        String destPortGroup = "";
////        String applicationName = "ANY";
////        String aclAction = "";
////        String description = "";
////        ipVersion = "";
////        String newOrder = "";
////        String release = "";
////        AddControlPolicyResponse addControlPolicyResponse = CloudFirewallPolicyManager.addControlPolicy(client, direction, sourceType, source, destinationType, destination, proto, destPortType, destPort, destPortGroup, applicationName, aclAction, description, ipVersion, newOrder, release);
////        String aclUuid = addControlPolicyResponse.body.aclUuid;
////        log.info("Create Control Policy, AclUuid Id is " + aclUuid + ".");
////
////        // 3. 获取访问策略列表
////        direction = "";
////        ipVersion = "";
////        describeControlPolicyResponse = CloudFirewallPolicyManager.describeControlPolicy(client, pageNo, pageSize, direction, ipVersion);
////        body = describeControlPolicyResponse.body;
////        log.info("Describe Control Policy, TotalCount: " + body.totalCount + ".");
////        for (DescribeControlPolicyResponseBody.DescribeControlPolicyResponseBodyPolicys policy : body.policys) {
////            log.info("aclUuid: " + policy.aclUuid + ", aclAction: " + policy.aclAction + "!");
////        }
////
////        // 4. 删除访问策略
//////        aclUuid = "";
////        direction = "";
////        DeleteControlPolicyResponse deleteControlPolicyResponse = CloudFirewallPolicyManager.deleteControlPolicy(client, aclUuid, direction);
////        String requestId = deleteControlPolicyResponse.body.requestId;
////        log.info("Delete Control Policy, requestId: " + requestId + ".");
////
////
////        // 5. 获取访问策略列表
////        describeControlPolicyResponse = CloudFirewallPolicyManager.describeControlPolicy(client, pageNo, pageSize, direction, ipVersion);
////        body = describeControlPolicyResponse.body;
////        log.info("Describe Control Policy, TotalCount: " + body.totalCount + ".");
////        for (DescribeControlPolicyResponseBody.DescribeControlPolicyResponseBodyPolicys policy : body.policys) {
////            log.info("aclUuid: " + policy.aclUuid + ", aclAction: " + policy.aclAction + "!");
////        }
//
//    }
//}
