-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding ability to list attestors (#384)
* adding ability to list attestors Signed-off-by: chaosinthecrd <[email protected]> * adding labels for default and always run attestors Signed-off-by: chaosinthecrd <[email protected]> * whoops, forgot to add the new file Signed-off-by: chaosinthecrd <[email protected]> * updating to include command-run attestor Signed-off-by: chaosinthecrd <[email protected]> * updating docs Signed-off-by: chaosinthecrd <[email protected]> * adding continue Signed-off-by: chaosinthecrd <[email protected]> --------- Signed-off-by: chaosinthecrd <[email protected]>
- Loading branch information
1 parent
1fbdaa9
commit 6f7d4a8
Showing
7 changed files
with
125 additions
and
3 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,75 @@ | ||
// Copyright 2021 The Witness Contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/in-toto/go-witness/attestation" | ||
"github.com/in-toto/witness/options" | ||
"github.com/olekukonko/tablewriter" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func AttestorsCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "attestors", | ||
Short: "List all available attestors", | ||
Long: "Lists all the available attestors in Witness with supporting information", | ||
SilenceErrors: true, | ||
SilenceUsage: true, | ||
DisableAutoGenTag: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return runAttestors(cmd.Context()) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func runAttestors(ctx context.Context) error { | ||
items := [][]string{} | ||
entries := attestation.RegistrationEntries() | ||
for _, entry := range entries { | ||
name := entry.Factory().Name() | ||
|
||
for _, a := range alwaysRunAttestors { | ||
if name == a.Name() || name == "command-run" { | ||
name = name + " (always run)" | ||
} | ||
} | ||
|
||
for _, a := range options.DefaultAttestors { | ||
if name == a { | ||
name = name + " (default)" | ||
} | ||
} | ||
|
||
runType := entry.Factory().RunType() | ||
item := []string{name, entry.Factory().Type(), fmt.Sprintf("%v", runType)} | ||
items = append(items, item) | ||
} | ||
|
||
table := tablewriter.NewWriter(os.Stdout) | ||
table.SetHeader([]string{"Name", "Type", "RunType"}) | ||
table.SetAutoMergeCells(false) | ||
table.SetRowLine(false) | ||
table.AppendBulk(items) | ||
table.Render() | ||
|
||
return nil | ||
} |
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