Skip to content

Commit

Permalink
Bump to golang 1.14 for ci and latest golangci-lint
Browse files Browse the repository at this point in the history
- Fix things flagged by bumped golangci-lint
  • Loading branch information
edwardecook committed Apr 17, 2020
1 parent 18c168a commit 0b1ead2
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 48 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13
go-version: 1.14
id: go
- name: Check out code
uses: actions/checkout@v1
Expand All @@ -26,12 +26,12 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13
go-version: 1.14
id: go
- name: Check out code
uses: actions/checkout@v1
- name: Lint
run: |
export PATH=$PATH:$(go env GOPATH)/bin # temporary fix. See https://github.com/actions/setup-go/issues/14
go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.23.8
go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.24.0
make lint
48 changes: 24 additions & 24 deletions bosh/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,53 +25,53 @@ type Runner struct {

func (r Runner) Run(data environment.Config, dryRun bool, boshArgs ...string) error {
lines := []string{
fmt.Sprintf(`ssh_key_path=$(mktemp)`),
`ssh_key_path=$(mktemp)`,
fmt.Sprintf(`echo "%s" >"$ssh_key_path"`, data.OpsManager.PrivateKey),
fmt.Sprintf(`chmod 0600 "${ssh_key_path}"`),
`chmod 0600 "${ssh_key_path}"`,

fmt.Sprintf(`bosh_ca_path=$(mktemp)`),
`bosh_ca_path=$(mktemp)`,
fmt.Sprintf(`ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -i "${ssh_key_path}" %s@"%s" cat /var/tempest/workspaces/default/root_ca_certificate 1>${bosh_ca_path} 2>/dev/null`, data.OpsManager.SshUser, data.OpsManager.IP.String()),
fmt.Sprintf(`chmod 0600 "${bosh_ca_path}"`),
`chmod 0600 "${bosh_ca_path}"`,

fmt.Sprintf(`creds="$(om -t %s -k -u %s -p %s curl -s -p /api/v0/deployed/director/credentials/bosh_commandline_credentials)"`, data.OpsManager.URL.String(), data.OpsManager.Username, data.OpsManager.Password),
fmt.Sprintf(`bosh_all="$(echo "$creds" | jq -r .credential | tr ' ' '\n' | grep '=')"`),
`bosh_all="$(echo "$creds" | jq -r .credential | tr ' ' '\n' | grep '=')"`,

fmt.Sprintf(`bosh_client="$(echo $bosh_all | tr ' ' '\n' | grep 'BOSH_CLIENT=')"`),
fmt.Sprintf(`bosh_env="$(echo $bosh_all | tr ' ' '\n' | grep 'BOSH_ENVIRONMENT=')"`),
fmt.Sprintf(`bosh_secret="$(echo $bosh_all | tr ' ' '\n' | grep 'BOSH_CLIENT_SECRET=')"`),
fmt.Sprintf(`bosh_ca_cert="BOSH_CA_CERT=$bosh_ca_path"`),
`bosh_client="$(echo $bosh_all | tr ' ' '\n' | grep 'BOSH_CLIENT=')"`,
`bosh_env="$(echo $bosh_all | tr ' ' '\n' | grep 'BOSH_ENVIRONMENT=')"`,
`bosh_secret="$(echo $bosh_all | tr ' ' '\n' | grep 'BOSH_CLIENT_SECRET=')"`,
`bosh_ca_cert="BOSH_CA_CERT=$bosh_ca_path"`,
fmt.Sprintf(`bosh_proxy="BOSH_ALL_PROXY=ssh+socks5://%s@%s:22?private-key=${ssh_key_path}"`, data.OpsManager.SshUser, data.OpsManager.IP.String()),
fmt.Sprintf(`bosh_gw_host="BOSH_GW_HOST=%s"`, data.OpsManager.IP.String()),
fmt.Sprintf(`bosh_gw_user="BOSH_GW_USER=%s"`, data.OpsManager.SshUser),
fmt.Sprintf(`bosh_gw_private_key="BOSH_GW_PRIVATE_KEY=${ssh_key_path}"`),
`bosh_gw_private_key="BOSH_GW_PRIVATE_KEY=${ssh_key_path}"`,
}

prereqs := []string{"jq", "om", "ssh"}

if len(boshArgs) > 0 {
lines = append(
lines,
fmt.Sprintf(`trap 'rm -f ${ssh_key_path} ${bosh_ca_path}' EXIT`),
`trap 'rm -f ${ssh_key_path} ${bosh_ca_path}' EXIT`,
fmt.Sprintf(`/usr/bin/env $bosh_client $bosh_env $bosh_secret $bosh_ca_cert $bosh_proxy $bosh_gw_host $bosh_gw_user $bosh_gw_private_key bosh %s`, strings.Join(boshArgs, " ")),
)
prereqs = append(prereqs, "bosh")
} else {
lines = append(
lines,
fmt.Sprintf(`echo "export BOSH_ENV_NAME=%s"`, data.Name),
fmt.Sprintf(`echo "export $bosh_client"`),
fmt.Sprintf(`echo "export $bosh_env"`),
fmt.Sprintf(`echo "export $bosh_secret"`),
fmt.Sprintf(`echo "export $bosh_ca_cert"`),
fmt.Sprintf(`echo "export $bosh_proxy"`),
fmt.Sprintf(`echo "export $bosh_gw_host"`),
fmt.Sprintf(`echo "export $bosh_gw_user"`),
fmt.Sprintf(`echo "export $bosh_gw_private_key"`),
fmt.Sprintf(`echo "export CREDHUB_SERVER=\"\${BOSH_ENVIRONMENT}:8844\""`),
fmt.Sprintf(`echo "export CREDHUB_PROXY=\"\${BOSH_ALL_PROXY}\""`),
fmt.Sprintf(`echo "export CREDHUB_CLIENT=\"\${BOSH_CLIENT}\""`),
fmt.Sprintf(`echo "export CREDHUB_SECRET=\"\${BOSH_CLIENT_SECRET}\""`),
fmt.Sprintf(`echo "export CREDHUB_CA_CERT=\"\${BOSH_CA_CERT}\""`),
`echo "export $bosh_client"`,
`echo "export $bosh_env"`,
`echo "export $bosh_secret"`,
`echo "export $bosh_ca_cert"`,
`echo "export $bosh_proxy"`,
`echo "export $bosh_gw_host"`,
`echo "export $bosh_gw_user"`,
`echo "export $bosh_gw_private_key"`,
`echo "export CREDHUB_SERVER=\"\${BOSH_ENVIRONMENT}:8844\""`,
`echo "export CREDHUB_PROXY=\"\${BOSH_ALL_PROXY}\""`,
`echo "export CREDHUB_CLIENT=\"\${BOSH_CLIENT}\""`,
`echo "export CREDHUB_SECRET=\"\${BOSH_CLIENT_SECRET}\""`,
`echo "export CREDHUB_CA_CERT=\"\${BOSH_CA_CERT}\""`,
)
}

Expand Down
6 changes: 3 additions & 3 deletions cf/login_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ type LoginRunner struct {
func (r LoginRunner) Run(data environment.Config, dryRun bool, args ...string) error {
lines := []string{
fmt.Sprintf(`prods="$(om -t %s -k -u %s -p %s curl -s -p /api/v0/staged/products)"`, data.OpsManager.URL.String(), data.OpsManager.Username, data.OpsManager.Password),
fmt.Sprintf(`guid="$(echo "$prods" | jq -r '.[] | select(.type == "cf") | .guid')"`),
`guid="$(echo "$prods" | jq -r '.[] | select(.type == "cf") | .guid')"`,
fmt.Sprintf(`creds="$(om -t %s -k -u %s -p %s curl -s -p /api/v0/deployed/products/"$guid"/credentials/.uaa.admin_credentials)"`, data.OpsManager.URL.String(), data.OpsManager.Username, data.OpsManager.Password),
fmt.Sprintf(`user="$(echo "$creds" | jq -r .credential.value.identity)"`),
fmt.Sprintf(`pass="$(echo "$creds" | jq -r .credential.value.password)"`),
`user="$(echo "$creds" | jq -r .credential.value.identity)"`,
`pass="$(echo "$creds" | jq -r .credential.value.password)"`,
fmt.Sprintf(`cf login -a "api.%s" -u "$user" -p "$pass" --skip-ssl-validation`, data.CFDomain),
}

Expand Down
4 changes: 2 additions & 2 deletions pks/login_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ type LoginRunner struct {
func (r LoginRunner) Run(data environment.Config, dryRun bool, args ...string) error {
lines := []string{
fmt.Sprintf(`prods="$(om -t %s -k -u %s -p %s curl -s -p /api/v0/staged/products)"`, data.OpsManager.URL.String(), data.OpsManager.Username, data.OpsManager.Password),
fmt.Sprintf(`guid="$(echo "$prods" | jq -r '.[] | select(.type == "pivotal-container-service") | .guid')"`),
`guid="$(echo "$prods" | jq -r '.[] | select(.type == "pivotal-container-service") | .guid')"`,
fmt.Sprintf(`creds="$(om -t %s -k -u %s -p %s curl -s -p /api/v0/deployed/products/"$guid"/credentials/.properties.uaa_admin_password)"`, data.OpsManager.URL.String(), data.OpsManager.Username, data.OpsManager.Password),
fmt.Sprintf(`pass="$(echo "$creds" | jq -r .credential.value.secret)"`),
`pass="$(echo "$creds" | jq -r .credential.value.secret)"`,
fmt.Sprintf(`pks login -a %s -u admin -p "$pass" --skip-ssl-validation`, data.PKSApi.URL.String()),
}

Expand Down
14 changes: 7 additions & 7 deletions ssh/director_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ func (b DirectorRunner) Run(data environment.Config, dryRun bool, args ...string
privateKeyPath := ".credential.value.private_key_pem"

sshCommandLines := []string{
fmt.Sprintf(`ssh_key_path=$(mktemp temp.XXXXXX)`),
`ssh_key_path=$(mktemp temp.XXXXXX)`,
fmt.Sprintf(`echo "%s" >"$ssh_key_path"`, data.OpsManager.PrivateKey),
fmt.Sprintf(`chmod 0600 "${ssh_key_path}"`),
`chmod 0600 "${ssh_key_path}"`,

fmt.Sprintf(`director_ssh_key="$(om -t %s -k -u %s -p %s curl -s -p %s | jq -r %s)"`, data.OpsManager.URL.String(), data.OpsManager.Username, data.OpsManager.Password, bbrCredsPath, privateKeyPath),
fmt.Sprintf(`director_ssh_key_path=$(mktemp)`),
fmt.Sprintf(`echo -e "$director_ssh_key" > "$director_ssh_key_path"`),
fmt.Sprintf(`chmod 0600 "${director_ssh_key_path}"`),
`director_ssh_key_path=$(mktemp)`,
`echo -e "$director_ssh_key" > "$director_ssh_key_path"`,
`chmod 0600 "${director_ssh_key_path}"`,

fmt.Sprintf(`bosh_env="$(om -t %s -k -u %s -p %s curl -s -p %s | grep -o "BOSH_ENVIRONMENT=\S*" | cut -f2 -d=)"`, data.OpsManager.URL.String(), data.OpsManager.Username, data.OpsManager.Password, boshCreds),

fmt.Sprintf(`trap 'rm -f ${director_ssh_key_path}; rm -f ${ssh_key_path}' EXIT`),
`trap 'rm -f ${director_ssh_key_path}; rm -f ${ssh_key_path}' EXIT`,

fmt.Sprintf(`jumpbox_cmd="ubuntu@%s -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -i ${ssh_key_path}"`, data.OpsManager.IP.String()),
fmt.Sprintf(`ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -J "$jumpbox_cmd" "bbr@${bosh_env}" -i "$director_ssh_key_path"`),
`ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -J "$jumpbox_cmd" "bbr@${bosh_env}" -i "$director_ssh_key_path"`,
}

return b.ScriptRunner.RunScript(sshCommandLines, []string{"ssh", "om"}, dryRun)
Expand Down
12 changes: 6 additions & 6 deletions ssh/opsmanager_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ func (b OpsManagerRunner) Run(data environment.Config, dryRun bool, args ...stri
sshCommand := fmt.Sprintf(`ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -i "${ssh_key_path}" -t ubuntu@"%s"`, data.OpsManager.IP.String())

sshCommandLines := []string{
fmt.Sprintf(`ssh_key_path=$(mktemp)`),
`ssh_key_path=$(mktemp)`,
fmt.Sprintf(`echo "%s" >"$ssh_key_path"`, data.OpsManager.PrivateKey),
fmt.Sprintf(`trap 'rm -f ${ssh_key_path}' EXIT`),
fmt.Sprintf(`chmod 0600 "${ssh_key_path}"`),
`trap 'rm -f ${ssh_key_path}' EXIT`,
`chmod 0600 "${ssh_key_path}"`,
fmt.Sprintf(`creds="$(om -t %s -k -u %s -p %s curl -s -p %s)"`, data.OpsManager.URL.String(), data.OpsManager.Username, data.OpsManager.Password, "/api/v0/deployed/director/credentials/bosh_commandline_credentials"),
fmt.Sprintf(`bosh="$(echo "$creds" | jq -r .credential | tr ' ' '\n' | grep '=')"`),
fmt.Sprintf(`echo "$bosh"`),
fmt.Sprintf(`shell="/usr/bin/env $(echo $bosh | tr '\n' ' ') bash -l"`),
`bosh="$(echo "$creds" | jq -r .credential | tr ' ' '\n' | grep '=')"`,
`echo "$bosh"`,
`shell="/usr/bin/env $(echo $bosh | tr '\n' ' ') bash -l"`,
fmt.Sprintf(`%s "$shell"`, sshCommand),
}

Expand Down
6 changes: 3 additions & 3 deletions sshuttle/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ func (b Runner) Run(data environment.Config, dryRun bool, args ...string) error
cidrPath := ".networks[].subnets[].cidr"

sshuttleCommandLines := []string{
fmt.Sprintf(`ssh_key_path=$(mktemp)`),
`ssh_key_path=$(mktemp)`,
fmt.Sprintf(`echo "%s" >"$ssh_key_path"`, data.OpsManager.PrivateKey),
fmt.Sprintf(`trap 'rm -f ${ssh_key_path}' EXIT`),
fmt.Sprintf(`chmod 0600 "${ssh_key_path}"`),
`trap 'rm -f ${ssh_key_path}' EXIT`,
`chmod 0600 "${ssh_key_path}"`,
fmt.Sprintf(`cidrs="$(om -t %s -k -u %s -p %s curl -s -p %s | jq -r %s | xargs echo)"`,
data.OpsManager.URL.String(), data.OpsManager.Username, data.OpsManager.Password, networksPath, cidrPath),

Expand Down

0 comments on commit 0b1ead2

Please sign in to comment.