-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(cli): use official url for agent installs (#369)
Signed-off-by: Salim Afiune Maya <[email protected]>
- Loading branch information
Showing
2 changed files
with
4 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,7 @@ package cmd | |
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"net" | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/AlecAivazis/survey/v2" | ||
|
@@ -35,6 +33,9 @@ import ( | |
"github.com/lacework/go-sdk/lwrunner" | ||
) | ||
|
||
// Official download url for installing Lacework agents | ||
const agentInstallDownloadURL = "https://packages.lacework.net/install.sh" | ||
|
||
func installRemoteAgent(_ *cobra.Command, args []string) error { | ||
var ( | ||
user = agentCmdState.InstallSshUser | ||
|
@@ -115,13 +116,7 @@ func installRemoteAgent(_ *cobra.Command, args []string) error { | |
return err | ||
} | ||
} | ||
|
||
downloadUrl, err := latestAgentInstallDownloadUrl() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cmd := fmt.Sprintf("sudo sh -c \"curl -sSL %s | sh -s -- %s\"", downloadUrl, token) | ||
cmd := fmt.Sprintf("sudo sh -c \"curl -sSL %s | sh -s -- %s\"", agentInstallDownloadURL, token) | ||
return runInstallCommandOnRemoteHost(runner, cmd) | ||
} | ||
|
||
|
@@ -150,40 +145,6 @@ func runInstallCommandOnRemoteHost(runner *lwrunner.Runner, cmd string) error { | |
return nil | ||
} | ||
|
||
func latestAgentInstallDownloadUrl() (string, error) { | ||
sha, err := latestAgentVersionSHA() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
url := fmt.Sprintf("https://s3-us-west-2.amazonaws.com/www.lacework.net/download/%s/install.sh", sha) | ||
cli.Log.Debugw("latest agent install.sh", "url", url) | ||
return url, nil | ||
} | ||
|
||
func latestAgentVersionSHA() (string, error) { | ||
url := "https://techally-artifacts.s3-us-west-2.amazonaws.com/lacework-cli-prod/agent-install/latest" | ||
cli.Log.Debugw("fetching latest agent version SHA", "url", url) | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
return "", errors.Wrap(err, "unable to fetch latest agent version") | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode == 404 { | ||
return "", errors.New("agent version artifact not found. Report this to [email protected]") | ||
} | ||
|
||
shaBytes, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return "", errors.Wrap(err, "unable to read response from latest agent version") | ||
} | ||
|
||
sha := strings.TrimSpace(string(shaBytes)) | ||
cli.Log.Debugw("latest agent version SHA", "sha", sha) | ||
return sha, nil | ||
} | ||
|
||
func isAgentInstalledOnRemoteHost(runner *lwrunner.Runner) error { | ||
agentVersionCmd := "sudo sh -c \"/var/lib/lacework/datacollector -v\"" | ||
|
||
|
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