Beispiel #1
0
// Create creates a resource.
// If the resource exists, it will be replaced.
func (r *Request) Create(resource api.Resource) (api.ChangeInfo, error) {

	response, err := r.UnderlyingRequest.Create(resource)

	if err != nil {
		return nil, err
	}

	changeInfo, err := extractChangeInfo(response)

	if err != nil {
		return nil, err
	}

	if changeInfo.Created() == 1 {
		resource.SetID(changeInfo.Deltas()[0][common.DataFieldID].(string))
	}

	if changeInfo.HasDeltas() {
		resource.ResourceData().MergeHere(changeInfo.Deltas()[0])
	}

	return changeInfo, nil

}
Beispiel #2
0
// Replace replaces a resource.
// If the resource does not exist, it will be created.
func (r *Request) Replace(resource api.Resource) (api.ChangeInfo, error) {

	response, err := r.UnderlyingRequest.Replace(resource)

	if err != nil {
		return nil, err
	}

	changeInfo, err := extractChangeInfo(response)

	if err != nil {
		return nil, err
	}

	if changeInfo.HasDeltas() {
		resource.ResourceData().MergeHere(changeInfo.Deltas()[0])
	}

	return changeInfo, nil

}