Skip to content

Commit

Permalink
refactor(cli): rename cli binary to lacework
Browse files Browse the repository at this point in the history
Closes #41

Signed-off-by: Salim Afiune Maya <[email protected]>
  • Loading branch information
afiune committed Apr 7, 2020
1 parent 190412b commit 51ce22f
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 66 deletions.
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ ci: lint test fmt-check imports-check build-cli-cross-platform

GOLANGCILINTVERSION?=1.23.8
COVERAGEOUT?=coverage.out
CLINAME?=lacework-cli
PACKAGENAME?=lacework-cli
CLINAME?=lacework
GO_LDFLAGS="-X github.com/lacework/go-sdk/cli/cmd.Version=$(shell cat 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)"
Expand Down Expand Up @@ -41,23 +42,25 @@ imports-check:
@test -z $(shell goimports -l $(shell go list -f {{.Dir}} ./...))

build-cli-cross-platform:
gox -output="bin/$(CLINAME)-{{.OS}}-{{.Arch}}" \
gox -output="bin/$(PACKAGENAME)-{{.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)
mv bin/$(PACKAGENAME)-$(shell uname -s | tr '[:upper:]' '[:lower:]')-amd64 /usr/local/bin/$(CLINAME)
else
ln -sf bin/$(CLINAME)-$(shell uname -s | tr '[:upper:]' '[:lower:]')-386 bin/$(CLINAME)
mv bin/$(PACKAGENAME)-$(shell uname -s | tr '[:upper:]' '[:lower:]')-386 /usr/local/bin/$(CLINAME)
endif
@echo "\nUpdate your PATH environment variable to execute the compiled lacework-cli:"
@echo "\n $$ export PATH=\"$(PWD)/bin:$$PATH\"\n"
@echo "\nThe lacework cli has been installed at /usr/local/bin"

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

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

install-tools:
ifeq (, $(shell which golangci-lint))
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,25 @@ Look at the [api/](api/) folder for more documentation.

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

The Lacework Command Line Interface.
The Lacework Command Line Interface is a tool that helps you manage the
Lacework cloud security platform. You can use it to manage compliance
reports, external integrations, vulnerability scans, and other operations.

### Basic Usage

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.
install the tool at `/usr/local/bin/lacework`:
```
$ make install-cli
# Make sure to update your PATH with the command provided from the above command
$ lacework-cli help
$ lacework version
lacework v0.1.1 (sha:ca9f95d17f4f2092f89dba7b64eaed6db7493a5a) (time:20200406091143)
```
Look at the [cli/](cli/) folder for more documentation.

## 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.
Expand Down
14 changes: 7 additions & 7 deletions cli/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<img src="https://techally-content.s3-us-west-1.amazonaws.com/public-content/lacework_logo_full.png" width="600">

# `lacework-cli`
# Lacework cli

The Lacework Command Line Interface is a tool that helps you manage your
The Lacework Command Line Interface is a tool that helps you manage the
Lacework cloud security platform. You can use it to manage compliance
reports, external integrations, vulnerability scans, and other operations.

Expand All @@ -21,7 +21,7 @@ C:\> iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubus

## Configuration File

The `lacework-cli` looks for a file named `.lacework.toml` inside your home
The Lacework cli looks for a file named `.lacework.toml` inside your home
directory (`$HOME/.lacework.toml`) to access the following settings:
* `account`: Account subdomain of URL (i.e. `<ACCOUNT>.lacework.net`)
* `api_key`: API Access Key
Expand Down Expand Up @@ -55,24 +55,24 @@ 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
$ lacework integration list
```
1) Use the `api` command to access Lacework's RestfulAPI, for example,
to get details about and specific event:
```bash
$ lacework-cli api get '/external/events/GetEventDetails?EVENT_ID=16700'
$ lacework 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.
to the compiled `lacework` binary.
```
$ make install-cli
# Make sure to update your PATH with the command provided from the above command
$ lacework-cli help
$ lacework help
```

