github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/api/cloudcontroller/ccv3/application_feature.go (about) 1 package ccv3 2 3 import ( 4 "bytes" 5 "fmt" 6 7 "code.cloudfoundry.org/cli/api/cloudcontroller" 8 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal" 9 ) 10 11 type ApplicationFeature struct { 12 // Name of the application feature 13 Name string 14 Enabled bool 15 //Reason string `json:omitempty` 16 } 17 18 type SSHEnabled struct { 19 Enabled bool 20 Reason string 21 } 22 23 func (client *Client) GetAppFeature(appGUID string, featureName string) (ApplicationFeature, Warnings, error) { 24 request, err := client.newHTTPRequest(requestOptions{ 25 RequestName: internal.GetApplicationFeaturesRequest, 26 URIParams: map[string]string{"app_guid": appGUID, "name": featureName}, 27 }) 28 29 if err != nil { 30 return ApplicationFeature{}, nil, err 31 } 32 33 var applicationFeature ApplicationFeature 34 response := cloudcontroller.Response{ 35 DecodeJSONResponseInto: &applicationFeature, 36 } 37 38 err = client.connection.Make(request, &response) 39 40 return applicationFeature, response.Warnings, err 41 } 42 43 func (client *Client) GetSSHEnabled(appGUID string) (SSHEnabled, Warnings, error) { 44 request, err := client.newHTTPRequest(requestOptions{ 45 RequestName: internal.GetSSHEnabled, 46 URIParams: map[string]string{"app_guid": appGUID}, 47 }) 48 49 if err != nil { 50 return SSHEnabled{}, nil, err 51 } 52 53 var sshEnabled SSHEnabled 54 response := cloudcontroller.Response{ 55 DecodeJSONResponseInto: &sshEnabled, 56 } 57 58 err = client.connection.Make(request, &response) 59 60 return sshEnabled, response.Warnings, err 61 } 62 63 // UpdateAppFeature enables/disables the ability to ssh for a given application. 64 func (client *Client) UpdateAppFeature(appGUID string, enabled bool, featureName string) (Warnings, error) { 65 request, err := client.newHTTPRequest(requestOptions{ 66 RequestName: internal.PatchApplicationFeaturesRequest, 67 Body: bytes.NewReader([]byte(fmt.Sprintf(`{"enabled":%t}`, enabled))), 68 URIParams: map[string]string{"app_guid": appGUID, "name": featureName}, 69 }) 70 71 if err != nil { 72 return nil, err 73 } 74 75 response := cloudcontroller.Response{} 76 err = client.connection.Make(request, &response) 77 78 return response.Warnings, err 79 }