code.cloudfoundry.org/cli@v7.1.0+incompatible/actor/v2action/stack.go (about)

     1  package v2action
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/actionerror"
     5  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
     7  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant"
     8  )
     9  
    10  type Stack ccv2.Stack
    11  
    12  // GetStack returns the stack information associated with the provided stack GUID.
    13  func (actor Actor) GetStack(guid string) (Stack, Warnings, error) {
    14  	stack, warnings, err := actor.CloudControllerClient.GetStack(guid)
    15  
    16  	if _, ok := err.(ccerror.ResourceNotFoundError); ok {
    17  		return Stack{}, Warnings(warnings), actionerror.StackNotFoundError{GUID: guid}
    18  	}
    19  
    20  	return Stack(stack), Warnings(warnings), err
    21  }
    22  
    23  // GetStackByName returns the provided stack
    24  func (actor Actor) GetStackByName(stackName string) (Stack, Warnings, error) {
    25  	stacks, warnings, err := actor.CloudControllerClient.GetStacks(ccv2.Filter{
    26  		Type:     constant.NameFilter,
    27  		Operator: constant.EqualOperator,
    28  		Values:   []string{stackName},
    29  	})
    30  	if err != nil {
    31  		return Stack{}, Warnings(warnings), err
    32  	}
    33  
    34  	if len(stacks) == 0 {
    35  		return Stack{}, Warnings(warnings), actionerror.StackNotFoundError{Name: stackName}
    36  	}
    37  
    38  	return Stack(stacks[0]), Warnings(warnings), nil
    39  }