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 }
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 }
func (command *commandGet) Execute(resource *handler.Resource) { containerName := resource.Params.(*paramsGet).container containerInfo, err := containers.Get(command.Ctx.ServiceClient, containerName).Extract() if err != nil { resource.Err = err return } resource.Result = structs.Map(containerInfo) resource.Result.(map[string]interface{})["Name"] = containerName }
func (command *commandGetMetadata) Execute(resource *handler.Resource) { params := resource.Params.(*paramsGetMetadata) containerName := params.containerName metadata, err := containers.Get(command.Ctx.ServiceClient, containerName).ExtractMetadata() if err != nil { resource.Err = err return } resource.Result = metadata }
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) }
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) }