Skip to content

Commit f20d427

Browse files
committed
review findings
- remove unneeded struct - remove newline - go fmt
1 parent 05447f8 commit f20d427

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/jetstream/plugins/cfappssh/app_ssh.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ type KeyCode struct {
4646
Rows int `json:"rows"`
4747
}
4848

49+
// When dealing with a v3 enabled cf api, we need to use the processID to build the username to create an SSH
50+
// connection to the app instances web process.
4951
func CheckForV3AvailabilityAndReturnProcessID(appID, baseURL, clientID, token string, apiClient http.Client) (string, error) {
5052
resp, err := apiClient.Head(fmt.Sprintf("%s/%s", baseURL, "v3"))
5153
if resp.StatusCode == http.StatusNotFound {
@@ -63,10 +65,10 @@ func CheckForV3AvailabilityAndReturnProcessID(appID, baseURL, clientID, token st
6365
defer resp.Body.Close()
6466
respBytes, err := io.ReadAll(resp.Body)
6567
if err != nil {
66-
return appID, sendSSHError("failed reading response for '%s': %s", resp.Request.URL.Path , err)
68+
return appID, sendSSHError("failed reading response for '%s': %s", resp.Request.URL.Path, err)
6769
}
68-
appWebProcess := &cloudFoundryResource.Process{}
69-
err = appWebProcess.UnmarshalJSON(respBytes);
70+
appWebProcess := &cloudFoundryResource.Process{}
71+
err = appWebProcess.UnmarshalJSON(respBytes)
7072
if err != nil {
7173
return appID, sendSSHError("failed unmarshaling response: '%s' for app_guid '%s': %s", string(respBytes), appID, err)
7274
}
@@ -96,7 +98,6 @@ func (cfAppSsh *CFAppSSH) appSSH(c echo.Context) error {
9698
apiEndpoint := cnsiRecord.APIEndpoint
9799

98100
cfPlugin, err := p.GetEndpointTypeSpec("cf")
99-
100101
if err != nil {
101102
return sendSSHError("Can not get Cloud Foundry endpoint plugin")
102103
}
@@ -111,7 +112,6 @@ func (cfAppSsh *CFAppSSH) appSSH(c echo.Context) error {
111112
return sendSSHError("Can not get Cloud Foundry Endpoint info")
112113
}
113114
cfInfo := cfInfoEndpoint.V2Info
114-
115115
appOrProcessGUID := c.Param("appGuid")
116116

117117
// Refresh token first - makes sure it will be valid when we make the request to get the code

src/jetstream/plugins/cfappssh/app_ssh_test.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,17 @@ import (
99
"testing"
1010

1111
"github.com/cloudfoundry/stratos/src/jetstream/plugins/cfappssh"
12-
"github.com/labstack/echo/v4"
1312
)
1413

15-
type FakeContext struct {
16-
echo.Context
17-
}
18-
1914
func TestCheckForV3Availability(t *testing.T) {
2015
expectedProcessID := "i-am-process-id"
2116
appGUID := "some-guid"
2217

23-
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request){
18+
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2419
appWebProcess := map[string]string{
2520
"AppGUID": "one two three",
26-
"guid": "i-am-process-id",
27-
"Type": "web",
21+
"guid": "i-am-process-id",
22+
"Type": "web",
2823
}
2924
re := regexp.MustCompile("^/v3")
3025

@@ -48,7 +43,7 @@ func TestCheckForV3Availability(t *testing.T) {
4843
apiClient := http.Client{}
4944
processID, err := cfappssh.CheckForV3AvailabilityAndReturnProcessID(appGUID, testServer.URL, "","", apiClient)
5045
if err != nil {
51-
t.Errorf("I didn't expect that: %s",err)
46+
t.Errorf("I didn't expect that: %s", err)
5247
}
5348
if processID != expectedProcessID {
5449
t.Errorf("the value should have changed to %s but was %s", expectedProcessID, appGUID)
@@ -62,6 +57,7 @@ func TestV2InstanceWebProcessSSH(t *testing.T) {
6257

6358
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
6459
re := regexp.MustCompile("^/v3")
60+
t.Log("path", r.URL.Path, "method", r.Method)
6561

6662
if re.Match([]byte(r.URL.Path)) && r.Method == http.MethodHead {
6763
w.WriteHeader(http.StatusNotFound)
@@ -73,7 +69,7 @@ func TestV2InstanceWebProcessSSH(t *testing.T) {
7369
apiClient := http.Client{}
7470
processID, err := cfappssh.CheckForV3AvailabilityAndReturnProcessID(appGUID, testServer.URL, "","", apiClient)
7571
if err != nil {
76-
t.Errorf("I didn't expect that: %s",err)
72+
t.Errorf("I didn't expect that: %s", err)
7773
}
7874
if processID != expectedProcessID {
7975
t.Errorf("the value should NOT have changed. expected %s but was %s", expectedProcessID, processID)

0 commit comments

Comments
 (0)