## License and Copyright
Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ var (
apiCmd = &cobra.Command{
Use: "api <method> <path>",
Short: "Helper to call Lacework's RestfulAPI",
Long: `Use this helper to call any available Lacework API endpoint.
Long: `Use this command as a helper to call any available Lacework API endpoint.
An example, list all integrations configured in your account:
For example, to list all integrations configured in your account run:
lacework-cli api get /external/integrations
lacework api get /external/integrations
For a complete list of available API endpoints visit:
Expand Down
6 changes: 3 additions & 3 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ var (
JsonF: prettyjson.NewFormatter(),
}
rootCmd = &cobra.Command{
Use: "lacework-cli",
Short: "A tool to manage your Lacework cloud security platform.",
Use: "lacework",
Short: "A tool to manage the Lacework cloud security platform.",
PersistentPreRun: loadStateFromViper,
SilenceErrors: true,
Long: `
The Lacework Command Line Interface is a tool that helps you manage your
The Lacework Command Line Interface is a tool that helps you manage the
Lacework cloud security platform. You can use it to manage compliance
reports, external integrations, vulnerability scans, and other operations.`,
}
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ var (
// versionCmd represents the version command
versionCmd = &cobra.Command{
Use: "version",
Short: "Print the lacework-cli version",
Short: "Print the Lacework cli version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("lacework-cli v%s (sha:%s) (time:%s)\n", Version, GitSHA, BuildTime)
fmt.Printf("lacework v%s (sha:%s) (time:%s)\n", Version, GitSHA, BuildTime)
},
}
)
Expand Down
4 changes: 2 additions & 2 deletions cli/install.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<#
.SYNOPSIS
Installs the 'lacework-cli' tool.
Installs the Lacework cli tool.
.Parameter Version
Specifies a version (ex: 0.1.0)
Expand All @@ -10,4 +10,4 @@ $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)"
Write-Host "Comming soon! (Installatiohn of the Lacework cli tool)"
35 changes: 18 additions & 17 deletions cli/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ set -eou pipefail
if [ -n "${LW_DEBUG:-}" ]; then set -x; fi

readonly github_releases="https://github.com/lacework/go-sdk/releases"
readonly installation_dir="/usr/local/bin"
readonly installation_dir=/usr/local/bin
readonly package_name=lacework-cli
readonly binary_name=lacework

