Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Formatting and style updates, closes #43 #58

Merged
merged 13 commits into from
Nov 21, 2018
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: go

before_install:
- cd src/omg-cli

install:
- go get -v ./...
- go get -u github.com/onsi/ginkgo/ginkgo
- go get -u github.com/onsi/gomega/...
- go get -u golang.org/x/lint/golint

script:
- golint -set_exit_status ./...
- ginkgo -skipPackage=certification -r .
1 change: 1 addition & 0 deletions deploy_pcf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cd "$(dirname $0)"
root=$(pwd)

pushd src/omg-cli
rm -f $root/bin/omg-cli
go build -o $root/bin/omg-cli
popd
export PATH=$root/bin:$PATH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package bosh_director_test

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
)

func TestBoshDirector(t *testing.T) {
Expand Down
10 changes: 7 additions & 3 deletions src/omg-cli/certification/environment/ops_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ package environment

import (
"fmt"

"omg-cli/ops_manager"

"github.com/pivotal-cf/om/api"
)

// DirectorProperties are the properties set on the BOSH Director.
type DirectorProperties map[string]map[string]interface{}

// OpsManagerQuery validates various pieces of a quickstart's installation.
type OpsManagerQuery interface {
// Tile returns a TileQuery interface if a tile is installed
// or an error if it's not found
Expand All @@ -37,6 +40,7 @@ type OpsManagerQuery interface {
Director() DirectorProperties
}

// TileQuery validates various details of a specific tile.
type TileQuery interface {
// Property returns the value of the given property set on the tile
Property(name string) api.ResponseProperty
Expand Down Expand Up @@ -67,7 +71,7 @@ func (lom *liveOpsManager) MustGetTile(name string) TileQuery {
return tile
}

func (lom *liveOpsManager) Director() map[string]map[string]interface{} {
func (lom *liveOpsManager) Director() DirectorProperties {
prop, err := lom.sdk.GetDirector()
if err != nil {
panic(fmt.Errorf("retreving director: %v", err))
Expand All @@ -86,8 +90,8 @@ func (ltq *liveTileQuery) Property(name string) api.ResponseProperty {
return ltq.props.Properties[name]
}

func (ltq *liveTileQuery) Resource(jobId string) api.JobProperties {
resource, err := ltq.sdk.GetResource(ltq.name, jobId)
func (ltq *liveTileQuery) Resource(jobID string) api.JobProperties {
resource, err := ltq.sdk.GetResource(ltq.name, jobID)
if err != nil {
panic(err)
}
Expand Down
12 changes: 4 additions & 8 deletions src/omg-cli/certification/environment/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,15 @@
package environment

import (
"net/http"

"sync"

"fmt"
"log"
"net/http"
"os"
"sync"

"omg-cli/config"

"omg-cli/ops_manager"

"log"

"github.com/onsi/ginkgo"
)

Expand Down Expand Up @@ -72,7 +68,7 @@ type liveTarget struct {

func (lt *liveTarget) OpsManager() OpsManagerQuery {
logger := log.New(os.Stdout, "TODO(jrjohnson): test logger", 0)
omSdk, err := ops_manager.NewSdk(fmt.Sprintf("https://%s", lt.cfg.OpsManagerHostname), lt.cfg.OpsManager, *logger)
omSdk, err := ops_manager.NewSdk(fmt.Sprintf("https://%s", lt.cfg.OpsManagerHostname), lt.cfg.OpsManager, logger)
if err != nil {
ginkgo.Fail(fmt.Sprintf("creating ops manager sdk: %v", err))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ert_routing_test

import (
"testing"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"testing"
)

func TestErtRouting(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion src/omg-cli/certification/ert_routing/tcp_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
. "github.com/onsi/gomega"
)

var _ = Describe("TcpRouter", func() {
var _ = Describe("TCPRouter", func() {
var (
ert TileQuery
)
Expand Down
7 changes: 6 additions & 1 deletion src/omg-cli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,28 @@

package config

// Config contains the infrastructure details.
type Config TerraformConfigSchema

// OpsManagerCredentials are the credentials for the Ops Manager API.
type OpsManagerCredentials struct {
Username string
Password string
DecryptionPhrase string
SkipSSLVerification bool
}

// CredhubEncryptionKey is the key for Credhub.
type CredhubEncryptionKey struct {
Name string
Key string
}

// Filenames for configs.
const (
TerraformOutputFile = "terraform_output.json"
EnvConfigFile = "config.json"
)

var ConfigFiles = []string{TerraformOutputFile, EnvConfigFile}
// Files are necessary files to upload.
var Files = []string{TerraformOutputFile, EnvConfigFile}
19 changes: 14 additions & 5 deletions src/omg-cli/config/env_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,30 @@ package config

import (
"encoding/json"
"fmt"
"io/ioutil"
"path/filepath"
)

// EnvConfig is the config needed to install the quickstart.
type EnvConfig struct {
DnsZoneName string
DNSZoneName string
ProjectID string
BaseImageURL string
EnvName string
Region string
PivnetApiToken string
PivnetAPIToken string
Zone1 string
Zone2 string
Zone3 string
SmallFootprint bool
IncludeHealthwatch bool
}

// DefaultEnvConfig creates a default quickstart configuration.
func DefaultEnvConfig() (*EnvConfig, error) {
c := &EnvConfig{
DnsZoneName: "pcf-zone",
DNSZoneName: "pcf-zone",
BaseImageURL: "https://storage.cloud.google.com/ops-manager-us/pcf-gcp-2.3-build.194.tar.gz",
EnvName: "pcf",
Region: "us-east1",
Expand All @@ -52,8 +55,14 @@ func DefaultEnvConfig() (*EnvConfig, error) {
return c, nil
}

func ConfigFromEnvDirectory(path string) (*EnvConfig, error) {
return fromEnvironment(filepath.Join(path, EnvConfigFile))
// FromEnvDirectory creates a quickstart config from a given directory.
func FromEnvDirectory(path string) (*EnvConfig, error) {
config, err := fromEnvironment(filepath.Join(path, EnvConfigFile))
if err != nil {
return nil, fmt.Errorf("creating environment from directory %s: %v", path, err)
}

return config, nil
}

func fromEnvironment(filename string) (*EnvConfig, error) {
Expand Down
53 changes: 30 additions & 23 deletions src/omg-cli/config/terraform_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,25 @@ import (
"strconv"
)

// TerraformConfigSchema is the quickstart's Terraform schema as a struct.
type TerraformConfigSchema struct {
OpsManagerHostname string `json:"ops_manager_dns"`
OpsManagerIp string `json:"ops_manager_private_ip"`
JumpboxIp string `json:"jumpbox_public_ip"`
OpsManagerIP string `json:"ops_manager_private_ip"`
JumpboxIP string `json:"jumpbox_public_ip"`
NetworkName string `json:"network_name"`
DeploymentTargetTag string `json:"vm_tag"`

OpsManagerServiceAccountKey string

// External database properties are omitted if internal database is chosen.
ExternalSqlIp string `json:"sql_db_ip,omitempty"`
ExternalSqlPort int
OpsManagerSqlDbName string `json:"opsman_sql_db_name,omitempty"`
OpsManagerSqlUsername string `json:"opsman_sql_username,omitempty"`
OpsManagerSqlPassword string `json:"opsman_sql_password,omitempty"`
ERTSqlDbName string `json:"ert_sql_db_name,omitempty"`
ERTSqlUsername string `json:"ert_sql_username,omitempty"`
ERTSqlPassword string `json:"ert_sql_password,omitempty"`
ExternalSQLIP string `json:"sql_db_ip,omitempty"`
ExternalSQLPort int
OpsManagerSQLDbName string `json:"opsman_sql_db_name,omitempty"`
OpsManagerSQLUsername string `json:"opsman_sql_username,omitempty"`
OpsManagerSQLPassword string `json:"opsman_sql_password,omitempty"`
ERTSQLDbName string `json:"ert_sql_db_name,omitempty"`
ERTSQLUsername string `json:"ert_sql_username,omitempty"`
ERTSQLPassword string `json:"ert_sql_password,omitempty"`

MgmtSubnetName string `json:"management_subnet_name"`
MgmtSubnetGateway string `json:"management_subnet_gateway"`
Expand All @@ -60,31 +61,31 @@ type TerraformConfigSchema struct {
ErtSubnetGateway string `json:"ert_subnet_gateway"`
ErtSubnetCIDR string `json:"ert_subnet_cidrs_0"`

HttpBackendServiceName string `json:"http_lb_backend_name"`
SshTargetPoolName string `json:"ssh_router_pool"`
WssTargetPoolName string `json:"wss_router_pool"`
TcpTargetPoolName string `json:"tcp_router_pool"`
TcpPortRange string `json:"tcp_port_range"`
HTTPBackendServiceName string `json:"http_lb_backend_name"`
SSHTargetPoolName string `json:"ssh_router_pool"`
WSSTargetPoolName string `json:"wss_router_pool"`
TCPTargetPoolName string `json:"tcp_router_pool"`
TCPPortRange string `json:"tcp_port_range"`

BuildpacksBucket string `json:"buildpacks_bucket"`
DropletsBucket string `json:"droplets_bucket"`
PackagesBucket string `json:"packages_bucket"`
ResourcesBucket string `json:"resources_bucket"`
DirectorBucket string `json:"director_blobstore_bucket"`

DnsSuffix string `json:"dns_suffix"`
DNSSuffix string `json:"dns_suffix"`
AppsDomain string `json:"apps_domain"`
SysDomain string `json:"sys_domain"`
DopplerDomain string `json:"doppler_domain"`
LoggregatorDomain string `json:"loggregator_domain"`

SslCertificate string `json:"ssl_cert"`
SslPrivateKey string `json:"ssl_cert_private_key"`
SSLCertificate string `json:"ssl_cert"`
SSLPrivateKey string `json:"ssl_cert_private_key"`

StackdriverNozzleServiceAccountKey string

ServiceBrokerServiceAccountKey string
ServiceBrokerDbIp string `json:"service_broker_db_ip"`
ServiceBrokerDbIP string `json:"service_broker_db_ip"`
ServiceBrokerDbUsername string `json:"service_broker_db_username"`
ServiceBrokerDbPassword string `json:"service_broker_db_password"`

Expand All @@ -98,8 +99,14 @@ type TerraformConfigSchema struct {
CredhubKey CredhubEncryptionKey
}

// TerraformFromEnvDirectory creates a Terraform config from a directory.
func TerraformFromEnvDirectory(path string) (*Config, error) {
return fromTerraform(filepath.Join(path, TerraformOutputFile))
config, err := fromTerraform(filepath.Join(path, TerraformOutputFile))
if err != nil {
return nil, fmt.Errorf("creating Terraform config from directory %s: %v", path, err)
}

return config, nil
}

func decode(input string) string {
Expand Down Expand Up @@ -141,7 +148,7 @@ func fromTerraform(filename string) (*Config, error) {
if err != nil {
return nil, err
}
hydratedCfg.ExternalSqlPort = int(parsed)
hydratedCfg.ExternalSQLPort = int(parsed)
}

hydratedCfg.OpsManagerServiceAccountKey = decode(flattened["ops_manager_service_account_key_base64"])
Expand All @@ -166,14 +173,14 @@ func fromTerraform(filename string) (*Config, error) {
* {"foo": "bar", "baz_0": "pizza", "baz_1": "thebest"}
*/

type TerraformValue struct {
type terraformValue struct {
Value interface{} `json:"value"`
}

func flattenTerraform(contents []byte) (map[string]string, error) {
res := map[string]string{}

tf := map[string]TerraformValue{}
tf := map[string]terraformValue{}

err := json.Unmarshal(contents, &tf)
if err != nil {
Expand Down
8 changes: 6 additions & 2 deletions src/omg-cli/config/tile_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@

package config

// PivnetMetadata is metadata about a tile's information on the Pivotal Network.
type PivnetMetadata struct {
Name string
ReleaseId int
FileId int
ReleaseID int
FileID int
Sha256 string
}

// StemcellMetadata is metadata about a stemcell.
type StemcellMetadata struct {
PivnetMetadata
StemcellName string
}

// OpsManagerMetadata is metadata associated with quickstart tiles.
type OpsManagerMetadata struct {
Name string
Version string
DependsOnPAS bool // tiles which depend on PAS but don't specify so in their metadata
}

// Tile represents an Ops Manager tile.
type Tile struct {
Pivnet PivnetMetadata
Product OpsManagerMetadata
Expand Down
2 changes: 2 additions & 0 deletions src/omg-cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require (
cloud.google.com/go/compute/metadata v0.0.0-20181109222614-193e596dec49 // indirect
code.cloudfoundry.org/clock v0.0.0-20180518195852-02e53af36e6c
code.cloudfoundry.org/lager v2.0.0+incompatible
code.cloudfoundry.org/trace-logger v0.0.0-20170119230301-107ef08a939d // indirect
code.cloudfoundry.org/uaa-go-client v0.0.0-20181022172934-480082394a82
github.com/PuerkitoBio/goquery v1.4.1 // indirect
github.com/alecthomas/kingpin v2.2.6+incompatible
Expand All @@ -16,6 +17,7 @@ require (
github.com/cloudfoundry/bosh-utils v0.0.0-20181109230347-f1d51d8b54a5 // indirect
github.com/cppforlife/go-patch v0.0.0-20171006213518-250da0e0e68c // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/gosuri/uilive v0.0.0-20170323041506-ac356e6e42cd
Expand Down
4 changes: 4 additions & 0 deletions src/omg-cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ code.cloudfoundry.org/clock v0.0.0-20180518195852-02e53af36e6c h1:5eeuG0BHx1+DHe
code.cloudfoundry.org/clock v0.0.0-20180518195852-02e53af36e6c/go.mod h1:QD9Lzhd/ux6eNQVUDVRJX/RKTigpewimNYBi7ivZKY8=
code.cloudfoundry.org/lager v2.0.0+incompatible h1:WZwDKDB2PLd/oL+USK4b4aEjUymIej9My2nUQ9oWEwQ=
code.cloudfoundry.org/lager v2.0.0+incompatible/go.mod h1:O2sS7gKP3HM2iemG+EnwvyNQK7pTSC6Foi4QiMp9sSk=
code.cloudfoundry.org/trace-logger v0.0.0-20170119230301-107ef08a939d h1:1I5BueV2nNkvIV40CQ0JQgmD/ijouF0QlLLOz0KMkRo=
code.cloudfoundry.org/trace-logger v0.0.0-20170119230301-107ef08a939d/go.mod h1:KAH6N5nwHViCZsOgmApk6nj8TDuqRGb9R06Hk461Uwc=
code.cloudfoundry.org/uaa-go-client v0.0.0-20181022172934-480082394a82 h1:qUuXU4x4xcL3OCtqdLcxELBmLr4RFp0agNgXzv1uQRE=
code.cloudfoundry.org/uaa-go-client v0.0.0-20181022172934-480082394a82/go.mod h1:RPJxhL74iNXTSTQf9EDtdAXJ5fLVAmkVsFtZRHEbgk0=
github.com/PuerkitoBio/goquery v1.4.1 h1:smcIRGdYm/w7JSbcdeLHEMzxmsBQvl8lhf0dSw2nzMI=
Expand All @@ -30,6 +32,8 @@ github.com/cppforlife/go-patch v0.0.0-20171006213518-250da0e0e68c h1:L6Qwcfk/qeD
github.com/cppforlife/go-patch v0.0.0-20171006213518-250da0e0e68c/go.mod h1:67a7aIi94FHDZdoeGSJRRFDp66l9MhaAG1yGxpUoFD8=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
Expand Down
Loading