Skip to content

Commit c8a23a2

Browse files
authored
Merge 12b3946 into 05690f3
2 parents 05690f3 + 12b3946 commit c8a23a2

File tree

15 files changed

+3515
-911
lines changed

15 files changed

+3515
-911
lines changed

.github/workflows/keyfactor-bootstrap-workflow.yml

Lines changed: 0 additions & 207 deletions
Original file line numberDiff line numberDiff line change
@@ -10,215 +10,8 @@ on:
1010
- 'release-*.*'
1111

1212
jobs:
13-
get-versions:
14-
runs-on: ubuntu-latest
15-
outputs:
16-
PR_BASE_REF: ${{ steps.set-outputs.outputs.PR_BASE_REF }}
17-
PR_COMMIT_SHA: ${{ steps.set-outputs.outputs.PR_COMMIT_SHA }}
18-
GITHUB_SHA: ${{ steps.set-outputs.outputs.GITHUB_SHA }}
19-
PR_BASE_TAG: ${{ steps.set-outputs.outputs.PR_BASE_TAG }}
20-
IS_FULL_RELEASE: ${{ steps.set-outputs.outputs.IS_FULL_RELEASE }}
21-
IS_PRE_RELEASE: ${{ steps.set-outputs.outputs.IS_PRE_RELEASE }}
22-
INC_LEVEL: ${{ steps.set-outputs.outputs.INC_LEVEL }}
23-
IS_RELEASE_BRANCH: ${{ steps.set-outputs.outputs.IS_RELEASE_BRANCH }}
24-
IS_HOTFIX: ${{ steps.set-outputs.outputs.IS_HOTFIX }}
25-
LATEST_TAG: ${{ steps.set-outputs.outputs.LATEST_TAG }}
26-
NEXT_VERSION: ${{ steps.set-outputs.outputs.NEW_PKG_VERSION }}
27-
28-
steps:
29-
- name: Check out the code
30-
uses: actions/checkout@v3
31-
with:
32-
token: ${{ secrets.V2BUILDTOKEN}}
33-
34-
- name: Display base.ref from Pull Request
35-
if: github.event_name == 'pull_request'
36-
id: display-from-pr
37-
run: |
38-
echo "Event: ${{ github.event_name }}" | tee -a $GITHUB_STEP_SUMMARY
39-
echo "Event Action: ${{ github.event.action }}" | tee -a $GITHUB_STEP_SUMMARY
40-
echo "PR_BASE_REF=${{ github.event.pull_request.base.ref }}" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
41-
echo "PR_STATE=${{ github.event.pull_request.state }}" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
42-
echo "PR_MERGED=${{ github.event.pull_request.merged }}" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
43-
echo "PR_COMMIT_SHA=${{ github.event.pull_request.merge_commit_sha }}" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
44-
echo "GITHUB_SHA=${{ github.sha }}" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
45-
baseref="${{ github.event.pull_request.base.ref }}"
46-
basetag="${baseref#release-}"
47-
echo "PR_BASE_TAG=$basetag" | tee -a "$GITHUB_ENV" | tee -a $GITHUB_STEP_SUMMARY
48-
49-
- name: Display base_ref from Push Event
50-
if: github.event_name == 'push'
51-
id: display-from-push
52-
run: |
53-
echo "Branch Ref: ${{ github.ref }}" | tee -a $GITHUB_STEP_SUMMARY
54-
echo "Event: ${{ github.event_name }}" | tee -a $GITHUB_STEP_SUMMARY
55-
echo "github.sha: ${{ github.sha }}" | tee -a $GITHUB_STEP_SUMMARY
56-
57-
- name: Find Latest Tag
58-
if: github.event_name == 'pull_request'
59-
id: find-latest-tag
60-
run: |
61-
prbasetag="${{env.PR_BASE_TAG}}"
62-
git fetch --tags
63-
if [[ -n `git tag` ]]; then
64-
echo "Setting vars"
65-
allBranchTags=`git tag --sort=-v:refname | grep "^$prbasetag" || echo ""`
66-
allRepoTags=`git tag --sort=-v:refname`
67-
branchTagBase=`git tag --sort=-v:refname | grep "^$prbasetag" | grep -o '^[0-9.]*' | head -n 1 || echo ""`
68-
latestTagBase=`git tag --sort=-v:refname | grep -o '^[0-9.]*' | head -n 1`
69-
latestBranchTag=`git tag --sort=-v:refname | grep "^$prbasetag" | grep "^$branchTagBase" | head -n 1 || echo ""`
70-
latestReleasedTag=`git tag --sort=-v:refname | grep "^$prbasetag" | grep "^$branchTagBase$" | head -n 1 || echo ""`
71-
72-
# If the *TagBase values are not found in the list of tags, it means no final release was produced, and the latest*Tag vars will be empty
73-
if [[ -z "$latestReleasedTag" ]]; then
74-
latestTag="$latestBranchTag"
75-
else
76-
latestTag="$latestReleasedTag"
77-
fi
78-
echo "LATEST_TAG=${latestTag}" | tee -a "$GITHUB_ENV"
79-
80-
if [[ "$latestTagBase" == *"$branchTagBase" ]]; then
81-
hf="False"
82-
else
83-
hf="True"
84-
fi
85-
86-
# The intention is to use this to set the make_latest:false property when
87-
# dispatching the create-release action, but it is not *yet* a configurable option
88-
echo "IS_HOTFIX=$hf" | tee -a "$GITHUB_ENV"
89-
else
90-
echo "No tags exist in this repo"
91-
echo "LATEST_TAG=" | tee -a "$GITHUB_ENV"
92-
fi
93-
- name: Set Outputs
94-
id: set-outputs
95-
run: |
96-
echo "PR_BASE_REF=${{ env.PR_BASE_REF }}" | tee -a "$GITHUB_OUTPUT"
97-
echo "PR_STATE=${{ env.PR_STATE }}"
98-
echo "PR_MERGED=${{ env.PR_MERGED }}"
99-
if [[ "${{ env.PR_STATE }}" == "closed" && "${{ env.PR_MERGED }}" == "true" && "${{ env.PR_COMMIT_SHA }}" == "${{ env.GITHUB_SHA }}" ]]; then
100-
echo "IS_FULL_RELEASE=True" | tee -a "$GITHUB_OUTPUT"
101-
echo "INC_LEVEL=patch" | tee -a "$GITHUB_OUTPUT"
102-
fi
103-
if [[ "${{ env.PR_STATE }}" == "open" ]]; then
104-
echo "IS_PRE_RELEASE=True" | tee -a "$GITHUB_OUTPUT" | tee -a "$GITHUB_ENV"
105-
echo "INC_LEVEL=prerelease" | tee -a "$GITHUB_OUTPUT"
106-
fi
107-
if [[ "${{ env.PR_BASE_REF }}" == "release-"* ]]; then
108-
echo "IS_RELEASE_BRANCH=True" | tee -a "$GITHUB_OUTPUT" | tee -a "$GITHUB_ENV"
109-
fi
110-
echo "PR_COMMIT_SHA=${{ env.PR_COMMIT_SHA }}" | tee -a "$GITHUB_OUTPUT"
111-
echo "GITHUB_SHA=${{ env.GITHUB_SHA }}" | tee -a "$GITHUB_OUTPUT"
112-
echo "PR_BASE_TAG=${{ env.PR_BASE_TAG }}" | tee -a "$GITHUB_OUTPUT"
113-
echo "IS_HOTFIX=${{ env.IS_HOTFIX }}" | tee -a "$GITHUB_OUTPUT"
114-
echo "LATEST_TAG=${{ env.LATEST_TAG }}" | tee -a "$GITHUB_OUTPUT"
115-
116-
# check-package-version:
117-
# needs: get-versions
118-
# if: github.event_name == 'pull_request' && needs.get-versions.outputs.IS_RELEASE_BRANCH == 'True'
119-
# outputs:
120-
# release_version: ${{ steps.create_release.outputs.current_tag }}
121-
# release_url: ${{ steps.create_release.outputs.upload_url }}
122-
# update_version: ${{ steps.check_version.outputs.update_version }}
123-
# next_version: ${{ steps.set-semver-info.outputs.new_version }}
124-
# runs-on: ubuntu-latest
125-
# steps:
126-
# - name: Check out the code
127-
# uses: actions/checkout@v3
128-
# - run: |
129-
# echo "INC_LEVEL=${{ needs.get-versions.outputs.INC_LEVEL}}"
130-
# - name: Check if initial release
131-
# if: needs.get-versions.outputs.LATEST_TAG == ''
132-
# run: |
133-
# echo "INITIAL_VERSION=${{needs.get-versions.outputs.PR_BASE_TAG}}.0-rc.0" | tee -a "$GITHUB_STEP_SUMMARY" | tee -a "$GITHUB_ENV"
134-
# echo "MANUAL_VERSION=${{needs.get-versions.outputs.PR_BASE_TAG}}.0-rc.0" | tee -a "$GITHUB_ENV"
135-
# - name: Set semver info
136-
# id: set-semver-info
137-
# if: needs.get-versions.outputs.LATEST_TAG != ''
138-
# uses: fiddlermikey/action-bump-semver@main
139-
# with:
140-
# current_version: ${{ needs.get-versions.outputs.LATEST_TAG}}
141-
# level: ${{ needs.get-versions.outputs.INC_LEVEL}}
142-
# preID: rc
143-
# - name: Show next sem-version
144-
# if: needs.get-versions.outputs.LATEST_TAG != ''
145-
# run: |
146-
# echo "MANUAL_VERSION=${{ steps.set-semver-info.outputs.new_version }}" > "$GITHUB_ENV"
147-
# - run: |
148-
# echo "Next version: ${{ env.MANUAL_VERSION }}" | tee -a "$GITHUB_STEP_SUMMARY"
149-
#
150-
# - name: Get Package Version
151-
# id: get-pkg-version
152-
# run: |
153-
# pwd
154-
# ls -la
155-
# echo "CURRENT_PKG_VERSION=$(cat pkg/version/version.go | grep 'const VERSION' | awk '{print $NF}' | tr -d '"')" | tee -a "$GITHUB_ENV"
156-
# - name: Compare package version
157-
# id: check_version
158-
# run: |
159-
# if [ "${{ env.CURRENT_PKG_VERSION }}" != "${{ env.MANUAL_VERSION }}" ]; then
160-
# echo "Updating version in version.go"
161-
# echo "update_version=true" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
162-
# echo "update_version=true" | tee -a "$GITHUB_STEP_SUMMARY"
163-
# else
164-
# echo "Versions match, no update needed"
165-
# echo "update_version=false" | tee -a $GITHUB_ENV | tee -a $GITHUB_OUTPUT
166-
# echo "update_version=false" | tee -a $GITHUB_STEP_SUMMARY
167-
# fi
168-
# env:
169-
# UPDATE_VERSION: ${{ steps.check_version.outputs.update_version }}
170-
#
171-
# - name: Set Outputs
172-
# id: set-outputs
173-
# if: needs.get-versions.outputs.LATEST_TAG != ''
174-
# run: |
175-
# echo "UPDATE_VERSION=${{ steps.check_version.outputs.update_version }}" | tee -a "$GITHUB_OUTPUT"
176-
# echo "CURRENT_PKG_VERSION=${{ env.CURRENT_PKG_VERSION }}" | tee -a "$GITHUB_OUTPUT"
177-
# echo "MANUAL_VERSION=${{ env.MANUAL_VERSION }}" | tee -a "$GITHUB_OUTPUT"
178-
# echo "NEW_PKG_VERSION=${{ env.MANUAL_VERSION }}" | tee -a "$GITHUB_OUTPUT"
179-
#
180-
# update-pkg-version:
181-
# needs:
182-
# - check-package-version
183-
# runs-on: ubuntu-latest
184-
#
185-
# steps:
186-
# - name: Checkout repository
187-
# uses: actions/checkout@v3
188-
# with:
189-
# token: ${{ secrets.V2BUILDTOKEN}}
190-
# - name: No Update
191-
# if: ${{ needs.check-package-version.outputs.update_version != 'true' }}
192-
# run: |
193-
# echo "Versions match, no update needed"
194-
# exit 0
195-
#
196-
# - name: Commit to PR branch
197-
# id: commit-version
198-
# if: ${{ needs.check-package-version.outputs.update_version == 'true' }}
199-
# env:
200-
# AUTHOR_EMAIL: [email protected]
201-
# AUTHOR_NAME: Keyfactor Robot
202-
# GITHUB_TOKEN: ${{ secrets.V2BUILDTOKEN}}
203-
# run: |
204-
# git remote -v
205-
# echo "Checking out ${{ github.head_ref }}"
206-
# git fetch
207-
# echo "git checkout -b ${{ github.head_ref }}"
208-
# git checkout -b ${{ github.head_ref }}
209-
# git reset --hard origin/${{ github.head_ref }}
210-
# sed -i "s/const VERSION = .*/const VERSION = \"${{ needs.check-package-version.outputs.next_version }}\"/" pkg/version/version.go
211-
# git add pkg/version/version.go
212-
# git config --global user.email "${{ env.AUTHOR_EMAIL }}"
213-
# git config --global user.name "${{ env.AUTHOR_NAME }}"
214-
# git commit -m "Bump package version to ${{ needs.check-package-version.outputs.next_version }}"
215-
# git push --set-upstream origin ${{ github.head_ref }}
216-
# echo "Version mismatch! Please create a new pull request with the updated version."
217-
# exit 1
218-
21913
call-starter-workflow:
22014
uses: keyfactor/actions/.github/workflows/starter.yml@v2
221-
needs: get-versions
22215
secrets:
22316
token: ${{ secrets.V2BUILDTOKEN}}
22417
APPROVE_README_PUSH: ${{ secrets.APPROVE_README_PUSH}}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,4 @@ alternatively you can specify the parent command
440440
cobra-cli add <my-new-command> -p '<parent>Cmd'
441441
```
442442
443+

cmd/constants.go

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Keyfactor
1+
// Package cmd Copyright 2024 Keyfactor
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -16,28 +16,47 @@ package cmd
1616
import "fmt"
1717

1818
const (
19-
ColorRed = "\033[31m"
20-
ColorWhite = "\033[37m"
21-
DefaultAPIPath = "KeyfactorAPI"
22-
DefaultConfigFileName = "command_config.json"
23-
FailedAuthMsg = "Login failed!"
24-
SuccessfulAuthMsg = "Login successful!"
25-
XKeyfactorRequestedWith = "APIClient"
26-
XKeyfactorApiVersion = "1"
27-
FlagGitRef = "git-ref"
28-
FlagFromFile = "from-file"
29-
DebugFuncEnter = "entered: %s"
30-
DebugFuncExit = "exiting: %s"
31-
DebugFuncCall = "calling: %s"
19+
ColorRed = "\033[31m"
20+
ColorWhite = "\033[37m"
21+
DefaultAPIPath = "KeyfactorAPI"
22+
DefaultConfigFileName = "command_config.json"
23+
DefaultROTAuditStoresOutfilePath = "rot_audit_selected_stores.csv"
24+
DefaultROTAuditAddCertsOutfilePath = "rot_audit_selected_certs_add.csv"
25+
DefaultROTAuditRemoveCertsOutfilePath = "rot_audit_selected_certs_remove.csv"
26+
FailedAuthMsg = "Login failed!"
27+
SuccessfulAuthMsg = "Login successful!"
28+
XKeyfactorRequestedWith = "APIClient"
29+
XKeyfactorApiVersion = "1"
30+
FlagGitRef = "git-ref"
31+
FlagFromFile = "from-file"
32+
DebugFuncEnter = "entered: %s"
33+
DebugFuncExit = "exiting: %s"
34+
DebugFuncCall = "calling: %s"
35+
ErrMsgEmptyResponse = "empty response received from Keyfactor Command %s"
36+
)
37+
38+
// CLI Menu Defaults
39+
const (
40+
DefaultMenuPageSizeSmall = 25
41+
DefaultMenuPageSizeLarge = 100
42+
)
43+
44+
var (
45+
DefaultSourceTypeOptions = []string{"API", "File"}
3246
)
3347

3448
var ProviderTypeChoices = []string{
3549
"azid",
3650
}
3751
var ValidAuthProviders = [2]string{"azure-id", "azid"}
52+
var ErrKfcEmptyResponse = fmt.Errorf("empty response recieved from Keyfactor Command")
3853

3954
// Error messages
4055
var (
41-
StoreTypeReadError = fmt.Errorf("error reading store type from configuration file")
42-
InvalidInputError = fmt.Errorf("invalid input")
56+
StoreTypeReadError = fmt.Errorf("error reading store type from configuration file")
57+
InvalidInputError = fmt.Errorf("invalid input")
58+
InvalidROTCertsInputErr = fmt.Errorf(
59+
"at least one of `--add-certs` or `--remove-certs` is required to perform a" +
60+
" root of trust audit",
61+
)
4362
)

cmd/export.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ import (
1818
"context"
1919
"encoding/json"
2020
"fmt"
21+
"os"
22+
"strconv"
23+
2124
"github.com/Keyfactor/keyfactor-go-client-sdk/api/keyfactor"
2225
"github.com/Keyfactor/keyfactor-go-client/v2/api"
2326
"github.com/rs/zerolog/log"
2427
"github.com/spf13/cobra"
25-
"os"
26-
"strconv"
2728
)
2829

2930
var exportPath string
@@ -371,8 +372,10 @@ func getIssuedAlerts(kfClient *keyfactor.APIClient) []keyfactor.KeyfactorApiMode
371372
func getDeniedAlerts(kfClient *keyfactor.APIClient) []keyfactor.KeyfactorApiModelsAlertsDeniedDeniedAlertCreationRequest {
372373

373374
alerts, _, reqErr := kfClient.DeniedAlertApi.DeniedAlertGetDeniedAlerts(
374-
context.Background()).XKeyfactorRequestedWith(
375-
XKeyfactorRequestedWith).XKeyfactorApiVersion(XKeyfactorApiVersion).Execute()
375+
context.Background(),
376+
).XKeyfactorRequestedWith(
377+
XKeyfactorRequestedWith,
378+
).XKeyfactorApiVersion(XKeyfactorApiVersion).Execute()
376379
if reqErr != nil {
377380
fmt.Printf("%s Error! Unable to get denied cert alerts %s%s\n", ColorRed, reqErr, ColorWhite)
378381
}
@@ -575,7 +578,13 @@ func init() {
575578
exportCmd.Flags().Lookup("collections").NoOptDefVal = "true"
576579
exportCmd.Flags().BoolVarP(&fMetadata, "metadata", "m", false, "export metadata to JSON file")
577580
exportCmd.Flags().Lookup("metadata").NoOptDefVal = "true"
578-
exportCmd.Flags().BoolVarP(&fExpirationAlerts, "expiration-alerts", "e", false, "export expiration cert alerts to JSON file")
581+
exportCmd.Flags().BoolVarP(
582+
&fExpirationAlerts,
583+
"expiration-alerts",
584+
"e",
585+
false,
586+
"export expiration cert alerts to JSON file",
587+
)
579588
exportCmd.Flags().Lookup("expiration-alerts").NoOptDefVal = "true"
580589
exportCmd.Flags().BoolVarP(&fIssuedAlerts, "issued-alerts", "i", false, "export issued cert alerts to JSON file")
581590
exportCmd.Flags().Lookup("issued-alerts").NoOptDefVal = "true"
@@ -585,7 +594,13 @@ func init() {
585594
exportCmd.Flags().Lookup("pending-alerts").NoOptDefVal = "true"
586595
exportCmd.Flags().BoolVarP(&fNetworks, "networks", "n", false, "export SSL networks to JSON file")
587596
exportCmd.Flags().Lookup("networks").NoOptDefVal = "true"
588-
exportCmd.Flags().BoolVarP(&fWorkflowDefinitions, "workflow-definitions", "w", false, "export workflow definitions to JSON file")
597+
exportCmd.Flags().BoolVarP(
598+
&fWorkflowDefinitions,
599+
"workflow-definitions",
600+
"w",
601+
false,
602+
"export workflow definitions to JSON file",
603+
)
589604
exportCmd.Flags().Lookup("workflow-definitions").NoOptDefVal = "true"
590605
exportCmd.Flags().BoolVarP(&fReports, "reports", "r", false, "export reports to JSON file")
591606
exportCmd.Flags().Lookup("reports").NoOptDefVal = "true"

cmd/helpers.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,34 @@ import (
1919
"encoding/json"
2020
"errors"
2121
"fmt"
22-
"github.com/google/uuid"
23-
"github.com/rs/zerolog"
24-
"github.com/rs/zerolog/log"
25-
"github.com/spf13/cobra"
2622
"io"
2723
"net/http"
2824
"os"
2925
"path/filepath"
3026
"strconv"
3127
"time"
28+
29+
"github.com/google/uuid"
30+
"github.com/rs/zerolog"
31+
"github.com/rs/zerolog/log"
32+
"github.com/spf13/cobra"
3233
)
3334

35+
func mergeErrsToString(errs *[]error, indent bool) string {
36+
var errStr string
37+
if errs == nil || len(*errs) == 0 {
38+
return ""
39+
}
40+
for _, err := range *errs {
41+
if indent {
42+
errStr += fmt.Sprintf(" \t%s\r\n", err)
43+
continue
44+
}
45+
errStr += fmt.Sprintf("%s\r\n", err)
46+
}
47+
return errStr
48+
}
49+
3450
func boolToPointer(b bool) *bool {
3551
return &b
3652
}

0 commit comments

Comments
 (0)