Skip to content

Commit

Permalink
feat(cli): Installation scripts and documentation 🎉
Browse files Browse the repository at this point in the history
Signed-off-by: Salim Afiune Maya <[email protected]>
  • Loading branch information
afiune committed Mar 26, 2020
1 parent 34a73b6 commit bb96b3b
Show file tree
Hide file tree
Showing 6 changed files with 467 additions and 13 deletions.
35 changes: 27 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
default: ci

ci: lint test fmt-check imports-check

export GOFLAGS=-mod=vendor
ci: lint test fmt-check imports-check build-cli-cross-platform

GOLANGCILINTVERSION?=1.23.8
COVERAGEOUT?=coverage.out
CLINAME?=lacework-cli
GO_LDFLAGS="-X github.com/lacework/go-sdk/cli/cmd.Version=$(shell cat cli/VERSION) \
-X github.com/lacework/go-sdk/cli/cmd.GitSHA=$(shell git rev-parse HEAD) \
-X github.com/lacework/go-sdk/cli/cmd.BuildTime=$(shell date +%Y%m%d%H%M%S)"
GOFLAGS=-mod=vendor
export GOFLAGS GO_LDFLAGS

prepare: install-tools go-vendor

Expand Down Expand Up @@ -37,11 +40,24 @@ fmt-check:
imports-check:
@test -z $(shell goimports -l $(shell go list -f {{.Dir}} ./...))

build-cli:
go build -o bin/$(CLINAME) cli/main.go
@echo
@echo To execute the generated binary run:
@echo " ./bin/$(CLINAME)"
build-cli-cross-platform:
gox -output="bin/$(CLINAME)-{{.OS}}-{{.Arch}}" \
-os="darwin linux windows" \
-arch="amd64 386" \
-ldflags=$(GO_LDFLAGS) \
github.com/lacework/go-sdk/cli

install-cli: build-cli-cross-platform
ifeq (x86_64, $(shell uname -m))
ln -sf bin/$(CLINAME)-$(shell uname -s | tr '[:upper:]' '[:lower:]')-amd64 bin/$(CLINAME)
else
ln -sf bin/$(CLINAME)-$(shell uname -s | tr '[:upper:]' '[:lower:]')-386 bin/$(CLINAME)
endif
@echo "\nUpdate your PATH environment variable to execute the compiled lacework-cli:"
@echo "\n $$ export PATH=\"$(PWD)/bin:$$PATH\"\n"

release-cli: lint fmt-check imports-check test
scripts/lacework_cli_release.sh

install-tools:
ifeq (, $(shell which golangci-lint))
Expand All @@ -50,3 +66,6 @@ endif
ifeq (, $(shell which goimports))
go get golang.org/x/tools/cmd/goimports
endif
ifeq (, $(shell which gox))
go get github.com/mitchellh/gox
endif
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,21 @@ Look at the [api/](api/) folder for more documentation.

## Lacework CLI ([`cli`](cli/))

_(work-in-progress)_ The Lacework Command Line Interface.
The Lacework Command Line Interface.

### Basic Usage

Today, you have to first build the CLI by running `make build-cli`, then you will be
able to execute it directly:
Build and install the CLI by running `make install-cli`, the automation will
ask you to update your `PATH` environment variable to execute the compiled
`lacework-cli` binary.
```
$ make build-cli
$ ./bin/lacework-cli
$ make install-cli
# Make sure to update your PATH with the command provided from the above command
$ lacework-cli help
```
Look at the [cli/](cli/) folder for more documentation.

## License and Copyright
Copyright 2020, Lacework Inc.
Expand Down
80 changes: 80 additions & 0 deletions cli/README.md
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.
```
13 changes: 13 additions & 0 deletions cli/install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<#
.SYNOPSIS
Installs the 'lacework-cli' tool.
.Parameter Version
Specifies a version (ex: 0.1.0)
#>

$ErrorActionPreference="stop"

Set-Variable GithubReleasesRootUrl -Option ReadOnly -value "https://github.com/lacework/go-sdk/releases"

Write-Host "Comming soon! (Installatiohn of the 'lacework-cli' tool)"
Loading

0 comments on commit bb96b3b

Please sign in to comment.