-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat add security command #168
Closed
Closed
Conversation
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
Signed-off-by: mahbub570 <[email protected]>
bupd
requested changes
Aug 16, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Giving Table as defautlt for summary would be better.
@mahbub570 Changes in package security
import (
"fmt"
"github.com/goharbor/harbor-cli/pkg/api"
"github.com/goharbor/harbor-cli/pkg/views/security/summary"
"github.com/spf13/cobra"
)
func getSecuritySummaryCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "summary",
Short: "Get the security summary of the system",
RunE: func(cmd *cobra.Command, args []string) error {
response,err := api.GetSecuritySummary()
if err != nil {
return fmt.Errorf("error getting security summary: %w", err)
}
summary.SecuritySummary(response.Payload)
return nil
},
}
return cmd
} |
Changes in package api
import (
"github.com/goharbor/go-client/pkg/sdk/v2.0/client/securityhub"
"github.com/goharbor/harbor-cli/pkg/utils"
)
func GetSecuritySummary() (*securityhub.GetSecuritySummaryOK, error) {
ctx, client, err := utils.ContextWithClient()
if err != nil {
return nil, err
}
response, err := client.Securityhub.GetSecuritySummary(ctx,&securityhub.GetSecuritySummaryParams{})
if err != nil {
return nil,err
}
return response,nil
}
func ListVulnerabilities(query string) error {
ctx, client, err := utils.ContextWithClient()
if err != nil {
return err
}
params := &securityhub.ListVulnerabilitiesParams{
Q: &query,
}
response, err := client.Securityhub.ListVulnerabilities(ctx, params)
if err != nil {
return err
}
utils.PrintPayloadInJSONFormat(response.Payload)
return nil
} |
Create new file in package summary
import (
"fmt"
"os"
"github.com/charmbracelet/bubbles/table"
tea "github.com/charmbracelet/bubbletea"
"github.com/goharbor/go-client/pkg/sdk/v2.0/models"
"github.com/goharbor/harbor-cli/pkg/views/base/tablelist"
)
var columns = []table.Column{
{Title: "Summary", Width: 25},
{Title: "Value", Width: 15},
}
func SecuritySummary(summary *models.SecuritySummary) {
var rows []table.Row
rows = append(rows, table.Row{"Critical Count", fmt.Sprintf("%d",summary.CriticalCnt)})
rows = append(rows, table.Row{"Fixable Count", fmt.Sprintf("%d",summary.FixableCnt)})
rows = append(rows, table.Row{"High Count", fmt.Sprintf("%d",summary.HighCnt)})
rows = append(rows, table.Row{"Low Count", fmt.Sprintf("%d",summary.LowCnt)})
rows = append(rows, table.Row{"Medium Count", fmt.Sprintf("%d",summary.MediumCnt)})
rows = append(rows, table.Row{"Scanned Count", fmt.Sprintf("%d",summary.ScannedCnt)})
rows = append(rows, table.Row{"None Count", fmt.Sprintf("%d",summary.NoneCnt)})
rows = append(rows, table.Row{"Unknown Count", fmt.Sprintf("%d",summary.UnknownCnt)})
rows = append(rows, table.Row{"Total Artifact", fmt.Sprintf("%d",summary.TotalArtifact)})
rows = append(rows, table.Row{"Total Vulnerability", fmt.Sprintf("%d",summary.TotalVuls)})
m := tablelist.NewModel(columns, rows, len(rows))
if _, err := tea.NewProgram(m).Run(); err != nil {
fmt.Println("Error running program:", err)
os.Exit(1)
}
} |
Signed-off-by: axif <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implements functions to fetch and display the security summary and vulnerabilities list
New Command:
harbor security summary
harbor security vulnerabilities
Fix: #94