-
Notifications
You must be signed in to change notification settings - Fork 25
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
feature(cli): The new lacework-cli MVP #28
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4ae8b8e
chore(deps): Add a few Go dependencies 🙌
afiune 34a73b6
feat(cli): the new lacework-cli MVP 🔥🔥
afiune bb96b3b
feat(cli): Installation scripts and documentation 🎉
afiune 9311b8f
fix(release): tar linux binaries
afiune 9d17b1f
fix(install): configurable installation_dir
afiune File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.DS_Store | ||
.idea | ||
|
||
# vim | ||
|
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,80 @@ | ||
<img src="https://techally-content.s3-us-west-1.amazonaws.com/public-content/lacework_logo_full.png" width="600"> | ||
|
||
# `lacework-cli` | ||
|
||
The Lacework Command Line Interface is a tool that helps you manage your | ||
Lacework cloud security platform. You can use it to manage compliance | ||
reports, external integrations, vulnerability scans, and other operations. | ||
|
||
## Install | ||
|
||
### Bash: | ||
``` | ||
$ curl https://raw.githubusercontent.com/lacework/go-sdk/master/cli/install.sh | sudo bash | ||
``` | ||
|
||
### Powershell: | ||
``` | ||
C:\> Set-ExecutionPolicy Bypass -Scope Process -Force | ||
C:\> iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/lacework/go-sdk/master/cli/install.ps1')) | ||
``` | ||
|
||
## Configuration File | ||
|
||
The `lacework-cli` looks for a file named `.lacework.toml` inside your home | ||
directory (`$HOME/.lacework.toml`) to access the following parameters: | ||
* `account`: Account subdomain of URL (i.e. `<ACCOUNT>.lacework.net`) | ||
* `api_key`: API Access Key ID | ||
* `api_secret`: API Access Secret Key | ||
|
||
|
||
An example of a Lacework configuration file: | ||
```toml | ||
account = "example" | ||
api_key = "EXAMPLE_1234567890ABC" | ||
api_secret = "_super_secret_key" | ||
``` | ||
|
||
You can provide a different configuration file with the option `--config`. | ||
|
||
## Basic Usage | ||
Once you have created your configuration file `$HOME/.lacework.toml`, | ||
you are ready to use the Lacework cli, a few basic commands are: | ||
|
||
1) List all integration in your account: | ||
```bash | ||
$ lacework-cli integration list | ||
``` | ||
1) Use the `api` command to access Lacework's ResfulAPI, for example, | ||
to get details about and specific event: | ||
```bash | ||
$ lacework-cli api get '/external/events/GetEventDetails?EVENT_ID=16700' | ||
``` | ||
|
||
## Development | ||
To build and install the CLI from source, use the `make install-cli` directive, | ||
this command will ask you to update your `PATH` environment variable to point | ||
to the compiled `lacework-cli` binary. | ||
``` | ||
$ make install-cli | ||
|
||
# Make sure to update your PATH with the command provided from the above command | ||
|
||
$ lacework-cli help | ||
``` | ||
|
||
## License and Copyright | ||
Copyright 2020, Lacework Inc. | ||
``` | ||
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. | ||
``` |
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 @@ | ||
0.1.0 |
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,123 @@ | ||
// | ||
// Author:: Salim Afiune Maya (<[email protected]>) | ||
// Copyright:: Copyright 2020, Lacework Inc. | ||
// License:: Apache License, Version 2.0 | ||
// | ||
// 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 ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/lacework/go-sdk/api" | ||
"github.com/lacework/go-sdk/internal/array" | ||
) | ||
|
||
var ( | ||
// list of valid API methods | ||
validApiMethods = []string{"get", "post", "delete", "patch"} | ||
|
||
// data to send for POST/PATCH request | ||
apiData string | ||
|
||
// apiCmd represents the api command | ||
apiCmd = &cobra.Command{ | ||
Use: "api <method> <path>", | ||
Short: "Helper to call Lacework's ResfulAPI", | ||
Long: `Use this helper to call any available Lacework API endpoint. | ||
|
||
An example, list all integrations configured in your account: | ||
|
||
lacework-cli api get /external/integrations | ||
|
||
For a complete list of available API endpoints visit: | ||
|
||
https://<ACCOUNT>.lacework.net/api/v1/external/docs | ||
`, | ||
Args: argsApiValidator, | ||
RunE: runApiCommand, | ||
} | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(apiCmd) | ||
|
||
apiCmd.Flags().StringVarP(&apiData, | ||
"data", "d", "", | ||
"data to send only for post and patch requests", | ||
) | ||
} | ||
|
||
func runApiCommand(cmd *cobra.Command, args []string) error { | ||
switch args[0] { | ||
case "post", "patch": | ||
if apiData == "" { | ||
return fmt.Errorf("missing '--data' parameter for post or patch requests") | ||
} | ||
case "delete", "get": | ||
if apiData != "" { | ||
return fmt.Errorf("use '--data' only for post and patch requests") | ||
} | ||
} | ||
|
||
lacework, err := api.NewClient(cli.Account, | ||
api.WithApiKeys(cli.KeyID, cli.Secret), | ||
) | ||
if err != nil { | ||
return errors.Wrap(err, "unable to generate Lacework API client") | ||
} | ||
|
||
cli.Log.Debugw("api client generated", | ||
"version", lacework.ApiVersion(), | ||
"base_url", lacework.URL(), | ||
) | ||
|
||
response := new(map[string]interface{}) | ||
err = lacework.RequestDecoder( | ||
strings.ToUpper(args[0]), | ||
strings.TrimPrefix(args[1], "/"), | ||
strings.NewReader(apiData), | ||
response, | ||
) | ||
if err != nil { | ||
return errors.Wrap(err, "unable to send the request") | ||
} | ||
|
||
pretty, err := cli.JsonF.Marshal(*response) | ||
if err != nil { | ||
cli.Log.Debugw("api response", "raw", response) | ||
return errors.Wrap(err, "unable to format json response") | ||
} | ||
|
||
fmt.Println(string(pretty)) | ||
return nil | ||
} | ||
|
||
func argsApiValidator(_ *cobra.Command, args []string) error { | ||
if len(args) != 2 { | ||
return errors.New("requires 2 argument. (method and path)") | ||
} | ||
if !array.ContainsStr(validApiMethods, args[0]) { | ||
return fmt.Errorf( | ||
"invalid method specified: '%s' (valid methods are %s)", | ||
args[0], validApiMethods, | ||
) | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// | ||
// Author:: Salim Afiune Maya (<[email protected]>) | ||
// Copyright:: Copyright 2020, Lacework Inc. | ||
// License:: Apache License, Version 2.0 | ||
// | ||
// 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 ( | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/lacework/go-sdk/api" | ||
) | ||
|
||
var ( | ||
// integrationCmd represents the integration command | ||
integrationCmd = &cobra.Command{ | ||
Use: "integration", | ||
Short: "Manage external integrations", | ||
} | ||
|
||
// integrationListCmd represents the list sub-command inside the integration command | ||
instegrationListCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "List all available external integrations", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
lacework, err := api.NewClient(cli.Account, | ||
api.WithApiKeys(cli.KeyID, cli.Secret), | ||
) | ||
if err != nil { | ||
return errors.Wrap(err, "unable to generate Lacework API client") | ||
} | ||
|
||
cli.Log.Debugw("api client generated", | ||
"version", lacework.ApiVersion(), | ||
"base_url", lacework.URL(), | ||
) | ||
|
||
integrations, err := lacework.Integrations.List() | ||
if err != nil { | ||
return errors.Wrap(err, "unable to get integrations") | ||
} | ||
|
||
fmt.Println(integrations.String()) | ||
return nil | ||
}, | ||
} | ||
|
||
// integrationCreateCmd represents the create sub-command inside the integration command | ||
instegrationCreateCmd = &cobra.Command{ | ||
Use: "create", | ||
Short: "Create an external integrations", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return nil | ||
}, | ||
} | ||
|
||
// integrationDeleteCmd represents the delete sub-command inside the integration command | ||
instegrationDeleteCmd = &cobra.Command{ | ||
Use: "delete", | ||
Short: "Delete an external integrations", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return nil | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
// add the integration command | ||
rootCmd.AddCommand(integrationCmd) | ||
|
||
// add sub-commands to the integration command | ||
integrationCmd.AddCommand(instegrationListCmd) | ||
integrationCmd.AddCommand(instegrationCreateCmd) | ||
integrationCmd.AddCommand(instegrationDeleteCmd) | ||
} |
Oops, something went wrong.
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.
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.
Should be "Restful"