Пример #1
0
// DeleteParticularServiceBinding unbind a service with particular app
func DeleteParticularServiceBinding(w http.ResponseWriter, r *http.Request) {
	render := &api.Render{r, w}
	config := configuration.GetDefaultConfig()
	if err := json.NewDecoder(r.Body).Decode(&config); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
	}

	appName := r.URL.Query().Get("app")
	instanceName := r.URL.Query().Get("service")

	bindRepo := UnbindService{}
	app, err := bindRepo.appRepo.FindByName(config, appName)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}

	instance, err := bindRepo.serviceRepo.FindInstanceByName(config, instanceName)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}

	log.Printf("Unbinding service %s to %s...", instance.Name, app.Name)
	err = bindRepo.serviceRepo.UnbindService(config, instance, app)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}

	log.Printf("Service details: %+v", config)
	render.JSON(config)
}
Пример #2
0
func (o OrganizationList) Run(w http.ResponseWriter, r *http.Request) {
	render := &api.Render{r, w}

	config := configuration.GetDefaultConfig()

	session := configuration.Session{}

	if err := json.NewDecoder(r.Body).Decode(&session); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
	}

	c := configuration.RedisConnect()
	defer c.Close()

	reply, err := c.Do("GET", "user:"******"List of organizations: %+v", orgs)
	render.JSON(orgs)
}
Пример #3
0
// CreatingAnApp will create app
func CreatingAnApp(w http.ResponseWriter, r *http.Request) {
	render := &api.Render{r, w}

	config := configuration.GetDefaultConfig()
	if err := json.NewDecoder(r.Body).Decode(&config); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
	}

	appName := r.URL.Query().Get("appname")
	repo := api.CloudControllerApplicationRepository{}

	app, err := repo.FindByName(config, appName)

	if err != nil {
		app, err = createApp(config, appName)

		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
	}

	// TODO, need to implement
	// err = repo.Upload(config, app)
	// if err != nil {
	// 	http.Error(w, err.Error(), http.StatusInternalServerError)
	// 	return
	// }

	log.Printf("App details: %+v", app)
	render.JSON(app)
}
Пример #4
0
// PutPerson get user token from CC
func (l Login) PutUser(u *User) (config *configuration.Configuration, err error) {
	config = configuration.GetDefaultConfig()

	response, err := api.Authenticate(config.AuthorizationEndpoint, u.Email, u.Password)
	if err != nil {
		return
	}

	config.AccessToken = fmt.Sprintf("%s %s", response.TokenType, response.AccessToken)
	return
}
func (a *AppEvents) GetRequirements(reqFactory requirements.Factory, w http.ResponseWriter, r *http.Request) (reqs []Requirement, config *configuration.Configuration, err error) {
	config = configuration.GetDefaultConfig()
	if err := json.NewDecoder(r.Body).Decode(&config); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
	}

	a.config = config

	appName := r.URL.Query().Get("appname")
	a.appReq = reqFactory.NewApplicationRequirement(appName)

	reqs = []Requirement{&a.appReq}
	return
}
Пример #6
0
// ListAllSpaces Get list of all spaces
func ListAllSpaces(w http.ResponseWriter, r *http.Request) {
	render := &Render{r, w}

	config := configuration.GetDefaultConfig()
	if err := json.NewDecoder(r.Body).Decode(&config); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
	}

	repo := CloudControllerSpaceRepository{}
	spaces, err := repo.FindAllSpaces(config)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}

	log.Printf("List of spaces: %+v", spaces)
	render.JSON(spaces)
}
// CreatingServiceInstance create a service instance
func CreatingServiceInstance(w http.ResponseWriter, r *http.Request) {
	render := &api.Render{r, w}

	config := configuration.GetDefaultConfig()
	if err := json.NewDecoder(r.Body).Decode(&config); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
	}

	name := r.URL.Query().Get("name")
	offeringName := r.URL.Query().Get("offering")
	planName := r.URL.Query().Get("plan")

	serviceRepo := api.CloudControllerServiceRepository{}
	offerings, err := serviceRepo.GetServiceOfferings(config)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}

	offering, err := findOffering(offerings, offeringName)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}

	plan, err := findPlan(offering.Plans, planName)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}

	log.Printf("Creating service %s", name)
	err = serviceRepo.CreateServiceInstance(config, name, plan)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}

	// TODO, find service by name and send json response
	log.Printf("Service details: %+v", config)
	render.JSON(config)
}
Пример #8
0
package api

import (
	"github.com/diatmpravin/gagan/api"
	"github.com/diatmpravin/gagan/commands"
	"github.com/diatmpravin/gagan/configuration"
	"github.com/diatmpravin/gagan/requirements"
	"net/http"
	"strings"
	"text/template"
)

// var configRepo = configuration.NewConfigurationDiskRepository()
var config = configuration.GetDefaultConfig()

var repoLocator = api.NewRepositoryLocator(config)
var cmdFactory = commands.NewFactory(repoLocator)

var reqFactory = requirements.NewFactory(repoLocator)
var cmdRunner = commands.NewRunner(reqFactory)

// custom template delimiters since the Go default delimiters clash
// with Angular's default.
var templateDelims = []string{"{{%", "%}}"}

func LoginHandler(w http.ResponseWriter, r *http.Request) {
	t := template.New("login.html")
	t.Delims(templateDelims[0], templateDelims[1])
	t.ParseFiles("web/pages/login.html")
	t.Execute(w, t)
}