-
Notifications
You must be signed in to change notification settings - Fork 0
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
Florian Fordermaier
committed
Dec 15, 2019
0 parents
commit 9b53f7d
Showing
9 changed files
with
189 additions
and
0 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,2 @@ | ||
/lib/ | ||
/node_modules/ |
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,3 @@ | ||
# pulumix | ||
|
||
My own extensions and helpers for use with pulumi. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,21 @@ | ||
{ | ||
"name": "pulumix", | ||
"version": "1.0.0", | ||
"description": "Some simple extensions and helpers for use with pulumi.", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "tsc" | ||
}, | ||
"homepage": "https://github.com/codedevote/pulumix", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/codedevote/pulumix.git" | ||
}, | ||
"author": "[email protected]", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@types/node": "^8.10.59", | ||
"typescript": "^3.7.3" | ||
}, | ||
"files": ["lib/**/*"] | ||
} |
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,14 @@ | ||
interface IDisposable { | ||
dispose() : void; | ||
} | ||
|
||
function using<T extends IDisposable>(resource: T, func: (resource: T) => void) { | ||
try { | ||
func(resource); | ||
} finally { | ||
resource.dispose(); | ||
} | ||
} | ||
|
||
export default IDisposable; | ||
export { IDisposable, using }; |
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,22 @@ | ||
import * as fs from "fs" | ||
import * as path from "path"; | ||
import { IDisposable } from "./IDisposable" | ||
|
||
class TempYaml implements IDisposable { | ||
|
||
fileName : string; | ||
dir : string; | ||
|
||
constructor(yaml: string) { | ||
this.dir = fs.mkdtempSync("sarooma"); | ||
this.fileName = path.join(this.dir, "temp.yaml"); | ||
fs.writeFileSync(this.fileName, yaml); | ||
} | ||
|
||
dispose() { | ||
fs.unlinkSync(this.fileName); | ||
fs.rmdirSync(this.dir); | ||
} | ||
} | ||
|
||
export default TempYaml; |
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,30 @@ | ||
import TempYaml from "../../TempYaml" | ||
|
||
class Certificate { | ||
/** | ||
* Creates a ClusterIssuer resource using letsencrypt staging servers and returns the yaml as string. | ||
* | ||
* @param name Name of the cluster issuer resource | ||
*/ | ||
public createCertificate(certName: string, namespace: string, dnsName: string, clusterIssuer: string) : TempYaml { | ||
|
||
var certificateTemplate = | ||
`apiVersion: cert-manager.io/v1alpha2 | ||
kind: Certificate | ||
metadata: | ||
name: ${certName} | ||
namespace: ${namespace} | ||
spec: | ||
secretName: ${certName} | ||
commonName: ${dnsName} | ||
dnsNames: | ||
- ${dnsName} | ||
issuerRef: | ||
name: ${clusterIssuer} | ||
kind: ClusterIssuer`; | ||
|
||
return new TempYaml(certificateTemplate); | ||
} | ||
} | ||
|
||
export default Certificate; |
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,66 @@ | ||
import TempYaml from "../../TempYaml" | ||
|
||
class ClusterIssuer { | ||
|
||
/** | ||
* Creates a ClusterIssuer resource using letsencrypt staging servers and returns the yaml as string. | ||
* | ||
* @param name Name of the cluster issuer resource | ||
*/ | ||
public createForStaging(name: String) : TempYaml { | ||
return this.createYaml(name, true); | ||
} | ||
|
||
/** | ||
* Creates a ClusterIssuer resource using letsencrypt production servers and returns the yaml as string. | ||
* | ||
* @param name Name of the cluster issuer resource | ||
*/ | ||
public createForProd(name: String) : TempYaml { | ||
return this.createYaml(name, false); | ||
} | ||
|
||
private createYaml(name: String, forStaging: Boolean) : TempYaml { | ||
const acmeServer = | ||
forStaging | ||
? "https://acme-staging-v02.api.letsencrypt.org/directory" | ||
: "https://acme-v02.api.letsencrypt.org/directory"; | ||
|
||
const clusterIssuerTemplate = | ||
`apiVersion: cert-manager.io/v1alpha2 | ||
kind: ClusterIssuer | ||
metadata: | ||
name: ${name} | ||
namespace: default | ||
spec: | ||
acme: | ||
server: ${acmeServer} | ||
email: [email protected] | ||
privateKeySecretRef: | ||
name: ${name} | ||
# this is the 'new' way of defining solvers | ||
solvers: | ||
# empty selector will match all Certificate resources that reference this issuer. | ||
# for selecting a specific solver from a Certificate resource (not required right now), see | ||
# https://docs.cert-manager.io/en/latest/tasks/upgrading/upgrading-0.7-0.8.html#performing-an-incremental-switch-to-the-new-format | ||
- selector: {} | ||
dns01: | ||
digitalocean: | ||
tokenSecretRef: | ||
name: dns01-solver-secret | ||
key: token | ||
- selector: | ||
matchLabels: | ||
use-http01-solver: "true" | ||
http01: | ||
ingress: | ||
class: nginx`; | ||
|
||
return new TempYaml(clusterIssuerTemplate); | ||
} | ||
} | ||
|
||
export default ClusterIssuer; | ||
export { ClusterIssuer }; | ||
|
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,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2016", | ||
"module": "commonjs", | ||
"declaration": true, | ||
"outDir": "./lib", | ||
"strict": true | ||
}, | ||
"include": ["src"], | ||
"exclude": ["node_modules", "**/__tests__/*"] | ||
} |