func (command *commandDeleteMetadata) Execute(resource *handler.Resource) { params := resource.Params.(*paramsDeleteMetadata) containerName := params.containerName objectName := params.objectName currentMetadata, err := objects.Get(command.Ctx.ServiceClient, containerName, objectName, nil).ExtractMetadata() if err != nil { resource.Err = err return } for _, k := range params.metadataKeys { currentMetadata[k] = "" } updateOpts := osObjects.UpdateOpts{ Metadata: currentMetadata, } updateResponse := objects.Update(command.Ctx.ServiceClient, containerName, objectName, updateOpts) if updateResponse.Err != nil { resource.Err = updateResponse.Err return } resource.Result = fmt.Sprintf("Successfully deleted metadata with keys [%s] from object [%s].\n", strings.Join(params.metadataKeys, ", "), objectName) }
func (command *commandUpdateMetadata) Execute(resource *handler.Resource) { params := resource.Params.(*paramsUpdateMetadata) containerName := params.containerName objectName := params.objectName currentMetadata, err := objects.Get(command.Ctx.ServiceClient, containerName, objectName, nil).ExtractMetadata() if err != nil { resource.Err = err return } for k, v := range params.metadata { k = strings.Title(k) currentMetadata[k] = v } updateOpts := osObjects.UpdateOpts{ Metadata: currentMetadata, } updateResponse := objects.Update(command.Ctx.ServiceClient, containerName, objectName, updateOpts) if updateResponse.Err != nil { resource.Err = updateResponse.Err return } metadata, err := objects.Get(command.Ctx.ServiceClient, containerName, objectName, nil).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 *commandGetMetadata) Execute(resource *handler.Resource) { params := resource.Params.(*paramsGetMetadata) containerName := params.containerName objectName := params.objectName metadata, err := objects.Get(command.Ctx.ServiceClient, containerName, objectName, nil).ExtractMetadata() if err != nil { resource.Err = err return } resource.Result = metadata }
func (command *commandSetMetadata) Execute(resource *handler.Resource) { params := resource.Params.(*paramsSetMetadata) containerName := params.containerName objectName := params.objectName currentMetadata, err := objects.Get(command.Ctx.ServiceClient, containerName, objectName, nil).ExtractMetadata() if err != nil { resource.Err = err return } for k := range currentMetadata { currentMetadata[k] = "" } for k, v := range params.metadata { currentMetadata[k] = v } updateOpts := osObjects.UpdateOpts{ Metadata: currentMetadata, } updateResponse := objects.Update(command.Ctx.ServiceClient, containerName, objectName, updateOpts) if updateResponse.Err != nil { resource.Err = updateResponse.Err return } metadata, err := objects.Get(command.Ctx.ServiceClient, containerName, objectName, nil).ExtractMetadata() if err != nil { resource.Err = err return } resource.Result = metadata }