|
| 1 | +import cuid from 'cuid' |
| 2 | +import { |
| 3 | + IKEOptionsSpecification, |
| 4 | + IPSECOptionsSpecification, |
| 5 | +} from 'tencentcloud-sdk-nodejs/tencentcloud/services/vpc/v20170312/vpc_models'; |
| 6 | +import { |
| 7 | + TencentVpnConnection, |
| 8 | + TencentVpnConnectionIkeOptionsSpecification, |
| 9 | + TencentVpnConnectionIpsecOptionsSpecification, |
| 10 | +} from '../../types/generated' |
| 11 | +import { RawTencentVpnConnection } from './data' |
| 12 | + |
| 13 | +const formatIKEOptionsSpecification = (ikeOptionsSpecification: IKEOptionsSpecification): TencentVpnConnectionIkeOptionsSpecification => { |
| 14 | + const { |
| 15 | + PropoEncryAlgorithm: propoEncryAlgorithm = '', |
| 16 | + PropoAuthenAlgorithm: propoAuthenAlgorithm = '', |
| 17 | + ExchangeMode: exchangeMode = '', |
| 18 | + LocalIdentity: localIdentity = '', |
| 19 | + RemoteIdentity: remoteIdentity = '', |
| 20 | + LocalAddress: localAddress = '', |
| 21 | + RemoteAddress: remoteAddress = '', |
| 22 | + LocalFqdnName: localFqdnName = '', |
| 23 | + RemoteFqdnName: remoteFqdnName = '', |
| 24 | + DhGroupName: dhGroupName = '', |
| 25 | + IKESaLifetimeSeconds: ikeSaLifetimeSeconds = 0, |
| 26 | + IKEVersion: ikeVersion = '', |
| 27 | + } = ikeOptionsSpecification |
| 28 | + |
| 29 | + return { |
| 30 | + propoEncryAlgorithm, |
| 31 | + propoAuthenAlgorithm, |
| 32 | + exchangeMode, |
| 33 | + localIdentity, |
| 34 | + remoteIdentity, |
| 35 | + localAddress, |
| 36 | + remoteAddress, |
| 37 | + localFqdnName, |
| 38 | + remoteFqdnName, |
| 39 | + dhGroupName, |
| 40 | + ikeSaLifetimeSeconds, |
| 41 | + ikeVersion, |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +const formatIPSECOptionsSpecification = ( |
| 46 | + ipsecOptionsSpecification: IPSECOptionsSpecification, |
| 47 | +): TencentVpnConnectionIpsecOptionsSpecification => { |
| 48 | + const { |
| 49 | + EncryptAlgorithm: encryptAlgorithm = '', |
| 50 | + IntegrityAlgorith: integrityAlgorith = '', |
| 51 | + IPSECSaLifetimeSeconds: ipsecSaLifetimeSeconds = 0, |
| 52 | + PfsDhGroup: pfsDhGroup = '', |
| 53 | + IPSECSaLifetimeTraffic: ipsecSaLifetimeTraffic = 0, |
| 54 | + } = ipsecOptionsSpecification |
| 55 | + |
| 56 | + return { |
| 57 | + encryptAlgorithm, |
| 58 | + integrityAlgorith, |
| 59 | + ipsecSaLifetimeSeconds, |
| 60 | + pfsDhGroup, |
| 61 | + ipsecSaLifetimeTraffic, |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +export default ({ |
| 66 | + service, |
| 67 | + region, |
| 68 | +}: { |
| 69 | + service: RawTencentVpnConnection |
| 70 | + region: string |
| 71 | +}): TencentVpnConnection=> { |
| 72 | + const { |
| 73 | + id, |
| 74 | + VpnConnectionName: name, |
| 75 | + PreShareKey: preShareKey, |
| 76 | + VpnProto: vpnProto, |
| 77 | + EncryptProto: encryptProto, |
| 78 | + RouteType: routeType, |
| 79 | + CreatedTime: createdTime, |
| 80 | + State: state, |
| 81 | + NetStatus: netStatus, |
| 82 | + SecurityPolicyDatabaseSet = [], |
| 83 | + IKEOptionsSpecification: ikeOptionsSpecification = {}, |
| 84 | + IPSECOptionsSpecification: ipsecOptionsSpecification = {}, |
| 85 | + EnableHealthCheck: enableHealthCheck, |
| 86 | + HealthCheckLocalIp: healthCheckLocalIp, |
| 87 | + HealthCheckRemoteIp: healthCheckRemoteIp, |
| 88 | + HealthCheckStatus: healthCheckStatus, |
| 89 | + } = service |
| 90 | + |
| 91 | + return { |
| 92 | + id, |
| 93 | + region, |
| 94 | + name, |
| 95 | + preShareKey, |
| 96 | + vpnProto, |
| 97 | + encryptProto, |
| 98 | + routeType, |
| 99 | + createdTime, |
| 100 | + state, |
| 101 | + netStatus, |
| 102 | + securityPolicyDatabaseSet: SecurityPolicyDatabaseSet.map(({ |
| 103 | + LocalCidrBlock: localCidrBlock, |
| 104 | + RemoteCidrBlock: remoteCidrBlock, |
| 105 | + }) => { |
| 106 | + return { |
| 107 | + id: cuid(), |
| 108 | + localCidrBlock, |
| 109 | + remoteCidrBlock, |
| 110 | + } |
| 111 | + }), |
| 112 | + ikeOptionsSpecification: formatIKEOptionsSpecification(ikeOptionsSpecification), |
| 113 | + ipsecOptionsSpecification: formatIPSECOptionsSpecification(ipsecOptionsSpecification), |
| 114 | + enableHealthCheck, |
| 115 | + healthCheckLocalIp, |
| 116 | + healthCheckRemoteIp, |
| 117 | + healthCheckStatus, |
| 118 | + } |
| 119 | +} |
0 commit comments