Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (m *Manager) registerManagement(request []byte) ([]byte, error) {
Routes: []struct {
Method string `json:"method"`
Path string `json:"path"`
}{{Method: "POST", Path: "/plugins/" + pluginName + "/quota"}},
}{{Method: "POST", Path: "/plugins/" + pluginName + "/quota-usage"}},
Resources: []struct {
Path string `json:"path"`
Menu string `json:"menu"`
Expand Down
2 changes: 1 addition & 1 deletion internal/plugin/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (m *Manager) HandleManagement(ctx context.Context, req pluginapi.Management
if req.Method == http.MethodGet && req.Path == "/v0/resource/plugins/"+pluginName+"/quota" {
return pluginapi.ManagementResponse{Headers: http.Header{"Content-Type": []string{"text/html; charset=utf-8"}}, Body: []byte(resources.QuotaPage)}, nil
}
if req.Method != http.MethodPost || req.Path != "/v0/management/plugins/"+pluginName+"/quota" {
if req.Method != http.MethodPost || req.Path != "/v0/management/plugins/"+pluginName+"/quota-usage" {
return pluginapi.ManagementResponse{StatusCode: http.StatusNotFound, Body: []byte(`{"error":"not found"}`)}, nil
}
var body quotaRequest
Expand Down
10 changes: 5 additions & 5 deletions internal/plugin/quota_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestManagementRegistration(t *testing.T) {
Resources []struct{ Path, Menu, Description string } `json:"resources"`
}
decodeResult(t, mustHandle(t, m, pluginabi.MethodManagementRegister, []byte(`{}`)), &got)
if len(got.Routes) != 1 || got.Routes[0].Method != http.MethodPost || got.Routes[0].Path != "/plugins/"+pluginName+"/quota" {
if len(got.Routes) != 1 || got.Routes[0].Method != http.MethodPost || got.Routes[0].Path != "/plugins/"+pluginName+"/quota-usage" {
t.Fatalf("routes = %+v", got.Routes)
}
if len(got.Resources) != 1 || got.Resources[0].Path != "/quota" || got.Resources[0].Menu != "OpenCode Go Quota" {
Expand All @@ -39,7 +39,7 @@ func TestQuotaListDoesNotCallHost(t *testing.T) {
m := NewManager(NewHostBridge(f.call))
m.cfg = config.Config{APIKeys: []config.APIKey{{Value: "quota-key-a"}, {Value: "quota-key-b"}}}
var got quotaList
resp, err := m.HandleManagement(context.Background(), pluginapi.ManagementRequest{Method: http.MethodPost, Path: "/v0/management/plugins/" + pluginName + "/quota", Body: []byte(`{}`)})
resp, err := m.HandleManagement(context.Background(), pluginapi.ManagementRequest{Method: http.MethodPost, Path: "/v0/management/plugins/" + pluginName + "/quota-usage", Body: []byte(`{}`)})
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestQuotaRefresh(t *testing.T) {
m := NewManager(NewHostBridge(f.call))
m.cfg = config.Config{BaseURL: "https://quota.test/v1/", RequestTimeout: config.DefaultRequestTimeout, APIKeys: []config.APIKey{{Value: key}}}
id, _ := quotaIdentity(key)
resp, err := m.HandleManagement(context.Background(), pluginapi.ManagementRequest{Method: http.MethodPost, Path: "/v0/management/plugins/" + pluginName + "/quota", Body: []byte(`{"key_id":"` + id + `"}`)})
resp, err := m.HandleManagement(context.Background(), pluginapi.ManagementRequest{Method: http.MethodPost, Path: "/v0/management/plugins/" + pluginName + "/quota-usage", Body: []byte(`{"key_id":"` + id + `"}`)})
if err != nil {
t.Fatal(err)
}
Expand All @@ -92,7 +92,7 @@ func TestQuotaUnknownKeyAndResource(t *testing.T) {
m := NewManager(NewHostBridge(f.call))
m.cfg = config.Config{APIKeys: []config.APIKey{{Value: key}}}
unknown := "opencode-go-key-unknown"
resp, err := m.HandleManagement(context.Background(), pluginapi.ManagementRequest{Method: http.MethodPost, Path: "/v0/management/plugins/" + pluginName + "/quota", Body: []byte(`{"key_id":"` + unknown + `"}`)})
resp, err := m.HandleManagement(context.Background(), pluginapi.ManagementRequest{Method: http.MethodPost, Path: "/v0/management/plugins/" + pluginName + "/quota-usage", Body: []byte(`{"key_id":"` + unknown + `"}`)})
if err != nil || resp.StatusCode != http.StatusNotFound || strings.Contains(string(resp.Body), key) || strings.Contains(string(resp.Body), unknown) || len(f.callsOf(pluginabi.MethodHostHTTPDo)) != 0 {
t.Fatalf("unknown response = %+v err=%v calls=%v", resp, err, f.callsOf(pluginabi.MethodHostHTTPDo))
}
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestQuotaErrorsAreRedacted(t *testing.T) {
f := &fakeCaller{responder: responder}
m := NewManager(NewHostBridge(f.call))
m.cfg = config.Config{BaseURL: "https://quota.test/v1", RequestTimeout: config.DefaultRequestTimeout, APIKeys: []config.APIKey{{Value: key}}}
resp, err := m.HandleManagement(context.Background(), pluginapi.ManagementRequest{Method: http.MethodPost, Path: "/v0/management/plugins/" + pluginName + "/quota", Body: []byte(`{"key_id":"` + id + `"}`)})
resp, err := m.HandleManagement(context.Background(), pluginapi.ManagementRequest{Method: http.MethodPost, Path: "/v0/management/plugins/" + pluginName + "/quota-usage", Body: []byte(`{"key_id":"` + id + `"}`)})
if err != nil || resp.StatusCode != http.StatusBadGateway || strings.Contains(string(resp.Body), key) || strings.Contains(string(resp.Body), "upstream body") {
t.Fatalf("response = %+v err=%v", resp, err)
}
Expand Down
2 changes: 1 addition & 1 deletion resources/quota_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<script>
(() => {
const app = document.getElementById("app");
const endpoint = "/v0/management/plugins/opencode-go-cliproxyapi/quota";
const endpoint = "/v0/management/plugins/opencode-go-cliproxyapi/quota-usage";
const storageKey = "opencode-go-cliproxyapi:quota";
const values = new Map();
const fetchedAt = new Map();
Expand Down