Ejemplo n.º 1
0
func (command *commandSetMetadata) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsSetMetadata)
	containerName := params.containerName

	currentMetadata, err := containers.Get(command.Ctx.ServiceClient, containerName).ExtractMetadata()
	if err != nil {
		resource.Err = err
		return
	}

	i := 0
	keys := make([]string, len(currentMetadata))
	for k := range currentMetadata {
		keys[i] = k
		i++
	}

	updateOpts := containers.UpdateOpts{
		Metadata:       params.metadata,
		DeleteMetadata: keys,
	}
	updateResponse := containers.Update(command.Ctx.ServiceClient, containerName, updateOpts)
	if updateResponse.Err != nil {
		resource.Err = updateResponse.Err
		return
	}

	metadata, err := containers.Get(command.Ctx.ServiceClient, containerName).ExtractMetadata()
	if err != nil {
		resource.Err = err
		return
	}

	resource.Result = metadata
}
Ejemplo n.º 2
0
func (command *commandUpdateMetadata) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsUpdateMetadata)
	containerName := params.containerName

	getResponse := containers.Get(command.Ctx.ServiceClient, containerName)
	if getResponse.Err != nil {
		resource.Err = getResponse.Err
		return
	}

	updateOpts := containers.UpdateOpts{
		Metadata: params.metadata,
	}
	updateResponse := containers.Update(command.Ctx.ServiceClient, containerName, updateOpts)
	if updateResponse.Err != nil {
		resource.Err = updateResponse.Err
		return
	}

	metadata, err := containers.Get(command.Ctx.ServiceClient, containerName).ExtractMetadata()
	if err != nil {
		resource.Err = err
		return
	}

	updatedMetadata := make(map[string]string, len(params.metadata))
	for k := range params.metadata {
		k = strings.Title(k)
		updatedMetadata[k] = metadata[k]
	}

	resource.Result = updatedMetadata
}
Ejemplo n.º 3
0
func (command *commandUpdate) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsUpdate)
	containerName := params.container

	containerRaw := containers.Get(command.Ctx.ServiceClient, containerName)
	if containerRaw.Err != nil {
		resource.Err = containerRaw.Err
		return
	}

	opts := params.opts
	rawResponse := containers.Update(command.Ctx.ServiceClient, containerName, opts)
	if rawResponse.Err != nil {
		resource.Err = rawResponse.Err
		return
	}
	resource.Result = fmt.Sprintf("Successfully updated container [%s]\n", containerName)
}
Ejemplo n.º 4
0
func (command *commandDeleteMetadata) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsDeleteMetadata)
	containerName := params.containerName

	getResponse := containers.Get(command.Ctx.ServiceClient, containerName)
	if getResponse.Err != nil {
		resource.Err = getResponse.Err
		return
	}

	updateOpts := containers.UpdateOpts{
		DeleteMetadata: params.metadataKeys,
	}
	updateResponse := containers.Update(command.Ctx.ServiceClient, containerName, updateOpts)
	if updateResponse.Err != nil {
		resource.Err = updateResponse.Err
		return
	}
	resource.Result = fmt.Sprintf("Successfully deleted metadata with keys [%s] from container [%s].\n", strings.Join(params.metadataKeys, ", "), containerName)
}