-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
12,389 additions
and
53 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
broker: | ||
bindable: true | ||
dashboard_client: null | ||
description: MongoDB | ||
host: https://p-mongodb-broker.cftesting.footoo.org | ||
id: SOME-UUID-98769-f-mongodb-broker # | ||
metadata: | ||
displayName: MongoDB | ||
documentationUrl: null | ||
imageUrl: http://info.mongodb.com/rs/mongodb/images/MongoDB_Logo_Full.png | ||
longDescription: Creating a service instance provisions a database. Binding | ||
applications provisions unique credentials for each application to access | ||
the database. | ||
providerDisplayName: fcf | ||
supportUrl: null | ||
name: f-mongodb # | ||
plan_updateable: false | ||
plans: | ||
- description: Shared MongoDB Server | ||
free: true | ||
id: mongo | ||
metadata: | ||
bullets: | ||
- Shared MongoDB(3.4.2) replica set | ||
costs: | ||
- amount: | ||
usd: 0 | ||
unit: month | ||
name: standard | ||
requires: null | ||
security_user_name: broker-username | ||
security_user_password: broker-password | ||
tags: | ||
- mongodb | ||
|
||
mongod: | ||
nodes: | ||
bind_ip: 0.0.0.0 | ||
ips: | ||
- 172.16.0.156 | ||
port: 27017 | ||
path: | ||
log: /var/vcap/sys/log/mongod/mongod.log | ||
replSet: | ||
enabled: true | ||
key: replicasetkey | ||
name: replicasetname | ||
root: | ||
pass: rootpassword | ||
user: rootusername | ||
storage: | ||
engine: wiredTiger | ||
journal: true | ||
path: /var/vcap/store/mongod |
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 |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package config | ||
|
||
import ( | ||
"os" | ||
|
||
"strings" | ||
|
||
"github.com/cloudfoundry-incubator/candiedyaml" | ||
"github.com/pivotal-cf/brokerapi" | ||
) | ||
|
||
type Config struct { | ||
MongoConfig MongoConfig `yaml:"mongod"` | ||
BrokerConfig BrokerConfig `yaml:"broker"` | ||
} | ||
|
||
type MongoConfig struct { | ||
Nodes MongoNodes `yaml:"nodes"` | ||
RootUser MongoRootUser `yaml:"root"` | ||
} | ||
|
||
type MongoRootUser struct { | ||
Username string `yaml:"user"` | ||
Password string `yaml:"pass"` | ||
} | ||
|
||
type MongoNodes struct { | ||
IPs []string `yaml:"ips"` | ||
Port string `yaml:"port"` | ||
} | ||
|
||
type BrokerConfig struct { | ||
Host string `yaml:"host"` | ||
BrokerUsername string `yaml:"security_user_name"` | ||
BrokerPassword string `yaml:"security_user_password"` | ||
|
||
ServiceID string `yaml:"id"` | ||
ServiceName string `yaml:"name"` | ||
ServiceDescription string `yaml:"description"` | ||
ServiceBindable bool `yaml:"bindable"` | ||
PlanUpdateable bool `yaml:"plan_updateable"` | ||
Plans []Plan `yaml:"plans"` | ||
Tags []string `yaml:"tags"` | ||
ServiceMetadata ServiceMetadata `yaml:"metadata"` | ||
} | ||
|
||
type ServiceMetadata struct { | ||
DisplayName string `yaml:"displayName"` | ||
ImageUrl string `yaml:"imageUrl"` | ||
LongDescription string `yaml:"longDescription"` | ||
ProviderDisplayName string `yaml:"providerDisplayName"` | ||
DocumentationUrl string `yaml:"documentationUrl"` | ||
SupportUrl string `yaml:"supportUrl"` | ||
} | ||
|
||
type Plan struct { | ||
ID string `yaml:"id"` | ||
Name string `yaml:"name"` | ||
Description string `yaml:"description"` | ||
Free bool `yaml:"free"` | ||
Metadata PlanMetadata `yaml:"metadata"` | ||
} | ||
|
||
type PlanMetadata struct { | ||
Bullets []string `yaml:"bullets"` | ||
Costs []PlanMetadataCost `yaml:"costs"` | ||
} | ||
|
||
type PlanMetadataCost struct { | ||
} | ||
|
||
func ParseConfig(path string) (Config, error) { | ||
file, error := os.Open(path) | ||
if error != nil { | ||
return Config{}, error | ||
} | ||
|
||
var config Config | ||
if err := candiedyaml.NewDecoder(file).Decode(&config); err != nil { | ||
return Config{}, err | ||
} | ||
|
||
return config, nil | ||
} | ||
|
||
func (config *Config) MongoHosts() string { | ||
var hosts []string | ||
for _, host := range config.MongoConfig.Nodes.IPs { | ||
hostWithPort := host + ":" + config.MongoConfig.Nodes.Port | ||
hosts = append(hosts, hostWithPort) | ||
} | ||
|
||
return strings.Join(hosts, ",") | ||
} | ||
|
||
func (config *Config) MongoUsername() string { | ||
return config.MongoConfig.RootUser.Username | ||
} | ||
|
||
func (config *Config) MongoPassword() string { | ||
return config.MongoConfig.RootUser.Password | ||
} | ||
|
||
func (config *Config) Services() []brokerapi.Service { | ||
planList := []brokerapi.ServicePlan{} | ||
for _, plan := range config.Plans() { | ||
planList = append(planList, *plan) | ||
} | ||
|
||
brokerConfig := config.BrokerConfig | ||
serviceMetadata := brokerConfig.ServiceMetadata | ||
|
||
services := []brokerapi.Service{ | ||
brokerapi.Service{ | ||
ID: brokerConfig.ServiceID, | ||
Name: brokerConfig.ServiceName, | ||
Description: brokerConfig.ServiceDescription, | ||
Bindable: brokerConfig.ServiceBindable, | ||
Tags: brokerConfig.Tags, | ||
Plans: planList, | ||
PlanUpdatable: brokerConfig.PlanUpdateable, | ||
Metadata: &brokerapi.ServiceMetadata{ | ||
DisplayName: serviceMetadata.DisplayName, | ||
ImageUrl: serviceMetadata.ImageUrl, | ||
LongDescription: serviceMetadata.LongDescription, | ||
ProviderDisplayName: serviceMetadata.ProviderDisplayName, | ||
DocumentationUrl: serviceMetadata.DocumentationUrl, | ||
SupportUrl: serviceMetadata.SupportUrl, | ||
}, | ||
//Requires | ||
//DashboardClient | ||
}, | ||
} | ||
|
||
return services | ||
} | ||
|
||
func (config *Config) Plans() map[string]*brokerapi.ServicePlan { | ||
plans := map[string]*brokerapi.ServicePlan{} | ||
|
||
for _, plan := range config.BrokerConfig.Plans { | ||
plans[plan.Name] = &brokerapi.ServicePlan{ | ||
ID: plan.ID, | ||
Name: plan.Name, | ||
Description: plan.Description, | ||
Free: &plan.Free, | ||
// Metadata | ||
} | ||
} | ||
|
||
return plans | ||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"path" | ||
"path/filepath" | ||
"testing" | ||
) | ||
|
||
func TestConfig(t *testing.T) { | ||
configPath := "test_config.yml" | ||
path, error := filepath.Abs(path.Join("assets", configPath)) | ||
|
||
if error != nil { | ||
t.Fatal("Error: ", error) | ||
} | ||
|
||
config, error := ParseConfig(path) | ||
|
||
if error != nil { | ||
t.Fatal("Error: ", error) | ||
} | ||
|
||
fmt.Println("Raw Config ----------------") | ||
fmt.Printf("%+v\n", config) | ||
|
||
//j, _ := json.MarshalIndent(config.Plans(), "", " ") | ||
fmt.Println("Raw Plans ----------------") | ||
fmt.Printf("%+v\n", config.Plans()) | ||
// | ||
//j, _ = json.MarshalIndent(config.Services(), "", " ") | ||
fmt.Println("Raw Service ----------------") | ||
fmt.Printf("%+v\n", config.Services()) | ||
} |
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
Oops, something went wrong.