Exemplo n.º 1
0
// Handles deploy from file API call.
func (apiHandler *ApiHandler) handleDeployFromFile(request *restful.Request, response *restful.Response) {
	deploymentSpec := new(AppDeploymentFromFileSpec)
	if err := request.ReadEntity(deploymentSpec); err != nil {
		handleInternalError(response, err)
		return
	}

	isDeployed, err := DeployAppFromFile(
		deploymentSpec, CreateObjectFromInfoFn, apiHandler.clientConfig)
	if !isDeployed {
		handleInternalError(response, err)
		return
	}

	errorMessage := ""
	if err != nil {
		errorMessage = err.Error()
	}

	response.WriteHeaderAndEntity(http.StatusCreated, AppDeploymentFromFileResponse{
		Name:    deploymentSpec.Name,
		Content: deploymentSpec.Content,
		Error:   errorMessage,
	})
}
Exemplo n.º 2
0
// Handles protocol validation API call.
func (apiHandler *ApiHandler) handleProtocolValidity(request *restful.Request, response *restful.Response) {
	spec := new(ProtocolValiditySpec)
	if err := request.ReadEntity(spec); err != nil {
		handleInternalError(response, err)
		return
	}

	response.WriteHeaderAndEntity(http.StatusCreated, ValidateProtocol(spec))
}
Exemplo n.º 3
0
// Handles deploy API call.
func (apiHandler *ApiHandler) handleDeploy(request *restful.Request, response *restful.Response) {
	cfg := new(AppDeployment)
	if err := request.ReadEntity(cfg); err != nil {
		handleInternalError(response, err)
		return
	}
	if err := DeployApp(cfg, apiHandler.client); err != nil {
		handleInternalError(response, err)
		return
	}

	response.WriteHeaderAndEntity(http.StatusCreated, cfg)
}
Exemplo n.º 4
0
// Handles image pull secret creation API call.
func (apiHandler *ApiHandler) handleCreateImagePullSecret(request *restful.Request, response *restful.Response) {
	secretSpec := new(ImagePullSecretSpec)
	if err := request.ReadEntity(secretSpec); err != nil {
		handleInternalError(response, err)
		return
	}
	secret, err := CreateSecret(apiHandler.client, secretSpec)
	if err != nil {
		handleInternalError(response, err)
		return
	}
	response.WriteHeaderAndEntity(http.StatusCreated, secret)
}
Exemplo n.º 5
0
// Handles deploy from file API call.
func (apiHandler *ApiHandler) handleDeployFromFile(request *restful.Request, response *restful.Response) {
	deploymentSpec := new(AppDeploymentFromFileSpec)
	if err := request.ReadEntity(deploymentSpec); err != nil {
		handleInternalError(response, err)
		return
	}
	if err := DeployAppFromFile(deploymentSpec, CreateObjectFromInfoFn); err != nil {
		handleInternalError(response, err)
		return
	}

	response.WriteHeaderAndEntity(http.StatusCreated, deploymentSpec)
}
Exemplo n.º 6
0
func do(request *restful.Request, response *restful.Response) {
	u := &user{}
	err := request.ReadEntity(u)
	if err != nil {
		log.Printf("should be no error, got:%v", err)
	}
	log.Printf("got:%v", u)

	ur := &userResponse{Status: statusActive}

	response.SetRequestAccepts(MIME_MSGPACK)
	response.WriteEntity(ur)
}
Exemplo n.º 7
0
// Handles namespace creation API call.
func (apiHandler *ApiHandler) handleCreateNamespace(request *restful.Request,
	response *restful.Response) {
	namespaceSpec := new(NamespaceSpec)
	if err := request.ReadEntity(namespaceSpec); err != nil {
		handleInternalError(response, err)
		return
	}
	if err := CreateNamespace(namespaceSpec, apiHandler.client); err != nil {
		handleInternalError(response, err)
		return
	}

	response.WriteHeaderAndEntity(http.StatusCreated, namespaceSpec)
}
// Handles image reference validation API call.
func (ApiHandler *ApiHandler) handleImageReferenceValidity(request *restful.Request, response *restful.Response) {
	spec := new(ImageReferenceValiditySpec)
	if err := request.ReadEntity(spec); err != nil {
		handleInternalError(response, err)
		return
	}

	validity, err := ValidateImageReference(spec)
	if err != nil {
		handleInternalError(response, err)
		return
	}
	response.WriteHeaderAndEntity(http.StatusCreated, validity)
}
Exemplo n.º 9
0
// Handles app name validation API call.
func (apiHandler *ApiHandler) handleNameValidity(request *restful.Request, response *restful.Response) {
	spec := new(AppNameValiditySpec)
	if err := request.ReadEntity(spec); err != nil {
		handleInternalError(response, err)
		return
	}

	validity, err := ValidateAppName(spec, apiHandler.client)
	if err != nil {
		handleInternalError(response, err)
		return
	}

	response.WriteHeaderAndEntity(http.StatusCreated, validity)
}
Exemplo n.º 10
0
func (a *Api) setSinks(req *restful.Request, resp *restful.Response) {
	sinkUris := new([]string)
	if err := req.ReadEntity(sinkUris); err != nil {
		resp.WriteError(http.StatusBadRequest, err)
		return
	}
	var uris manager.Uris
	for _, s := range *sinkUris {
		if err := uris.Set(s); err != nil {
			resp.WriteError(http.StatusBadRequest, err)
			return
		}
	}
	if err := a.manager.SetSinkUris(uris); err != nil {
		resp.WriteError(http.StatusInternalServerError, err)
		return
	}
}
func (apiHandler *ApiHandler) handlePutResource(
	request *restful.Request, response *restful.Response) {
	kind := request.PathParameter("kind")
	namespace := request.PathParameter("namespace")
	name := request.PathParameter("name")
	putSpec := &runtime.Unknown{}
	if err := request.ReadEntity(putSpec); err != nil {
		handleInternalError(response, err)
		return
	}

	if err := apiHandler.verber.Put(kind, namespace, name, putSpec); err != nil {
		handleInternalError(response, err)
		return
	}

	response.WriteHeader(http.StatusOK)
}
Exemplo n.º 12
0
// Handles update of Replication Controller pods update API call.
func (apiHandler *ApiHandler) handleUpdateReplicasCount(
	request *restful.Request, response *restful.Response) {

	namespace := request.PathParameter("namespace")
	replicationControllerName := request.PathParameter("replicationController")
	replicationControllerSpec := new(ReplicationControllerSpec)

	if err := request.ReadEntity(replicationControllerSpec); err != nil {
		handleInternalError(response, err)
		return
	}

	if err := UpdateReplicasCount(apiHandler.client, namespace, replicationControllerName,
		replicationControllerSpec); err != nil {
		handleInternalError(response, err)
		return
	}

	response.WriteHeader(http.StatusAccepted)
}
Exemplo n.º 13
0
// patronize handles a request to patronize an artist.
func patronize(req *restful.Request, resp *restful.Response) {
	pr := PatronageRequest{}
	err := req.ReadEntity(&pr)
	if err != nil {
		log.Println(err)
		resp.WriteError(http.StatusBadRequest, err)
		return
	}
	//
	// Validate zip code
	//
	idx := validZip.FindStringIndex(pr.Zip)
	if idx == nil {
		log.Println("Invalid zip code:", pr.Zip)
		resp.WriteError(http.StatusBadRequest, err)
		return
	}
	//
	// Save patron to database
	//
	artistId, err := strconv.Atoi(req.PathParameter("artist-id"))
	if err != nil {
		log.Println(err)
		resp.WriteError(http.StatusBadRequest, err)
		return
	}
	p := Patron{
		ArtistId:  int64(artistId),
		Email:     pr.Email,
		Zip:       pr.Zip,
		Created:   time.Now(),
		Confirmed: false,
	}
	err = dbmap.Insert(&p)
	if err != nil {
		log.Println(err)
		resp.WriteError(http.StatusInternalServerError, err)
		return
	}
	resp.WriteEntity(p)
}
Exemplo n.º 14
0
// createArtist handles a request to create a new Artist.
func createArtist(req *restful.Request, resp *restful.Response) {
	ar := ArtistRequest{}
	err := req.ReadEntity(&ar)
	if err != nil {
		resp.WriteError(http.StatusBadRequest, err)
		return
	}
	a := Artist{
		Name:        ar.Name,
		Email:       ar.Email,
		Hometown:    ar.Hometown,
		Zip:         ar.Zip,
		Description: ar.Description,
	}
	err = dbmap.Insert(&a)
	if err != nil {
		resp.WriteError(http.StatusBadRequest, err)
		return
	}
	resp.WriteEntity(a)
}