github.com/sap/cf-mta-plugin@v2.6.3+incompatible/clients/restclient/rest_client.go (about) 1 package restclient 2 3 import ( 4 "context" 5 "net/http" 6 7 "github.com/go-openapi/runtime" 8 "github.com/go-openapi/strfmt" 9 10 "github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/baseclient" 11 "github.com/cloudfoundry-incubator/multiapps-cli-plugin/clients/restclient/operations" 12 ) 13 14 const restBaseURL string = "rest/" 15 const csrfRestBaseURL string = "api/v1/" 16 17 // RestClient represents a client for the MTA deployer REST protocol 18 type RestClient struct { 19 baseclient.BaseClient 20 Client *Rest 21 } 22 23 // NewRestClient creates a new Rest client 24 func NewRestClient(host string, rt http.RoundTripper, tokenFactory baseclient.TokenFactory) RestClientOperations { 25 t := baseclient.NewHTTPTransport(host, restBaseURL, restBaseURL, rt) 26 client := New(t, strfmt.Default) 27 return RestClient{baseclient.BaseClient{tokenFactory}, client} 28 } 29 30 func (c RestClient) PurgeConfiguration(org, space string) error { 31 params := &operations.PurgeConfigurationParams{ 32 Org: org, 33 Space: space, 34 Context: context.TODO(), 35 } 36 _, err := executeRestOperation(c.TokenFactory, func(token runtime.ClientAuthInfoWriter) (interface{}, error) { 37 return c.Client.Operations.PurgeConfiguration(params, token) 38 }) 39 if err != nil { 40 return baseclient.NewClientError(err) 41 } 42 return nil 43 } 44 45 func executeRestOperation(tokenProvider baseclient.TokenFactory, restOperation func(token runtime.ClientAuthInfoWriter) (interface{}, error)) (interface{}, error) { 46 token, err := tokenProvider.NewToken() 47 if err != nil { 48 return nil, baseclient.NewClientError(err) 49 } 50 return restOperation(token) 51 }