Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 1 addition & 36 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ func store(cluster string, vhost string, username string, password string, billi
if err != nil {
fmt.Println(err)
}
fmt.Println(newname)
err = db.Close()
}

Expand Down Expand Up @@ -130,18 +129,8 @@ func retreive(v string) (c string, vh string, u string, p string, t []tagspec) {
db.Close()
}
}
fmt.Println(cluster)
fmt.Println(vhost)
fmt.Println(username)
fmt.Println(password_enc)
fmt.Println(Decrypt(password_enc))
var tagsa []tagspec
json.Unmarshal(tags, &tagsa)
for _, element := range tagsa {
fmt.Println(element.Resource)
fmt.Println(element.Name)
fmt.Println(element.Value)
}
db.Close()
return cluster, vhost, username, Decrypt(password_enc), tagsa

Expand Down Expand Up @@ -186,7 +175,6 @@ func delete(vhost string) error {
return dberr
}

fmt.Println("# Deleting")
stmt, err := db.Prepare("delete from provision where vhost=$1")
if err != nil {
return err
Expand All @@ -195,11 +183,10 @@ func delete(vhost string) error {
if err != nil {
return err
}
affect, err := res.RowsAffected()
_, err = res.RowsAffected()
if err != nil {
return err
}
fmt.Println(affect, "rows changed")

return nil
}
Expand All @@ -211,27 +198,22 @@ func url(params martini.Params, r render.Render) {
rcluster, rvhost, rusername, rpassword, _ := retreive(params["name"])
url := clusterInfo(rcluster).Amqp
amqp := "amqp://" + rusername + ":" + rpassword + "@" + url + ":5672/" + rvhost
fmt.Println(amqp)
r.JSON(200, map[string]string{"RABBITMQ_URL": amqp})
}

// func provision(..)
// TODO: Document
// TODO: error handling
func provision(spec provisionspec, err binding.Errors, r render.Render) {
fmt.Println(spec)
cluster := spec.Plan
billingcode := spec.Billingcode

newusername, newpassword := createuserandpassword()
create(cluster, newusername, newusername, newpassword)
fmt.Println(newusername)
fmt.Println(newpassword)
store(cluster, newusername, newusername, newpassword, billingcode)
rcluster, rvhost, rusername, rpassword, _ := retreive(newusername)
url := clusterInfo(rcluster).Amqp
amqp := "amqp://" + rusername + ":" + rpassword + "@" + url + ":5672/" + rvhost
fmt.Println(amqp)
r.JSON(201, map[string]string{"RABBITMQ_URL": amqp})

}
Expand Down Expand Up @@ -389,7 +371,6 @@ func createvhost(cluster string, vhost string) {
auth := base64.StdEncoding.EncodeToString([]byte(username + ":" + password))

client := &http.Client{}
fmt.Println("http://" + clusterinfo.Url + ":15672/api/vhosts/" + vhost)
request, _ := http.NewRequest("PUT", "http://"+clusterinfo.Url+":15672/api/vhosts/"+vhost, nil)
request.Header.Add("Authorization", "Basic "+auth)
request.Header.Add("Content-type", "application/json")
Expand Down Expand Up @@ -432,8 +413,6 @@ func createMirrorPolicy(cluster string, vhost string) {
if err != nil {
fmt.Println("Error preparing request")
}
jsonStr := (string(payload))
fmt.Println(jsonStr)

client := &http.Client{}
request, _ := http.NewRequest("PUT", "http://"+clusterinfo.Url+":15672/api/policies/"+vhost+"/"+policyname, bytes.NewBuffer(payload))
Expand Down Expand Up @@ -548,9 +527,6 @@ func tag(spec tagspec, berr binding.Errors, r render.Render) {
r.JSON(500, errorout)
return
}
fmt.Println(spec.Resource)
fmt.Println(spec.Name)
fmt.Println(spec.Value)
var tags []tagspec
_, _, _, _, tags = retreive(spec.Resource)
tags = append(tags, spec)
Expand All @@ -559,7 +535,6 @@ func tag(spec tagspec, berr binding.Errors, r render.Render) {
fmt.Println("Error preparing request")
}
jsonStr := (string(str))
fmt.Println(jsonStr)
uri := brokerdb
db, err := sql.Open("postgres", uri)
if err != nil {
Expand All @@ -572,7 +547,6 @@ func tag(spec tagspec, berr binding.Errors, r render.Render) {
if err != nil {
fmt.Println(err)
}
fmt.Println(nvhost)
err = db.Close()

r.JSON(201, map[string]interface{}{"response": "tag added"})
Expand All @@ -585,9 +559,7 @@ func tag(spec tagspec, berr binding.Errors, r render.Render) {
func getvaultcreds() (u string, p string) {
vaulttoken := os.Getenv("VAULT_TOKEN")
vaultaddr := os.Getenv("VAULT_ADDR")
fmt.Println(vaulttoken)
rabbitmqsecret := os.Getenv("RABBITMQ_SECRET")
fmt.Println(rabbitmqsecret)
vaultaddruri := vaultaddr + "/v1/" + rabbitmqsecret
vreq, err := http.NewRequest("GET", vaultaddruri, nil)
vreq.Header.Add("X-Vault-Token", vaulttoken)
Expand All @@ -598,18 +570,14 @@ func getvaultcreds() (u string, p string) {
}
defer vresp.Body.Close()
bodyj, err := simplejson.NewFromReader(vresp.Body)
fmt.Println(bodyj)
if err != nil {
fmt.Println(err)
}
fmt.Println(bodyj)
adminusername, _ := bodyj.Get("data").Get("username").String()
adminpassword, _ := bodyj.Get("data").Get("password").String()
keystring, _ := bodyj.Get("data").Get("key").String()
key = []byte(keystring)
brokerdb, _ = bodyj.Get("data").Get("brokerdb").String()
fmt.Println(adminusername)
fmt.Println(adminpassword)
return adminusername, adminpassword

}
Expand All @@ -623,8 +591,6 @@ func populateClusterInfo(adminuser string, adminpass string) {
var live ClusterInfo

adminuser, adminpass := getvaultcreds()
fmt.Println(adminuser)
fmt.Println(adminpass)
sandbox.Url = os.Getenv("SANDBOX_RABBIT_URL")
sandbox.Username = adminuser
sandbox.Password = adminpass
Expand All @@ -648,7 +614,6 @@ func populateClusterInfo(adminuser string, adminpass string) {
c.Password = adminpass
c.Amqp = os.Getenv(strings.ToUpper(element) + "_RABBIT_AMQP")
c.Cluster = element
fmt.Println(c)
clusters = append(clusters, c)
}

Expand Down