github.com/sap/cf-mta-plugin@v2.6.3+incompatible/clients/mtaclient_v2/mta_v2_rest_client.go (about)

     1  package mtaclient_v2
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  
     7  	"github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/baseclient"
     8  	"github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/models"
     9  	"github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/mtaclient_v2/operations"
    10  	"github.com/go-openapi/runtime"
    11  	"github.com/go-openapi/strfmt"
    12  )
    13  
    14  const restBaseURL string = ""
    15  
    16  type MtaV2RestClient struct {
    17  	baseclient.BaseClient
    18  	client    *HTTPMtaV2
    19  	spaceGUID string
    20  }
    21  
    22  func NewMtaClient(host string, spaceGUID string, rt http.RoundTripper, tokenFactory baseclient.TokenFactory) MtaV2ClientOperations {
    23  	t := baseclient.NewHTTPTransport(host, restBaseURL, restBaseURL, rt)
    24  	httpMtaV2Client := New(t, strfmt.Default)
    25  	return &MtaV2RestClient{baseclient.BaseClient{TokenFactory: tokenFactory}, httpMtaV2Client, spaceGUID}
    26  }
    27  
    28  func (c MtaV2RestClient) GetMtas(name, namespace *string, spaceGuid string) ([]*models.Mta, error) {
    29  	params := &operations.GetMtasV2Params{
    30  		Context:   context.TODO(),
    31  		Name:      name,
    32  		Namespace: namespace,
    33  		SpaceGUID: spaceGuid,
    34  	}
    35  	token, err := c.TokenFactory.NewToken()
    36  	if err != nil {
    37  		return nil, baseclient.NewClientError(err)
    38  	}
    39  	resp, err := c.client.Operations.GetMtasV2(params, token)
    40  	if err != nil {
    41  		return nil, baseclient.NewClientError(err)
    42  	}
    43  	return resp.Payload, nil
    44  }
    45  
    46  func (c MtaV2RestClient) GetMtasForThisSpace(name, namespace *string) ([]*models.Mta, error) {
    47  	return c.GetMtas(name, namespace, c.spaceGUID)
    48  }
    49  
    50  func executeRestOperation(tokenProvider baseclient.TokenFactory, restOperation func(token runtime.ClientAuthInfoWriter) (interface{}, error)) (interface{}, error) {
    51  	token, err := tokenProvider.NewToken()
    52  	if err != nil {
    53  		return nil, baseclient.NewClientError(err)
    54  	}
    55  	return restOperation(token)
    56  }