Skip to content

Commit

Permalink
PMM-12913 migrate /v1/AWSInstanceCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Mar 13, 2024
1 parent 9711084 commit 53c8bc1
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 269 deletions.
29 changes: 9 additions & 20 deletions api-tests/server/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ func TestSetup(t *testing.T) {
req.Header.Set("X-Test-Must-Setup", "1")

resp, b := doRequest(t, client, req)
defer resp.Body.Close() //nolint:gosec,errcheck,nolintlint

assert.Equal(t, 200, resp.StatusCode, "response:\n%s", b)
assert.True(t, strings.HasPrefix(string(b), `<!doctype html>`), string(b))
Expand All @@ -135,9 +134,9 @@ func TestSetup(t *testing.T) {
"swagger": 200,
"swagger/": 301,

"v1/server/readyz": 200,
"v1/AWSInstanceCheck": 501, // only POST is expected, other request methods are seen as unimplemented
"v1/server/version": 401, // Grafana authentication required
"v1/server/readyz": 200,
"v1/server/AWSInstance": 501, // It must accept a parameter
"v1/server/version": 401, // Grafana authentication required
}
for path, code := range paths {
path, code := path, code
Expand All @@ -153,7 +152,6 @@ func TestSetup(t *testing.T) {
req.Header.Set("X-Test-Must-Setup", "1")

resp, b := doRequest(t, client, req)
defer resp.Body.Close() //nolint:gosec,errcheck,nolintlint

assert.Equal(t, code, resp.StatusCode, "response:\n%s", b)
if code == 303 {
Expand All @@ -166,20 +164,19 @@ func TestSetup(t *testing.T) {
t.Run("API", func(t *testing.T) {
t.Parallel()

q := make(url.Values)
q.Set("instance_id", "123")
uri := baseURL.ResolveReference(&url.URL{
Path: "v1/AWSInstanceCheck",
Path: "v1/server/AWSInstance",
RawQuery: q.Encode(),
})
t.Logf("URI: %s", uri)
b, err := json.Marshal(server.AWSInstanceCheckBody{
InstanceID: "123",
})
require.NoError(t, err)
req, err := http.NewRequestWithContext(pmmapitests.Context, http.MethodPost, uri.String(), bytes.NewReader(b))
req, err := http.NewRequestWithContext(pmmapitests.Context, http.MethodGet, uri.String(), nil)
require.NoError(t, err)
req.Header.Set("X-Test-Must-Setup", "1")

resp, b := doRequest(t, client, req)
defer resp.Body.Close() //nolint:gosec,errcheck,nolintlint

assert.Equal(t, 200, resp.StatusCode, "response:\n%s", b)
assert.Equal(t, "{}", string(b), "response:\n%s", b)
Expand Down Expand Up @@ -214,7 +211,6 @@ func TestSwagger(t *testing.T) {
require.NoError(t, err)

resp, _ := doRequest(t, http.DefaultClient, req)
defer resp.Body.Close() //nolint:gosec,errcheck,nolintlint

require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode)
Expand All @@ -231,7 +227,6 @@ func TestSwagger(t *testing.T) {
require.NoError(t, err)

resp, _ := doRequest(t, http.DefaultClient, req)
defer resp.Body.Close() //nolint:gosec,errcheck,nolintlint

require.NoError(t, err)
assert.Equal(t, 200, resp.StatusCode)
Expand Down Expand Up @@ -394,7 +389,6 @@ func deleteUser(t *testing.T, userID int) {
require.NoError(t, err)

resp, b := doRequest(t, http.DefaultClient, req)
defer resp.Body.Close() //nolint:gosec,errcheck,nolintlint

require.Equalf(t, http.StatusOK, resp.StatusCode, "failed to delete user, status code: %d, response: %s", resp.StatusCode, b)
}
Expand All @@ -418,9 +412,8 @@ func createUser(t *testing.T, login string) int {
require.NoError(t, err)

req.Header.Set("Content-Type", "application/json; charset=utf-8")

resp, b := doRequest(t, http.DefaultClient, req)
defer resp.Body.Close() //nolint:gosec,errcheck,nolintlint

require.Equalf(t, http.StatusOK, resp.StatusCode, "failed to create user, status code: %d, response: %s", resp.StatusCode, b)

var m map[string]interface{}
Expand All @@ -447,7 +440,6 @@ func setRole(t *testing.T, userID int, role string) {

req.Header.Set("Content-Type", "application/json; charset=utf-8")
resp, b := doRequest(t, http.DefaultClient, req)
defer resp.Body.Close() //nolint:gosec,errcheck,nolintlint

require.Equalf(t, http.StatusOK, resp.StatusCode, "failed to set role for user, response: %s", b)
}
Expand All @@ -463,7 +455,6 @@ func deleteAPIKey(t *testing.T, apiKeyID int) {
require.NoError(t, err)

resp, b := doRequest(t, http.DefaultClient, req)
defer resp.Body.Close() //nolint:gosec,errcheck,nolintlint

require.Equalf(t, http.StatusOK, resp.StatusCode, "failed to delete API Key, status code: %d, response: %s", resp.StatusCode, b)
}
Expand All @@ -487,7 +478,6 @@ func createAPIKeyWithRole(t *testing.T, name, role string) (int, string) {
req.Header.Set("Content-Type", "application/json; charset=utf-8")

resp, b := doRequest(t, http.DefaultClient, req)
defer resp.Body.Close() //nolint:gosec,errcheck,nolintlint

require.Equalf(t, http.StatusOK, resp.StatusCode, "failed to create API key, status code: %d, response: %s", resp.StatusCode, b)

Expand All @@ -503,7 +493,6 @@ func createAPIKeyWithRole(t *testing.T, name, role string) (int, string) {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey))

resp1, b := doRequest(t, http.DefaultClient, req)
defer resp1.Body.Close() //nolint:gosec,errcheck,nolintlint

require.Equalf(t, http.StatusOK, resp1.StatusCode, "failed to get API key, status code: %d, response: %s", resp1.StatusCode, b)

Expand Down
2 changes: 1 addition & 1 deletion api/MIGRATION_TO_V3.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
GET /logz.zip GET /v1/server/logs.zip /logs.zip is now a redirect to /v1/server/logs.zip
GET /v1/version GET /v1/server/version ✅ /v1/version is now a redirect to /v1/server/version
GET /v1/readyz GET /v1/server/readyz ✅ /v1/readyz is now a redirect to /v1/server/readyz
POST /v1/AWSInstanceCheck GET /v1/server/AWSInstance
POST /v1/AWSInstanceCheck GET /v1/server/AWSInstance
POST /v1/leaderHealthCheck GET /v1/server/leaderHealthCheck
POST /v1/settings/Change PUT /v1/server/settings ✅
POST /v1/settings/Get GET /v1/server/settings ✅
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 15 additions & 24 deletions api/server/v1/json/v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,35 +63,29 @@
}
}
},
"/v1/AWSInstanceCheck": {
"/v1/leaderHealthCheck": {
"post": {
"description": "Checks AWS EC2 instance ID.",
"description": "Checks if the instance is the leader in a cluster. Returns an error if the instance isn't the leader.",
"tags": [
"ServerService"
],
"summary": "AWS instance check",
"operationId": "AWSInstanceCheck",
"summary": "Check Leadership",
"operationId": "LeaderHealthCheck",
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"type": "object",
"properties": {
"instance_id": {
"description": "AWS EC2 instance ID (i-1234567890abcdef0).",
"type": "string",
"x-order": 0
}
}
"type": "object"
}
}
],
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"description": "This probe is available without authentication, so it should not contain any data.",
"type": "object"
}
},
Expand Down Expand Up @@ -131,29 +125,26 @@
}
}
},
"/v1/leaderHealthCheck": {
"post": {
"description": "Checks if the instance is the leader in a cluster. Returns an error if the instance isn't the leader.",
"/v1/server/AWSInstance": {
"get": {
"description": "Checks AWS EC2 instance ID.",
"tags": [
"ServerService"
],
"summary": "Check Leadership",
"operationId": "LeaderHealthCheck",
"summary": "AWS instance check",
"operationId": "AWSInstanceCheck",
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"type": "object"
}
"type": "string",
"description": "AWS EC2 instance ID (i-1234567890abcdef0).",
"name": "instance_id",
"in": "query"
}
],
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"description": "This probe is available without authentication, so it should not contain any data.",
"type": "object"
}
},
Expand Down
32 changes: 16 additions & 16 deletions api/server/v1/server.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 53c8bc1

Please sign in to comment.