-
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.
* add rvive linters * linter fixes * add revive linter bage to readme Co-authored-by: Budylnikov Vladimir <[email protected]>
- Loading branch information
Showing
4 changed files
with
104 additions
and
73 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,23 @@ | ||
--- | ||
name: revive linters | ||
|
||
on: | ||
push: | ||
|
||
permissions: | ||
contents: write | ||
# packages: write | ||
# issues: write | ||
|
||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.19 | ||
- run: go install github.com/mgechev/[email protected] | ||
- run: revive |
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,3 @@ | ||
linters: | ||
enable: | ||
- revive |
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,92 +1,95 @@ | ||
// exports traefik's certificates as files | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"encoding/base64" | ||
"io/ioutil" | ||
"os" | ||
"log" | ||
"encoding/base64" | ||
"encoding/json" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
) | ||
|
||
// ACME is an imported global traefik acme.json sctructure | ||
type ACME struct { | ||
Le struct { | ||
Account struct { | ||
Email string | ||
} `json: "Account"` | ||
Certificates []Certificates | ||
} `json: "le"` | ||
Le struct { | ||
Account struct { | ||
Email string | ||
} `json: "Account"` | ||
Certificates []Certificates | ||
} `json: "le"` | ||
} | ||
|
||
// Certificates list in acme.json | ||
type Certificates struct { | ||
Domain struct { | ||
Main string `json: "main"` | ||
}`json: "domain"` | ||
Certificate string `json: "certificate"` | ||
Key string `json: "key"` | ||
Domain struct { | ||
Main string `json: "main"` | ||
} `json: "domain"` | ||
Certificate string `json: "certificate"` | ||
Key string `json: "key"` | ||
} | ||
|
||
func main() { | ||
// open json file | ||
jsonFile, err := os.Open("input/acme.json") | ||
// if os.Open returns an error then print out it | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
log.Println("Successfully Opened acme.json") | ||
// defer the closing of the json file | ||
defer jsonFile.Close() | ||
// open json file | ||
jsonFile, err := os.Open("input/acme.json") | ||
// if os.Open returns an error then print out it | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
log.Println("Successfully Opened acme.json") | ||
// defer the closing of the json file | ||
defer jsonFile.Close() | ||
|
||
// create directory for certs | ||
path := "output" | ||
err = os.MkdirAll(path, os.ModePerm) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
// create directory for certs | ||
path := "output" | ||
err = os.MkdirAll(path, os.ModePerm) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
|
||
byteValue, _ := ioutil.ReadAll(jsonFile) | ||
var traefik ACME | ||
err = json.Unmarshal(byteValue, &traefik) | ||
if err != nil { | ||
panic(err) | ||
} | ||
for i := 0; i < len(traefik.Le.Certificates); i++ { | ||
// print cert hostname | ||
log.Println("Certificate host:", traefik.Le.Certificates[i].Domain.Main) | ||
// decode and print certificate | ||
cert_body, err := base64.StdEncoding.DecodeString(traefik.Le.Certificates[i].Certificate) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
log.Println("Save certificate body", traefik.Le.Certificates[i].Domain.Main) | ||
// create cert file | ||
cert_file, err := os.Create("output/"+ traefik.Le.Certificates[i].Domain.Main + ".cer") | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
defer cert_file.Close() | ||
byteValue, _ := ioutil.ReadAll(jsonFile) | ||
var traefik ACME | ||
err = json.Unmarshal(byteValue, &traefik) | ||
if err != nil { | ||
panic(err) | ||
} | ||
for i := 0; i < len(traefik.Le.Certificates); i++ { | ||
// print cert hostname | ||
log.Println("Certificate host:", traefik.Le.Certificates[i].Domain.Main) | ||
// decode and print certificate | ||
certBody, err := base64.StdEncoding.DecodeString(traefik.Le.Certificates[i].Certificate) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
log.Println("Save certificate body", traefik.Le.Certificates[i].Domain.Main) | ||
// create cert file | ||
certFile, err := os.Create("output/" + traefik.Le.Certificates[i].Domain.Main + ".cer") | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
defer certFile.Close() | ||
|
||
_, err = cert_file.Write(cert_body) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
_, err = certFile.Write(certBody) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
|
||
// decode and print key | ||
cert_key, err := base64.StdEncoding.DecodeString(traefik.Le.Certificates[i].Key) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
log.Println("Save certificate key", traefik.Le.Certificates[i].Domain.Main) | ||
// create cert file | ||
key_file, err := os.Create("output/"+ traefik.Le.Certificates[i].Domain.Main + ".key") | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
defer key_file.Close() | ||
// decode and print key | ||
certKey, err := base64.StdEncoding.DecodeString(traefik.Le.Certificates[i].Key) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
log.Println("Save certificate key", traefik.Le.Certificates[i].Domain.Main) | ||
// create cert file | ||
keyFile, err := os.Create("output/" + traefik.Le.Certificates[i].Domain.Main + ".key") | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
defer keyFile.Close() | ||
|
||
_, err = key_file.Write(cert_key) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
_, err = keyFile.Write(certKey) | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
|
||
} | ||
} | ||
} |