usage() {
local _cmd
_cmd="$(basename "${0}")"
cat <<USAGE
${_cmd}: Installs the 'lacework-cli' tool.
${_cmd}: Installs the Lacework cli tool.
USAGE:
${_cmd} [FLAGS]
Expand Down Expand Up @@ -48,15 +50,15 @@ main() {
esac
done

log "Installing the 'lacewor-cli' tool"
log "Installing the Lacework cli tool"
create_workdir
check_platform
download_archive "$version" "$target"
verify_archive
extract_archive
install_cli
print_cli_version
log "The 'lacework-cli' tool has been successfully installed."
log "The Lacework cli tool has been successfully installed."
}

create_workdir() {
Expand Down Expand Up @@ -125,19 +127,19 @@ download_archive() {
local url

if [ "$_version" == "latest" ]; then
url="${github_releases}/latest/download/lacework-cli-${_target}.${ext}"
url="${github_releases}/latest/download/${package_name}-${_target}.${ext}"
else
url="${github_releases}/download/${_version}/lacework-cli-${_target}.${ext}"
url="${github_releases}/download/${_version}/${package_name}-${_target}.${ext}"
fi

download_file "${url}" "${workdir}/lacework-cli-${_version}.${ext}"
download_file "${url}.sha256sum" "${workdir}/lacework-cli-${_version}.${ext}.sha256sum"
download_file "${url}" "${workdir}/${package_name}-${_version}.${ext}"
download_file "${url}.sha256sum" "${workdir}/${package_name}-${_version}.${ext}.sha256sum"

archive="lacework-cli-${_target}.${ext}"
sha_file="lacework-cli-${_target}.${ext}.sha256sum"
archive="${package_name}-${_target}.${ext}"
sha_file="${package_name}-${_target}.${ext}.sha256sum"

mv -v "${workdir}/lacework-cli-${_version}.${ext}" "${archive}"
mv -v "${workdir}/lacework-cli-${_version}.${ext}.sha256sum" "${sha_file}"
mv -v "${workdir}/${package_name}-${_version}.${ext}" "${archive}"
mv -v "${workdir}/${package_name}-${_version}.${ext}.sha256sum" "${sha_file}"
}

verify_archive() {
Expand Down Expand Up @@ -165,15 +167,14 @@ extract_archive() {
}

install_cli() {
log "Installing lacework-cli into $installation_dir"
log "Installing Lacework cli into $installation_dir"
mkdir -pv "$installation_dir"
binary="lacework-cli-${target}"
install -v "${archive_dir}/lacework-cli-"* "${installation_dir}/lacework-cli"
install -v "${archive_dir}/${cli_name}" "${installation_dir}/${cli_name}"
}

print_cli_version() {
info "Verifying installed lacework-cli version"
"${installation_dir}/lacework-cli" version
info "Verifying installed lacework cli version"
"${installation_dir}/lacework" version
}

download_file() {
Expand Down
46 changes: 29 additions & 17 deletions scripts/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
#
set -eou pipefail

PROJECT=go-sdk
CLINAME=lacework-cli
readonly project_name=go-sdk
readonly package_name=lacework-cli
readonly binary_name=lacework

VERSION=$(cat VERSION)
TARGETS=(
${CLINAME}-darwin-386
${CLINAME}-darwin-amd64
${CLINAME}-windows-386.exe
${CLINAME}-windows-amd64.exe
${CLINAME}-linux-386
${CLINAME}-linux-amd64
${package_name}-darwin-386
${package_name}-darwin-amd64
${package_name}-windows-386.exe
${package_name}-windows-amd64.exe
${package_name}-linux-386
${package_name}-linux-amd64
)

usage() {
Expand Down Expand Up @@ -88,7 +90,7 @@ update_changelog() {
}

load_list_of_changes() {
local _list_of_changes=$(git log --no-merges --pretty="* %s (%an)([%h](https://github.com/lacework/${PROJECT}/commit/%H))" ${latest_version}..master)
local _list_of_changes=$(git log --no-merges --pretty="* %s (%an)([%h](https://github.com/lacework/${project_name}/commit/%H))" ${latest_version}..master)
echo "## Features" > CHANGES.md
echo "$_list_of_changes" | grep "\* feat[:(]" >> CHANGES.md
echo "## Refactor" >> CHANGES.md
Expand Down Expand Up @@ -131,7 +133,7 @@ tag_release() {
log "creating github tag: $_tag"
git tag "$_tag"
git push origin "$_tag"
log "go to https://github.com/lacework/go-sdk/releases and upload all files from 'bin/'"
log "go to https://github.com/lacework/${project_name}/releases and upload all files from 'bin/'"
}

release_check() {
Expand Down Expand Up @@ -225,26 +227,36 @@ generate_shasums() {
compress_targets() {
log "compressing target binaries"
local _target_with_ext
local _cli_name

for target in ${TARGETS[*]}; do
if [[ "$target" =~ exe ]]; then
_cli_name="bin/${binary_name}.exe"
else
_cli_name="bin/${binary_name}"
fi

mv "bin/${target}" "$_cli_name"

if [[ "$target" =~ linux ]]; then
_target_with_ext="bin/${target}.tar.gz"
log $_target_with_ext
tar -czvf "${_target_with_ext}" "bin/${target}" 2>/dev/null
tar -czvf "$_target_with_ext" "$_cli_name" 2>/dev/null
else
_target_with_ext="bin/${target}.zip"
log $_target_with_ext
zip "${_target_with_ext}" "bin/${target}" >/dev/null
zip "$_target_with_ext" "$_cli_name" >/dev/null
fi
rm -f "bin/${target}"

log $_target_with_ext
rm -f "$_cli_name"
done
}

log() {
echo "--> ${PROJECT}: $1"
echo "--> ${project_name}: $1"
}

warn() {
echo "xxx ${PROJECT}: $1" >&2
echo "xxx ${project_name}: $1" >&2
}

main "$@" || exit 99

0 comments on commit 51ce22f

Please sign in to comment.