func (repo CloudControllerBuildpackRepository) Update(buildpack models.Buildpack) (updatedBuildpack models.Buildpack, apiErr error) { path := fmt.Sprintf("%s/%s", buildpacksPath, buildpack.GUID) entity := resources.BuildpackEntity{ Name: buildpack.Name, Position: buildpack.Position, Enabled: buildpack.Enabled, Key: "", Filename: "", Locked: buildpack.Locked, } body, err := json.Marshal(entity) if err != nil { apiErr = fmt.Errorf("%s: %s", T("Could not serialize updates."), err.Error()) return } resource := new(resources.BuildpackResource) apiErr = repo.gateway.UpdateResource(repo.config.APIEndpoint(), path, bytes.NewReader(body), resource) if apiErr != nil { return } updatedBuildpack = resource.ToFields() return }
func (repo CloudControllerBuildpackRepository) Create(name string, position *int, enabled *bool, locked *bool) (createdBuildpack models.Buildpack, apiErr error) { entity := resources.BuildpackEntity{Name: name, Position: position, Enabled: enabled, Locked: locked} body, err := json.Marshal(entity) if err != nil { apiErr = fmt.Errorf("%s: %s", T("Could not serialize information"), err.Error()) return } resource := new(resources.BuildpackResource) apiErr = repo.gateway.CreateResource(repo.config.APIEndpoint(), buildpacksPath, bytes.NewReader(body), resource) if apiErr != nil { return } createdBuildpack = resource.ToFields() return }