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

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

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

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

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

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

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

	metadata, err := accounts.Get(command.Ctx.ServiceClient).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
}
Esempio n. 3
0
func (command *commandGetMetadata) Execute(resource *handler.Resource) {
	metadata, err := accounts.Get(command.Ctx.ServiceClient).ExtractMetadata()
	if err != nil {
		resource.Err = err
		return
	}

	resource.Result = metadata
}