Created
January 24, 2017 18:34
-
-
Save allomov/acb3974248ab7219ecab5a71d6e678d0 to your computer and use it in GitHub Desktop.
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
{ | |
"ListenAddress": "0.0.0.0", | |
"ListenPort": 8080, | |
"Username": "turbulence", | |
"Password": "generated-password", | |
"CertificatePath": "/var/vcap/jobs/turbulence_api/config/cert", | |
"PrivateKeyPath": "/var/vcap/jobs/turbulence_api/config/private_key", | |
"Director": { | |
"Host": "some-bosh-ip-address", | |
"Port": 25555, | |
"CACert": "-----BEGIN CERTIFICATE-----\nFAKEFAKEFAKEFAKEFAKEFAKEFAKE\nFAKEFAKEFAKEFAKEFAKEFAKE\nFAKEFAKEFAKEFAKEFAKEFAKEFAKEFAKE\nFAKEFAKEFAKEFAKEFAKEFAKEFAKEFAKEFAKE\n-----END CERTIFICATE-----\n", | |
"Client": "director", | |
"ClientSecret": "director-client-secret" | |
}, | |
"Datadog": { | |
"AppKey": "", | |
"APIKey": "" | |
} | |
} |
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
package main | |
import ( | |
"encoding/json" | |
// boshdir "github.com/cloudfoundry/bosh-cli/director" | |
bosherr "github.com/cloudfoundry/bosh-utils/errors" | |
boshlog "github.com/cloudfoundry/bosh-utils/logger" | |
boshsys "github.com/cloudfoundry/bosh-utils/system" | |
turbulence_director "github.com/cppforlife/turbulence/director" | |
// alias "github.com/cppforlife/turbulence/main" | |
"github.com/davecgh/go-spew/spew" | |
"os" | |
) | |
func main() { | |
logger := boshlog.NewWriterLogger(boshlog.LevelDebug, os.Stderr, os.Stderr) | |
fs := boshsys.NewOsFileSystem(logger) | |
config, err := NewConfigFromPath("config.json", fs) | |
if err != nil { | |
logger.Error("tag", err.Error()) | |
} | |
spew.Dump(config) | |
factory := turbulence_director.NewFactory(config, logger) | |
director, err := factory.New() | |
if err != nil { | |
logger.Error("tag", err.Error()) | |
} | |
spew.Dump(director.AllInstances()) | |
} | |
type Config struct { | |
ListenAddress string | |
ListenPort int | |
Username string | |
Password string | |
CertificatePath string | |
PrivateKeyPath string | |
Director turbulence_director.Config | |
// Datadog reporter.DatadogConfig | |
} | |
func NewConfigFromPath(path string, fs boshsys.FileSystem) (turbulence_director.Config, error) { | |
var config Config | |
bytes, err := fs.ReadFile(path) | |
if err != nil { | |
return turbulence_director.Config{}, bosherr.WrapErrorf(err, "Reading config %s", path) | |
} | |
err = json.Unmarshal(bytes, &config) | |
if err != nil { | |
return turbulence_director.Config{}, bosherr.WrapError(err, "Unmarshalling config") | |
} | |
return config.Director, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment