Skip to content

Commit b1a4f1f

Browse files
committed
fix(ci): Adding .goreleaser.yml
1 parent 0dc4292 commit b1a4f1f

File tree

3 files changed

+127
-24
lines changed

3 files changed

+127
-24
lines changed

.goreleaser.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Visit https://goreleaser.com for documentation on how to customize this
2+
# behavior.
3+
before:
4+
hooks:
5+
# this is just an example and not a requirement for provider building/publishing
6+
- go mod tidy
7+
builds:
8+
- env:
9+
# goreleaser does not work with CGO, it could also complicate
10+
# usage by users in CI/CD systems like Terraform Cloud where
11+
# they are unable to install libraries.
12+
- CGO_ENABLED=0
13+
mod_timestamp: '{{ .CommitTimestamp }}'
14+
flags:
15+
- -trimpath
16+
ldflags:
17+
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
18+
goos:
19+
- freebsd
20+
- windows
21+
- linux
22+
- darwin
23+
goarch:
24+
- amd64
25+
- '386'
26+
- arm
27+
- arm64
28+
ignore:
29+
- goos: darwin
30+
goarch: '386'
31+
binary: '{{ .ProjectName }}_v{{ .Version }}'
32+
archives:
33+
- format: zip
34+
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
35+
checksum:
36+
extra_files: []
37+
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
38+
algorithm: sha256
39+
signs:
40+
- artifacts: checksum
41+
args:
42+
# if you are using this in a GitHub action or some other automated pipeline, you
43+
# need to pass the batch flag to indicate its not interactive.
44+
- "--batch"
45+
- "--local-user"
46+
- "{{ .Env.GPG_FINGERPRINT }}" # set this environment variable for your signing key
47+
- "--output"
48+
- "${signature}"
49+
- "--detach-sign"
50+
- "${artifact}"
51+
release:
52+
extra_files: []
53+
# If you want to manually examine the release before its live, uncomment this line:
54+
draft: true
55+
changelog:
56+
skip: true

GNUmakefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ NAMESPACE=keyfactor
66
WEBSITE_REPO=https://github.com/Keyfactor/kfutil
77
NAME=kfutil
88
BINARY=${NAME}
9-
VERSION=0.0.1
9+
VERSION=0.0.2
1010
OS_ARCH := $(shell go env GOOS)_$(shell go env GOARCH)
1111
BASEDIR := ${HOME}/go/bin
1212
INSTALLDIR := ${BASEDIR}
@@ -45,4 +45,10 @@ test:
4545
fmt:
4646
gofmt -w $(GOFMT_FILES)
4747

48-
.PHONY: build release install test fmt
48+
prerelease:
49+
git tag -d $(VERSION)
50+
git push origin :$(VERSION)
51+
git tag $(VERSION)
52+
git push origin $(VERSION)
53+
54+
.PHONY: build prerelease release install test fmt

cmd/rot.go

