-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #288 from w3f/git-config
Git config
- Loading branch information
Showing
18 changed files
with
436 additions
and
277 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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
description: Polkadot Watcher | ||
name: polkadot-watcher | ||
version: v4.2.0 | ||
appVersion: v4.2.0 | ||
version: v4.3.0 | ||
appVersion: v4.3.0 | ||
apiVersion: v2 |
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 @@ | ||
{{/* Returns the app name */}} | ||
{{- define "app.name" -}} | ||
{{- default .Release.Name .Values.nameOverride -}} | ||
{{- end }} |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ .Release.Name }} | ||
name: {{ include "app.name" . }} | ||
data: | ||
main.yaml: |- | ||
{{ toYaml .Values.config | indent 4 }} |
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ .Release.Name }} | ||
name: {{ include "app.name" . }} | ||
labels: | ||
app: {{ .Release.Name }} | ||
app: {{ include "app.name" . }} | ||
spec: | ||
ports: | ||
- name: metrics | ||
port: {{ .Values.config.port }} | ||
selector: | ||
app: {{ .Release.Name }} | ||
app: {{ include "app.name" . }} |
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
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
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,8 @@ | ||
import { GitConfigLoader } from "./gitConfigLoaderInterface"; | ||
import { Subscribable } from "../types"; | ||
|
||
export class Disabled implements GitConfigLoader { | ||
async downloadAndLoad(): Promise<Array<Subscribable>> { | ||
return [] | ||
} | ||
} |
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,24 @@ | ||
import { InputConfig } from "../types" | ||
import { Disabled } from "./disabled" | ||
import { GitConfigLoader } from "./gitConfigLoaderInterface" | ||
import { GitLabPrivate } from "./gitLabPrivate" | ||
|
||
export class GitConfigLoaderFactory { | ||
constructor(private readonly cfg: InputConfig){} | ||
makeGitConfigLoader = (): GitConfigLoader => { | ||
|
||
const gitConfig = this.cfg.validatorsFromGit | ||
|
||
if(!gitConfig?.enabled) | ||
return new Disabled() | ||
|
||
switch (gitConfig.platform.toLowerCase()) { | ||
case "gitlab": | ||
if(gitConfig.private.enabled) return new GitLabPrivate(gitConfig.url,gitConfig.private.apiToken,gitConfig.network) //implemented just GitLab private for now | ||
else new Disabled() | ||
break; | ||
default: | ||
return new Disabled() | ||
} | ||
} | ||
} |
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 @@ | ||
import { Subscribable } from "../types"; | ||
|
||
export interface GitConfigLoader { | ||
downloadAndLoad(): Promise<Array<Subscribable>>; | ||
} |
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,39 @@ | ||
import { GitConfigLoader } from "./gitConfigLoaderInterface"; | ||
import fetch from 'node-fetch'; | ||
import fs from 'fs'; | ||
import { Config } from '@w3f/config'; | ||
import { InputConfigFromGit, Subscribable } from "../types"; | ||
|
||
export class GitLabPrivate implements GitConfigLoader { | ||
|
||
constructor( | ||
protected readonly url: string, | ||
protected readonly apiToken: string, | ||
protected readonly network: string | ||
) { } | ||
|
||
async downloadAndLoad(): Promise<Array<Subscribable>> { | ||
const response = await fetch(this.url, { | ||
headers: { | ||
'PRIVATE-TOKEN': this.apiToken | ||
} | ||
}); | ||
const data = await response.text(); | ||
if(!response.ok) throw new Error("git config download probelm: " + data) | ||
|
||
fs.writeFileSync("./tmp.yaml",data) | ||
const cfg = new Config<InputConfigFromGit>().parse("./tmp.yaml"); | ||
fs.rmSync("./tmp.yaml") | ||
|
||
switch (this.network.toLowerCase()) { | ||
case "kusama": | ||
return cfg.Kusama | ||
|
||
case "polkadot": | ||
return cfg.Polkadot | ||
|
||
default: | ||
throw new Error("unexpected configuration") | ||
} | ||
} | ||
} |
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
Oops, something went wrong.