2021-12-10 17:15:33 +00:00
|
|
|
// Copyright (C) 2022 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
//go:generate go run ./
|
|
|
|
|
|
|
|
import (
|
2022-09-01 16:25:27 +01:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2022-02-17 13:49:07 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"storj.io/common/uuid"
|
2021-12-10 17:15:33 +00:00
|
|
|
"storj.io/storj/private/apigen"
|
2022-02-17 13:49:07 +00:00
|
|
|
"storj.io/storj/satellite/accounting"
|
2021-12-10 17:15:33 +00:00
|
|
|
"storj.io/storj/satellite/console"
|
|
|
|
)
|
|
|
|
|
2023-03-03 14:29:11 +00:00
|
|
|
// main defines the structure of the API and generates its associated frontend and backend code.
|
|
|
|
// These API endpoints are not currently used from inside the Satellite UI.
|
2021-12-10 17:15:33 +00:00
|
|
|
func main() {
|
2022-04-12 17:59:07 +01:00
|
|
|
// definition for REST API
|
2022-01-11 13:20:02 +00:00
|
|
|
a := &apigen.API{
|
2022-03-21 12:15:33 +00:00
|
|
|
Version: "v0",
|
2023-05-17 22:47:58 +01:00
|
|
|
Description: "Interacts with projects",
|
2022-01-11 13:20:02 +00:00
|
|
|
PackageName: "consoleapi",
|
|
|
|
}
|
2021-12-10 17:15:33 +00:00
|
|
|
|
|
|
|
{
|
2022-01-11 13:20:02 +00:00
|
|
|
g := a.Group("ProjectManagement", "projects")
|
2021-12-10 17:15:33 +00:00
|
|
|
|
2022-04-28 16:59:55 +01:00
|
|
|
g.Post("/create", &apigen.Endpoint{
|
|
|
|
Name: "Create new Project",
|
|
|
|
Description: "Creates new Project with given info",
|
|
|
|
MethodName: "GenCreateProject",
|
2022-08-09 22:38:01 +01:00
|
|
|
RequestName: "createProject",
|
2022-04-28 16:59:55 +01:00
|
|
|
Response: &console.Project{},
|
2022-07-14 04:43:33 +01:00
|
|
|
Request: console.ProjectInfo{},
|
2022-04-28 16:59:55 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
g.Patch("/update/{id}", &apigen.Endpoint{
|
|
|
|
Name: "Update Project",
|
|
|
|
Description: "Updates project with given info",
|
|
|
|
MethodName: "GenUpdateProject",
|
2022-08-09 22:38:01 +01:00
|
|
|
RequestName: "updateProject",
|
2022-07-14 04:43:33 +01:00
|
|
|
Response: console.Project{},
|
|
|
|
Request: console.ProjectInfo{},
|
|
|
|
PathParams: []apigen.Param{
|
2022-04-28 16:59:55 +01:00
|
|
|
apigen.NewParam("id", uuid.UUID{}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
g.Delete("/delete/{id}", &apigen.Endpoint{
|
|
|
|
Name: "Delete Project",
|
|
|
|
Description: "Deletes project by id",
|
|
|
|
MethodName: "GenDeleteProject",
|
2022-08-09 22:38:01 +01:00
|
|
|
RequestName: "deleteProject",
|
2022-07-14 04:43:33 +01:00
|
|
|
PathParams: []apigen.Param{
|
2022-04-28 16:59:55 +01:00
|
|
|
apigen.NewParam("id", uuid.UUID{}),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2021-12-10 17:15:33 +00:00
|
|
|
g.Get("/", &apigen.Endpoint{
|
2022-01-11 13:20:02 +00:00
|
|
|
Name: "Get Projects",
|
|
|
|
Description: "Gets all projects user has",
|
2022-02-17 13:49:07 +00:00
|
|
|
MethodName: "GenGetUsersProjects",
|
2022-08-09 22:38:01 +01:00
|
|
|
RequestName: "getProjects",
|
2021-12-10 17:15:33 +00:00
|
|
|
Response: []console.Project{},
|
|
|
|
})
|
2022-01-11 13:20:02 +00:00
|
|
|
|
2022-02-17 13:49:07 +00:00
|
|
|
g.Get("/bucket-rollup", &apigen.Endpoint{
|
apigen: endpoint to get all buckets usage by project ID
Added new endpoint to get all bucket rollups by bucket ID.
Example of response:
vitalii:~/Documents$ ./testapi.sh
HTTP/1.1 200 OK
Content-Type: application/json
Date: Mon, 07 Mar 2022 11:18:55 GMT
Content-Length: 671
[{"projectID":"a9b2b1b6-714a-4c49-99f1-6a53d0852525","bucketName":"demo-bucket","totalStoredData":0.0026272243089674662,"totalSegments":0.05000107166666666,"objectCount":0.03333373083333333,"metadataSize":1.6750359008333334e-9,"repairEgress":0,"getEgress":0,"auditEgress":0,"since":"2022-03-01T11:00:00Z","before":"2022-03-07T11:17:07Z"},{"projectID":"a9b2b1b6-714a-4c49-99f1-6a53d0852525","bucketName":"qwe","totalStoredData":0.000018436725422435552,"totalSegments":0.016667081388888887,"objectCount":0.016667081388888887,"metadataSize":1.933381441111111e-9,"repairEgress":0,"getEgress":0,"auditEgress":0,"since":"2022-03-01T11:00:00Z","before":"2022-03-07T11:17:07Z"}]
Change-Id: I8b04b24dbc67b78be5c309ce542bf03d6f67e65d
2022-03-07 11:20:28 +00:00
|
|
|
Name: "Get Project's Single Bucket Usage",
|
|
|
|
Description: "Gets project's single bucket usage by bucket ID",
|
2022-02-17 13:49:07 +00:00
|
|
|
MethodName: "GenGetSingleBucketUsageRollup",
|
2022-08-09 22:38:01 +01:00
|
|
|
RequestName: "getBucketRollup",
|
2022-07-14 04:43:33 +01:00
|
|
|
Response: accounting.BucketUsageRollup{},
|
|
|
|
QueryParams: []apigen.Param{
|
2022-02-17 13:49:07 +00:00
|
|
|
apigen.NewParam("projectID", uuid.UUID{}),
|
|
|
|
apigen.NewParam("bucket", ""),
|
|
|
|
apigen.NewParam("since", time.Time{}),
|
|
|
|
apigen.NewParam("before", time.Time{}),
|
|
|
|
},
|
|
|
|
})
|
apigen: endpoint to get all buckets usage by project ID
Added new endpoint to get all bucket rollups by bucket ID.
Example of response:
vitalii:~/Documents$ ./testapi.sh
HTTP/1.1 200 OK
Content-Type: application/json
Date: Mon, 07 Mar 2022 11:18:55 GMT
Content-Length: 671
[{"projectID":"a9b2b1b6-714a-4c49-99f1-6a53d0852525","bucketName":"demo-bucket","totalStoredData":0.0026272243089674662,"totalSegments":0.05000107166666666,"objectCount":0.03333373083333333,"metadataSize":1.6750359008333334e-9,"repairEgress":0,"getEgress":0,"auditEgress":0,"since":"2022-03-01T11:00:00Z","before":"2022-03-07T11:17:07Z"},{"projectID":"a9b2b1b6-714a-4c49-99f1-6a53d0852525","bucketName":"qwe","totalStoredData":0.000018436725422435552,"totalSegments":0.016667081388888887,"objectCount":0.016667081388888887,"metadataSize":1.933381441111111e-9,"repairEgress":0,"getEgress":0,"auditEgress":0,"since":"2022-03-01T11:00:00Z","before":"2022-03-07T11:17:07Z"}]
Change-Id: I8b04b24dbc67b78be5c309ce542bf03d6f67e65d
2022-03-07 11:20:28 +00:00
|
|
|
|
|
|
|
g.Get("/bucket-rollups", &apigen.Endpoint{
|
|
|
|
Name: "Get Project's All Buckets Usage",
|
|
|
|
Description: "Gets project's all buckets usage",
|
|
|
|
MethodName: "GenGetBucketUsageRollups",
|
2022-08-09 22:38:01 +01:00
|
|
|
RequestName: "getBucketRollups",
|
apigen: endpoint to get all buckets usage by project ID
Added new endpoint to get all bucket rollups by bucket ID.
Example of response:
vitalii:~/Documents$ ./testapi.sh
HTTP/1.1 200 OK
Content-Type: application/json
Date: Mon, 07 Mar 2022 11:18:55 GMT
Content-Length: 671
[{"projectID":"a9b2b1b6-714a-4c49-99f1-6a53d0852525","bucketName":"demo-bucket","totalStoredData":0.0026272243089674662,"totalSegments":0.05000107166666666,"objectCount":0.03333373083333333,"metadataSize":1.6750359008333334e-9,"repairEgress":0,"getEgress":0,"auditEgress":0,"since":"2022-03-01T11:00:00Z","before":"2022-03-07T11:17:07Z"},{"projectID":"a9b2b1b6-714a-4c49-99f1-6a53d0852525","bucketName":"qwe","totalStoredData":0.000018436725422435552,"totalSegments":0.016667081388888887,"objectCount":0.016667081388888887,"metadataSize":1.933381441111111e-9,"repairEgress":0,"getEgress":0,"auditEgress":0,"since":"2022-03-01T11:00:00Z","before":"2022-03-07T11:17:07Z"}]
Change-Id: I8b04b24dbc67b78be5c309ce542bf03d6f67e65d
2022-03-07 11:20:28 +00:00
|
|
|
Response: []accounting.BucketUsageRollup{},
|
2022-07-14 04:43:33 +01:00
|
|
|
QueryParams: []apigen.Param{
|
apigen: endpoint to get all buckets usage by project ID
Added new endpoint to get all bucket rollups by bucket ID.
Example of response:
vitalii:~/Documents$ ./testapi.sh
HTTP/1.1 200 OK
Content-Type: application/json
Date: Mon, 07 Mar 2022 11:18:55 GMT
Content-Length: 671
[{"projectID":"a9b2b1b6-714a-4c49-99f1-6a53d0852525","bucketName":"demo-bucket","totalStoredData":0.0026272243089674662,"totalSegments":0.05000107166666666,"objectCount":0.03333373083333333,"metadataSize":1.6750359008333334e-9,"repairEgress":0,"getEgress":0,"auditEgress":0,"since":"2022-03-01T11:00:00Z","before":"2022-03-07T11:17:07Z"},{"projectID":"a9b2b1b6-714a-4c49-99f1-6a53d0852525","bucketName":"qwe","totalStoredData":0.000018436725422435552,"totalSegments":0.016667081388888887,"objectCount":0.016667081388888887,"metadataSize":1.933381441111111e-9,"repairEgress":0,"getEgress":0,"auditEgress":0,"since":"2022-03-01T11:00:00Z","before":"2022-03-07T11:17:07Z"}]
Change-Id: I8b04b24dbc67b78be5c309ce542bf03d6f67e65d
2022-03-07 11:20:28 +00:00
|
|
|
apigen.NewParam("projectID", uuid.UUID{}),
|
|
|
|
apigen.NewParam("since", time.Time{}),
|
|
|
|
apigen.NewParam("before", time.Time{}),
|
|
|
|
},
|
|
|
|
})
|
2022-08-31 14:55:28 +01:00
|
|
|
|
|
|
|
g.Get("/apikeys/{projectID}", &apigen.Endpoint{
|
|
|
|
Name: "Get Project's API Keys",
|
|
|
|
Description: "Gets API keys by project ID",
|
|
|
|
MethodName: "GenGetAPIKeys",
|
|
|
|
RequestName: "getAPIKeys",
|
|
|
|
Response: console.APIKeyPage{},
|
|
|
|
PathParams: []apigen.Param{
|
|
|
|
apigen.NewParam("projectID", uuid.UUID{}),
|
|
|
|
},
|
|
|
|
QueryParams: []apigen.Param{
|
|
|
|
apigen.NewParam("search", ""),
|
|
|
|
apigen.NewParam("limit", uint(0)),
|
|
|
|
apigen.NewParam("page", uint(0)),
|
|
|
|
apigen.NewParam("order", console.APIKeyOrder(0)),
|
|
|
|
apigen.NewParam("orderDirection", console.OrderDirection(0)),
|
|
|
|
},
|
|
|
|
})
|
2021-12-10 17:15:33 +00:00
|
|
|
}
|
2022-01-11 13:20:02 +00:00
|
|
|
|
2022-05-06 12:29:59 +01:00
|
|
|
{
|
|
|
|
g := a.Group("APIKeyManagement", "apikeys")
|
|
|
|
|
|
|
|
g.Post("/create", &apigen.Endpoint{
|
|
|
|
Name: "Create new macaroon API key",
|
|
|
|
Description: "Creates new macaroon API key with given info",
|
|
|
|
MethodName: "GenCreateAPIKey",
|
2022-08-09 22:38:01 +01:00
|
|
|
RequestName: "createAPIKey",
|
2022-07-14 04:43:33 +01:00
|
|
|
Response: console.CreateAPIKeyResponse{},
|
|
|
|
Request: console.CreateAPIKeyRequest{},
|
2022-05-06 12:29:59 +01:00
|
|
|
})
|
2022-08-31 14:55:28 +01:00
|
|
|
|
|
|
|
g.Delete("/delete/{id}", &apigen.Endpoint{
|
|
|
|
Name: "Delete API Key",
|
|
|
|
Description: "Deletes macaroon API key by id",
|
|
|
|
MethodName: "GenDeleteAPIKey",
|
|
|
|
RequestName: "deleteAPIKey",
|
|
|
|
PathParams: []apigen.Param{
|
|
|
|
apigen.NewParam("id", uuid.UUID{}),
|
|
|
|
},
|
|
|
|
})
|
2022-05-06 12:29:59 +01:00
|
|
|
}
|
|
|
|
|
2022-05-27 15:31:28 +01:00
|
|
|
{
|
|
|
|
g := a.Group("UserManagement", "users")
|
|
|
|
|
|
|
|
g.Get("/", &apigen.Endpoint{
|
|
|
|
Name: "Get User",
|
|
|
|
Description: "Gets User by request context",
|
|
|
|
MethodName: "GenGetUser",
|
2022-08-09 22:38:01 +01:00
|
|
|
RequestName: "getUser",
|
2022-07-14 04:43:33 +01:00
|
|
|
Response: console.ResponseUser{},
|
2022-05-27 15:31:28 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-09-01 16:25:27 +01:00
|
|
|
modroot := findModuleRootDir()
|
|
|
|
a.MustWriteGo(filepath.Join(modroot, "satellite", "console", "consoleweb", "consoleapi", "api.gen.go"))
|
|
|
|
a.MustWriteTS(filepath.Join(modroot, "web", "satellite", "src", "api", a.Version+".gen.ts"))
|
2023-05-17 22:47:58 +01:00
|
|
|
a.MustWriteDocs(filepath.Join(modroot, "satellite", "console", "consoleweb", "consoleapi", "apidocs.gen.md"))
|
2022-09-01 16:25:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func findModuleRootDir() string {
|
|
|
|
dir, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
panic("unable to find current working directory")
|
|
|
|
}
|
|
|
|
start := dir
|
|
|
|
|
|
|
|
for i := 0; i < 100; i++ {
|
|
|
|
if fileExists(filepath.Join(dir, "go.mod")) {
|
|
|
|
return dir
|
|
|
|
}
|
|
|
|
next := filepath.Dir(dir)
|
|
|
|
if next == dir {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
dir = next
|
|
|
|
}
|
|
|
|
|
|
|
|
panic("unable to find go.mod starting from " + start)
|
|
|
|
}
|
|
|
|
|
|
|
|
func fileExists(path string) bool {
|
|
|
|
_, err := os.Stat(path)
|
|
|
|
return err == nil
|
2021-12-10 17:15:33 +00:00
|
|
|
}
|