forked from kubescape/kubescape
-
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.
Merge pull request kubescape#894 from kubescape/dev
Enhancing CLI capabilities and SARIF output
- Loading branch information
Showing
43 changed files
with
1,225 additions
and
156 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package update | ||
|
||
//This update command updates to the latest kubescape release. | ||
//Example:- | ||
// kubescape update | ||
|
||
import ( | ||
"os/exec" | ||
"runtime" | ||
|
||
logger "github.com/kubescape/go-logger" | ||
"github.com/kubescape/kubescape/v2/core/cautils" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func GetUpdateCmd() *cobra.Command { | ||
updateCmd := &cobra.Command{ | ||
Use: "update", | ||
Short: "Update your version", | ||
Long: ``, | ||
RunE: func(_ *cobra.Command, args []string) error { | ||
//Checking the user's version of kubescape to the latest release | ||
if cautils.BuildNumber == cautils.LatestReleaseVersion { | ||
//your version == latest version | ||
logger.L().Info(("You are in the latest version")) | ||
} else { | ||
|
||
const OSTYPE string = runtime.GOOS | ||
var ShellToUse string | ||
switch OSTYPE { | ||
|
||
case "windows": | ||
cautils.StartSpinner() | ||
//run the installation command for windows | ||
ShellToUse = "powershell" | ||
_, err := exec.Command(ShellToUse, "-c", "iwr -useb https://raw.githubusercontent.com/kubescape/kubescape/master/install.ps1 | iex").Output() | ||
|
||
if err != nil { | ||
logger.L().Fatal(err.Error()) | ||
} | ||
cautils.StopSpinner() | ||
|
||
default: | ||
ShellToUse = "bash" | ||
cautils.StartSpinner() | ||
//run the installation command for linux and macOS | ||
_, err := exec.Command(ShellToUse, "-c", "curl -s https://raw.githubusercontent.com/kubescape/kubescape/master/install.sh | /bin/bash").Output() | ||
if err != nil { | ||
logger.L().Fatal(err.Error()) | ||
} | ||
|
||
cautils.StopSpinner() | ||
} | ||
} | ||
return nil | ||
}, | ||
} | ||
return updateCmd | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package getter | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
containeranalysis "cloud.google.com/go/containeranalysis/apiv1" | ||
) | ||
|
||
type GCPCloudAPI struct { | ||
credentialsPath string | ||
context context.Context | ||
client *containeranalysis.Client | ||
projectID string | ||
credentialsCheck bool | ||
} | ||
|
||
func GetGlobalGCPCloudAPIConnector() *GCPCloudAPI { | ||
|
||
if os.Getenv("KS_GCP_CREDENTIALS_PATH") == "" || os.Getenv("KS_GCP_PROJECT_ID") == "" { | ||
return &GCPCloudAPI{ | ||
credentialsCheck: false, | ||
} | ||
} else { | ||
return &GCPCloudAPI{ | ||
context: context.Background(), | ||
credentialsPath: os.Getenv("KS_GCP_CREDENTIALS_PATH"), | ||
projectID: os.Getenv("KS_GCP_PROJECT_ID"), | ||
credentialsCheck: true, | ||
} | ||
} | ||
} | ||
|
||
func (api *GCPCloudAPI) SetClient(client *containeranalysis.Client) { | ||
api.client = client | ||
} | ||
|
||
func (api *GCPCloudAPI) GetCredentialsPath() string { return api.credentialsPath } | ||
func (api *GCPCloudAPI) GetClient() *containeranalysis.Client { return api.client } | ||
func (api *GCPCloudAPI) GetProjectID() string { return api.projectID } | ||
func (api *GCPCloudAPI) GetCredentialsCheck() bool { return api.credentialsCheck } | ||
func (api *GCPCloudAPI) GetContext() context.Context { return api.context } |
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
Oops, something went wrong.