-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c542a9
commit b909eb2
Showing
8 changed files
with
268 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@pulumi-helpers/component-alicloud-cdn': minor | ||
--- | ||
|
||
add AlicloudCdnComponent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{ | ||
"name": "@pulumi-helpers/component-alicloud-cdn", | ||
"version": "0.0.0", | ||
"keywords": [ | ||
"pulumi", | ||
"pulumi-component", | ||
"alicloud-cdn" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/bingtsingw/pulumi-helpers" | ||
}, | ||
"license": "MIT", | ||
"author": { | ||
"name": "bingtsingw", | ||
"email": "[email protected]", | ||
"url": "https://github.com/bingtsingw" | ||
}, | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "tsup", | ||
"check-type": "tsc --noEmit", | ||
"dev": "tsup --watch", | ||
"lint:js": "eslint . --cache --ext .js,.jsx,.ts,.tsx", | ||
"lint:js:fix": "eslint . --cache --ext .js,.jsx,.ts,.tsx --fix", | ||
"test": "bun test" | ||
}, | ||
"eslintConfig": { | ||
"extends": "@xstools-dev/eslint-config/base", | ||
"rules": { | ||
"no-new": "off" | ||
} | ||
}, | ||
"dependencies": { | ||
"@pulumi/alicloud": "^3.62.0" | ||
}, | ||
"devDependencies": { | ||
"@pulumi/pulumi": "^3.131.0" | ||
}, | ||
"peerDependencies": { | ||
"@pulumi/pulumi": "*" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"registry": "https://registry.npmjs.org" | ||
}, | ||
"tsup": { | ||
"entry": [ | ||
"src/index.ts" | ||
], | ||
"format": [ | ||
"cjs" | ||
], | ||
"dts": true, | ||
"clean": true, | ||
"treeshake": true, | ||
"minify": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
import * as alicloud from '@pulumi/alicloud'; | ||
import * as pulumi from '@pulumi/pulumi'; | ||
|
||
interface AlicloudCdnProps { | ||
resourceGroupId: string; | ||
type: 'web' | 'download' | 'video'; | ||
scope: 'domestic' | 'overseas' | 'global'; | ||
sources: { content: string; type: 'oss' | 'ipaddr' | 'domain'; port: number }[]; | ||
domain: { host: string; record: string }; | ||
cert?: { pub: string; pri: string }; | ||
} | ||
|
||
export class AlicloudCdnComponent extends pulumi.ComponentResource { | ||
private cdnName: string; | ||
private dnsName: string; | ||
private host: string; | ||
|
||
public constructor( | ||
private name: string, | ||
private props: AlicloudCdnProps, | ||
opts?: pulumi.ComponentResourceOptions, | ||
) { | ||
super('pkg:index:AlicloudCdnComponent', name, {}, opts); | ||
|
||
this.cdnName = `${this.name}-cdn`; | ||
this.dnsName = `${this.cdnName}-dns`; | ||
this.host = `${this.props.domain.record}.${this.props.domain.host}`; | ||
|
||
const cdn = this.createCdn(); | ||
|
||
this.configBasic(cdn); | ||
|
||
this.configHttps(cdn); | ||
|
||
this.registerOutputs(); | ||
} | ||
|
||
private createCdn() { | ||
const cdn = new alicloud.cdn.DomainNew( | ||
this.cdnName, | ||
{ | ||
resourceGroupId: this.props.resourceGroupId, | ||
cdnType: this.props.type, | ||
scope: this.props.scope, | ||
sources: this.props.sources, | ||
domainName: this.host, | ||
...(this.props.cert | ||
? { | ||
certificateConfig: { | ||
certType: 'upload', | ||
privateKey: this.props.cert.pri, | ||
serverCertificate: this.props.cert.pub, | ||
}, | ||
} | ||
: {}), | ||
}, | ||
{ parent: this }, | ||
); | ||
|
||
new alicloud.dns.Record( | ||
this.dnsName, | ||
{ | ||
hostRecord: this.props.domain.record, | ||
name: this.props.domain.host, | ||
type: 'CNAME', | ||
value: cdn.cname, | ||
}, | ||
{ parent: this }, | ||
); | ||
|
||
return cdn; | ||
} | ||
|
||
private configBasic(cdn: alicloud.cdn.DomainNew) { | ||
// IPv6开关 | ||
new alicloud.cdn.DomainConfig( | ||
`${this.cdnName}-ipv6`, | ||
{ | ||
domainName: cdn.domainName, | ||
functionName: 'ipv6', | ||
functionArgs: [ | ||
{ argName: 'switch', argValue: 'on' }, | ||
{ argName: 'region', argValue: '*' }, | ||
], | ||
}, | ||
{ parent: this }, | ||
); | ||
|
||
// 回源HOST | ||
new alicloud.cdn.DomainConfig( | ||
`${this.cdnName}-set_req_host_header`, | ||
{ | ||
domainName: cdn.domainName, | ||
functionName: 'set_req_host_header', | ||
functionArgs: [{ argName: 'domain_name', argValue: this.host }], | ||
}, | ||
{ parent: this }, | ||
); | ||
|
||
// 回源协议 | ||
new alicloud.cdn.DomainConfig( | ||
`${this.cdnName}-forward_scheme`, | ||
{ | ||
domainName: cdn.domainName, | ||
functionName: 'forward_scheme', | ||
functionArgs: [ | ||
{ argName: 'enable', argValue: 'on' }, | ||
{ argName: 'scheme_origin', argValue: 'https' }, | ||
], | ||
}, | ||
{ parent: this }, | ||
); | ||
} | ||
|
||
private configHttps(cdn: alicloud.cdn.DomainNew) { | ||
// HTTP/2 OCSP设置 | ||
new alicloud.cdn.DomainConfig( | ||
`${this.cdnName}-https_option`, | ||
{ | ||
domainName: cdn.domainName, | ||
functionName: 'https_option', | ||
functionArgs: [ | ||
{ argName: 'http2', argValue: 'on' }, | ||
{ argName: 'ocsp_stapling', argValue: 'on' }, | ||
], | ||
}, | ||
{ parent: this, ignoreChanges: ['functionArgs'] }, | ||
); | ||
|
||
// 强制跳转 | ||
new alicloud.cdn.DomainConfig( | ||
`${this.cdnName}-https_force`, | ||
{ | ||
domainName: cdn.domainName, | ||
functionName: 'https_force', | ||
functionArgs: [{ argName: 'enable', argValue: 'on' }], | ||
}, | ||
{ parent: this }, | ||
); | ||
|
||
// TLS版本 | ||
new alicloud.cdn.DomainConfig( | ||
`${this.cdnName}-https_tls_version`, | ||
{ | ||
domainName: cdn.domainName, | ||
functionName: 'https_tls_version', | ||
functionArgs: [ | ||
{ argName: 'tls10', argValue: 'on' }, | ||
{ argName: 'tls11', argValue: 'on' }, | ||
{ argName: 'tls12', argValue: 'on' }, | ||
{ argName: 'tls13', argValue: 'on' }, | ||
], | ||
}, | ||
{ parent: this }, | ||
); | ||
|
||
// HSTS | ||
new alicloud.cdn.DomainConfig( | ||
`${this.cdnName}-hsts`, | ||
{ | ||
domainName: cdn.domainName, | ||
functionName: 'HSTS', | ||
functionArgs: [ | ||
{ argName: 'enabled', argValue: 'on' }, | ||
{ argName: 'https_hsts_max_age', argValue: '5184000' }, | ||
], | ||
}, | ||
{ parent: this }, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "@xstools-dev/typescript-config/base/tsconfig.json", | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.