コード例 #1
0
ファイル: services.go プロジェクト: gisnalbert/rack
func ServiceDelete(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	service := mux.Vars(r)["service"]

	s, err := models.GetService(service)

	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such service: %s", service)
	}

	if err != nil {
		return httperr.Server(err)
	}

	err = s.Delete()

	if err != nil {
		return httperr.Server(err)
	}

	s, err = models.GetService(service)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, s)
}
コード例 #2
0
ファイル: services.go プロジェクト: cleblanc87/rack
func ServiceDelete(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	service := mux.Vars(r)["service"]

	s, err := models.GetService(service)
	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such service: %s", service)
	}
	if err != nil {
		return httperr.Server(err)
	}

	// new services should use the provider interfaces
	if s.Type == "syslog" {
		s, err := provider.ServiceDelete(service)
		if err != nil {
			return httperr.Server(err)
		}

		return RenderJson(rw, s)
	}

	err = s.Delete()
	if err != nil {
		return httperr.Server(err)
	}

	s, err = models.GetService(service)
	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, s)
}
コード例 #3
0
ファイル: services.go プロジェクト: jbuck/rack
func ServiceDelete(rw http.ResponseWriter, r *http.Request) error {
	service := mux.Vars(r)["service"]

	s, err := models.GetService(service)

	if awsError(err) == "ValidationError" {
		return RenderNotFound(rw, fmt.Sprintf("no such service: %s", service))
	}

	if err != nil {
		return err
	}

	err = s.Delete()

	if err != nil {
		return err
	}

	s, err = models.GetService(service)

	if err != nil {
		return err
	}

	return RenderJson(rw, s)
}
コード例 #4
0
ファイル: services.go プロジェクト: jbuck/rack
func ServiceCreate(rw http.ResponseWriter, r *http.Request) error {
	name := GetForm(r, "name")
	t := GetForm(r, "type")

	service := &models.Service{
		Name: name,
		Type: t,
	}

	err := service.Create()

	if awsError(err) == "ValidationError" {
		return RenderForbidden(rw, fmt.Sprintf("invalid service name: %s", name))
	}

	if err != nil {
		return err
	}

	service, err = models.GetService(name)

	if err != nil {
		return err
	}

	return RenderJson(rw, service)
}
コード例 #5
0
ファイル: services.go プロジェクト: cleblanc87/rack
func ServiceUpdate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	service := mux.Vars(r)["service"]

	s, err := models.GetService(service)

	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such service: %s", service)
	}

	if err != nil {
		return httperr.Server(err)
	}

	err = r.ParseForm()
	if err != nil {
		return httperr.Server(err)
	}

	// get the last set value for all form values
	// ie:  foo=1&foo=2  sets foo to "2"
	params := make(map[string]string)
	for key, values := range r.Form {
		val := values[len(values)-1]
		params[key] = val
	}

	err = s.Update(models.CFParams(params))

	if err != nil && awsError(err) == "ValidationError" {
		e := err.(awserr.Error)
		return httperr.Errorf(403, convoxifyCloudformationError(e.Message()))
	}

	if err != nil {
		return httperr.Server(err)
	}

	s, err = models.GetService(service)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, s)
}
コード例 #6
0
ファイル: services.go プロジェクト: soulware/rack
func ServiceCreate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	err := r.ParseForm()
	if err != nil {
		return httperr.Server(err)
	}

	// get the last set value for all form values
	// ie:  foo=1&foo=2  sets foo to "2"
	params := make(map[string]string)
	for key, values := range r.Form {
		val := values[len(values)-1]
		params[key] = val
	}
	name := params["name"]
	delete(params, "name")
	kind := params["type"]
	delete(params, "type")

	// Early check for unbound service only.
	service, err := models.GetServiceUnbound(name)

	if err == nil {
		return httperr.Errorf(403, "there is already a legacy service named %s (%s). We recommend you delete this service and create it again.", name, service.Status)
	}

	if awsError(err) == "ValidationError" {
		// If unbound check fails this will result in a bound service.
		service = &models.Service{
			Name:       name,
			Type:       kind,
			Parameters: models.CFParams(params),
		}
	}

	err = service.Create()

	if err != nil && strings.HasSuffix(err.Error(), "not found") {
		return httperr.Errorf(403, "invalid service type: %s", kind)
	}

	if err != nil && awsError(err) == "ValidationError" {
		e := err.(awserr.Error)
		return httperr.Errorf(403, convoxifyCloudformationError(e.Message()))
	}

	if err != nil {
		return httperr.Server(err)
	}

	service, err = models.GetService(name)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, service)
}
コード例 #7
0
ファイル: links.go プロジェクト: cleblanc87/rack
func LinkCreate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	service := mux.Vars(r)["service"]

	s, err := models.GetService(service)
	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such service: %s", service)
	}
	if err != nil {
		return httperr.Server(err)
	}

	if s.Status != "running" {
		return httperr.Errorf(403, "can not link service with status: %s", s.Status)
	}

	// new services should use the provider interfaces
	if s.Type == "syslog" {
		s, err := provider.ServiceLink(service, GetForm(r, "app"), GetForm(r, "process"))
		if err != nil {
			return httperr.Server(err)
		}

		return RenderJson(rw, s)
	}

	if s.Type != "papertrail" {
		return httperr.Errorf(403, "linking is not yet implemented for service type: %s", s.Type)
	}

	app := GetForm(r, "app")

	a, err := models.GetApp(app)

	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such app: %s", app)
	}

	if err != nil {
		return httperr.Server(err)
	}

	err = s.LinkPapertrail(*a)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, s)
}
コード例 #8
0
ファイル: services.go プロジェクト: anthonyrisinger/rack
func ServiceCreate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	err := r.ParseForm()
	if err != nil {
		return httperr.Server(err)
	}

	// get the last set value for all form values
	// ie:  foo=1&foo=2  sets foo to "2"
	params := make(map[string]string)
	for key, values := range r.Form {
		val := values[len(values)-1]
		params[key] = val
	}
	name := params["name"]
	delete(params, "name")
	kind := params["type"]
	delete(params, "type")

	service := &models.Service{
		Name:       name,
		Type:       kind,
		Parameters: models.CFParams(params),
	}

	err = service.Create()

	if err != nil && strings.HasSuffix(err.Error(), "not found") {
		return httperr.Errorf(403, "invalid service type: %s", kind)
	}

	if err != nil && awsError(err) == "ValidationError" {
		e := err.(awserr.Error)
		return httperr.Errorf(403, convoxifyCloudformationError(e.Message()))
	}

	if err != nil {
		return httperr.Server(err)
	}

	service, err = models.GetService(name)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, service)
}
コード例 #9
0
ファイル: services.go プロジェクト: gisnalbert/rack
func ServiceCreate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	name := GetForm(r, "name")
	t := GetForm(r, "type")
	url := GetForm(r, "url")

	service := &models.Service{
		Name: name,
		Type: t,
		URL:  url,
	}

	var err error

	switch t {
	case "papertrail":
		err = service.CreatePapertrail()
	case "webhook":
		err = service.CreateWebhook()
	default:
		err = service.CreateDatastore()
	}

	if err != nil && strings.HasSuffix(err.Error(), "not found") {
		return httperr.Errorf(403, "invalid service type: %s", t)
	}

	if err != nil && awsError(err) == "ValidationError" {
		return httperr.Errorf(403, "invalid service name: %s", name)
	}

	if err != nil {
		return httperr.Server(err)
	}

	service, err = models.GetService(name)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, service)
}
コード例 #10
0
ファイル: services.go プロジェクト: harryross/rack
func ServiceLogs(ws *websocket.Conn) error {
	service := mux.Vars(ws.Request())["service"]

	s, err := models.GetService(service)

	if err != nil {
		return err
	}

	logs := make(chan []byte)
	done := make(chan bool)

	s.SubscribeLogs(logs, done)

	for data := range logs {
		ws.Write(data)
	}

	return nil
}
コード例 #11
0
ファイル: links.go プロジェクト: anthonyrisinger/rack
func LinkDelete(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	app := mux.Vars(r)["app"]
	service := mux.Vars(r)["service"]

	s, err := models.GetService(service)

	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such service: %s", service)
	}

	if err != nil {
		return httperr.Server(err)
	}

	if s.Status != "running" {
		return httperr.Errorf(403, "can not unlink service with status: %s", s.Status)
	}

	if s.Type != "papertrail" {
		return httperr.Errorf(403, "unlinking is not yet implemented for service type: %s", s.Type)
	}

	a, err := models.GetApp(app)

	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such app: %s", app)
	}

	if err != nil {
		return httperr.Server(err)
	}

	err = s.UnlinkPapertrail(*a)

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, s)
}
コード例 #12
0
ファイル: services.go プロジェクト: gisnalbert/rack
func ServiceLogs(ws *websocket.Conn) *httperr.Error {
	service := mux.Vars(ws.Request())["service"]

	s, err := models.GetService(service)

	if err != nil {
		return httperr.Server(err)
	}

	logs := make(chan []byte)
	done := make(chan bool)

	s.SubscribeLogs(logs, done)

	go signalWsClose(ws, done)

	for data := range logs {
		ws.Write(data)
	}

	return nil
}