Lines changed: 63 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,13 @@ var rotCmd = &cobra.Command{
3838
var lookupFailures []string
3939
kfClient, _ := initClient()
4040
storesFile, _ := cmd.Flags().GetString("stores")
41-
certsFile, _ := cmd.Flags().GetString("certs")
41+
addRootsFile, _ := cmd.Flags().GetString("add-certs")
42+
removeRootsFile, _ := cmd.Flags().GetString("remove-certs")
43+
dryRun, _ := cmd.Flags().GetBool("dry-run")
4244
log.Printf("[DEBUG] storesFile: %s", storesFile)
43-
log.Printf("[DEBUG] certsFile: %s", certsFile)
45+
log.Printf("[DEBUG] addRootsFile: %s", addRootsFile)
46+
log.Printf("[DEBUG] removeRootsFile: %s", removeRootsFile)
47+
log.Printf("[DEBUG] dryRun: %t", dryRun)
4448

4549
// Read in the stores CSV
4650
csvFile, _ := os.Open(storesFile)
@@ -69,31 +73,65 @@ var rotCmd = &cobra.Command{
6973
storesJson, _ := json.Marshal(stores)
7074
fmt.Println(string(storesJson))
7175

72-
// Read in the certs CSV
73-
csvFile, _ = os.Open(certsFile)
74-
reader = csv.NewReader(bufio.NewReader(csvFile))
75-
certEntries, _ := reader.ReadAll()
76-
var certs = make(map[string]RotCert)
77-
for _, entry := range certEntries {
78-
if entry[0] == "CertId" || entry[0] == "thumbprint" {
79-
continue // Skip header
76+
// Read in the add addCerts CSV
77+
var addCerts = make(map[string]RotCert)
78+
if addRootsFile != "" {
79+
addCerts, err := readCertsFile(addRootsFile)
80+
if err != nil {
81+
log.Fatalf("Error reading addCerts file: %s", err)
8082
}
81-
certs[entry[0]] = RotCert{
82-
ThumbPrint: entry[0],
83+
addCertsJson, _ := json.Marshal(addCerts)
84+
fmt.Printf("[DEBUG] add certs JSON: %s", string(addCertsJson))
85+
fmt.Println("add rot called")
86+
} else {
87+
log.Printf("[DEBUG] No addCerts file specified")
88+
log.Printf("[DEBUG] No addCerts = %s", addCerts)
89+
}
90+
91+
// Read in the remove removeCerts CSV
92+
var removeCerts = make(map[string]RotCert)
93+
if removeRootsFile != "" {
94+
removeCerts, err := readCertsFile(removeRootsFile)
95+
if err != nil {
96+
log.Fatalf("Error reading removeCerts file: %s", err)
8397
}
84-
// Get certificate context
85-
//args := &api.GetCertificateContextArgs{
86-
// IncludeMetadata: boolToPointer(true),
87-
// IncludeLocations: boolToPointer(true),
88-
// CollectionId: nil,
89-
// Id: certificateIdInt,
90-
//}
91-
//cResp, err := r.p.client.GetCertificateContext(args)
98+
removeCertsJson, _ := json.Marshal(removeCerts)
99+
fmt.Println(string(removeCertsJson))
100+
fmt.Println("remove rot called")
101+
} else {
102+
log.Printf("[DEBUG] No removeCerts file specified")
103+
log.Printf("[DEBUG] No removeCerts = %s", removeCerts)
92104
}
93-
fmt.Println("rot called")
94105
},
95106
}
96107

108+
func readCertsFile(certsFilePath string) (map[string]RotCert, error) {
109+
// Read in the cert CSV
110+
csvFile, _ := os.Open(certsFilePath)
111+
reader := csv.NewReader(bufio.NewReader(csvFile))
112+
certEntries, _ := reader.ReadAll()
113+
var certs = make(map[string]RotCert)
114+
for _, entry := range certEntries {
115+
switch entry[0] {
116+
case "CertId", "thumbprint", "id", "certId", "Thumbprint":
117+
continue // Skip header
118+
}
119+
120+
certs[entry[0]] = RotCert{
121+
ThumbPrint: entry[0],
122+
}
123+
// Get certificate context
124+
//args := &api.GetCertificateContextArgs{
125+
// IncludeMetadata: boolToPointer(true),
126+
// IncludeLocations: boolToPointer(true),
127+
// CollectionId: nil,
128+
// Id: certificateIdInt,
129+
//}
130+
//cResp, err := r.p.client.GetCertificateContext(args)
131+
}
132+
return certs, nil
133+
}
134+
97135
var rotGenStoreTemplateCmd = &cobra.Command{
98136
Use: "generate-template-rot",
99137
Short: "For generating Root Of Trust template(s)",
@@ -177,7 +215,10 @@ func init() {
177215
var certs string
178216
rotCmd.Flags().StringVarP(&stores, "stores", "s", "", "CSV file containing cert stores to enroll into")
179217
rotCmd.MarkFlagRequired("stores")
180-
rotCmd.Flags().StringVarP(&certs, "certs", "c", "", "CSV file containing cert(s) to enroll into the defined cert stores")
218+
rotCmd.Flags().StringVarP(&certs, "add-certs", "a", "", "CSV file containing cert(s) to enroll into the defined cert stores")
219+
rotCmd.Flags().StringVarP(&certs, "remove-certs", "r", "", "CSV file containing cert(s) to remove from the defined cert stores")
220+
221+
rotCmd.Flags().BoolP("dry-run", "d", false, "Dry run mode")
181222
rotCmd.MarkFlagRequired("certs")
182223
storesCmd.AddCommand(rotGenStoreTemplateCmd)
183224
rotGenStoreTemplateCmd.Flags().String("outpath", "template.csv", "Output file to write the template to")

0 commit comments

Comments
 (0)