feat: add test database setup and usage helpers
- Introduced a new test file for setting up an in-memory SQLite database for testing purposes. - Added helper functions for seeding test data, including users, plans, subscriptions, and wallet transactions. - Implemented usage helpers to load user video counts and storage usage. - Created user payload struct and functions to build user payloads with preferences and wallet balance. - Refactored gRPC server setup to include new services and handlers. - Updated proto files to simplify service definitions by removing redundant service prefixes.
This commit is contained in:
186
proto/agent/v1/woodpecker.proto
Normal file
186
proto/agent/v1/woodpecker.proto
Normal file
@@ -0,0 +1,186 @@
|
||||
// Copyright 2021 Woodpecker Authors
|
||||
// Copyright 2011 Drone.IO Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
syntax = "proto3";
|
||||
|
||||
option go_package = "go.woodpecker-ci.org/woodpecker/v3/rpc/proto";
|
||||
package proto;
|
||||
|
||||
// !IMPORTANT!
|
||||
// Increased Version in version.go by 1 if you change something here!
|
||||
// !IMPORTANT!
|
||||
|
||||
// Woodpecker Server Service
|
||||
service Woodpecker {
|
||||
rpc Version (Empty) returns (VersionResponse) {}
|
||||
rpc Next (NextRequest) returns (NextResponse) {}
|
||||
rpc Init (InitRequest) returns (Empty) {}
|
||||
rpc Wait (WaitRequest) returns (WaitResponse) {}
|
||||
rpc Done (DoneRequest) returns (Empty) {}
|
||||
rpc Extend (ExtendRequest) returns (Empty) {}
|
||||
rpc Update (UpdateRequest) returns (Empty) {}
|
||||
rpc Log (LogRequest) returns (Empty) {}
|
||||
rpc RegisterAgent (RegisterAgentRequest) returns (RegisterAgentResponse) {}
|
||||
rpc UnregisterAgent (Empty) returns (Empty) {}
|
||||
rpc ReportHealth (ReportHealthRequest) returns (Empty) {}
|
||||
|
||||
// New Streaming RPCs
|
||||
rpc StreamJobs (StreamOptions) returns (stream Workflow) {}
|
||||
rpc SubmitStatus (stream StatusUpdate) returns (Empty) {}
|
||||
}
|
||||
|
||||
//
|
||||
// Basic Types
|
||||
//
|
||||
|
||||
message StepState {
|
||||
string step_uuid = 1;
|
||||
int64 started = 2;
|
||||
int64 finished = 3;
|
||||
bool exited = 4;
|
||||
int32 exit_code = 5;
|
||||
string error = 6;
|
||||
bool canceled = 7;
|
||||
}
|
||||
|
||||
message WorkflowState {
|
||||
int64 started = 1;
|
||||
int64 finished = 2;
|
||||
string error = 3;
|
||||
bool canceled = 4;
|
||||
}
|
||||
|
||||
message LogEntry {
|
||||
string step_uuid = 1;
|
||||
int64 time = 2;
|
||||
int32 line = 3;
|
||||
int32 type = 4; // 0 = stdout, 1 = stderr, 2 = exit-code, 3 = metadata, 4 = progress
|
||||
bytes data = 5;
|
||||
}
|
||||
|
||||
message Filter {
|
||||
map<string, string> labels = 1;
|
||||
}
|
||||
|
||||
message Workflow {
|
||||
string id = 1;
|
||||
int64 timeout = 2;
|
||||
bytes payload = 3;
|
||||
bool cancel = 4;
|
||||
}
|
||||
|
||||
//
|
||||
// Request types
|
||||
//
|
||||
|
||||
message NextRequest {
|
||||
Filter filter = 1;
|
||||
}
|
||||
|
||||
message InitRequest {
|
||||
string id = 1;
|
||||
WorkflowState state = 2;
|
||||
}
|
||||
|
||||
message WaitRequest {
|
||||
string id = 1;
|
||||
}
|
||||
|
||||
message DoneRequest {
|
||||
string id = 1;
|
||||
WorkflowState state = 2;
|
||||
}
|
||||
|
||||
message ExtendRequest {
|
||||
string id = 1;
|
||||
}
|
||||
|
||||
message UpdateRequest {
|
||||
string id = 1;
|
||||
StepState state = 2;
|
||||
}
|
||||
|
||||
message LogRequest {
|
||||
repeated LogEntry logEntries = 1;
|
||||
}
|
||||
|
||||
message Empty {
|
||||
}
|
||||
|
||||
message ReportHealthRequest {
|
||||
string status = 1;
|
||||
}
|
||||
|
||||
message AgentInfo {
|
||||
string platform = 1;
|
||||
int32 capacity = 2;
|
||||
string backend = 3;
|
||||
string version = 4;
|
||||
map<string, string> customLabels = 5;
|
||||
}
|
||||
|
||||
message RegisterAgentRequest {
|
||||
AgentInfo info = 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Response types
|
||||
//
|
||||
|
||||
message VersionResponse {
|
||||
int32 grpc_version = 1;
|
||||
string server_version = 2;
|
||||
}
|
||||
|
||||
message NextResponse {
|
||||
Workflow workflow = 1;
|
||||
}
|
||||
|
||||
message RegisterAgentResponse {
|
||||
string agent_id = 1;
|
||||
}
|
||||
|
||||
message WaitResponse {
|
||||
bool canceled = 1;
|
||||
};
|
||||
|
||||
// Woodpecker auth service is a simple service to authenticate agents and acquire a token
|
||||
|
||||
service WoodpeckerAuth {
|
||||
rpc Auth (AuthRequest) returns (AuthResponse) {}
|
||||
}
|
||||
|
||||
message AuthRequest {
|
||||
string agent_token = 1;
|
||||
string agent_id = 2;
|
||||
string hostname = 3;
|
||||
}
|
||||
|
||||
message AuthResponse {
|
||||
string status = 1;
|
||||
string agent_id = 2;
|
||||
string access_token = 3;
|
||||
}
|
||||
|
||||
message StreamOptions {
|
||||
Filter filter = 1;
|
||||
}
|
||||
|
||||
message StatusUpdate {
|
||||
string step_uuid = 1;
|
||||
int64 time = 2;
|
||||
int32 type = 3; // 0=stdout, 1=stderr, 2=exit-code, 3=metadata, 4=progress, 5=system-resource
|
||||
bytes data = 4;
|
||||
}
|
||||
@@ -6,24 +6,21 @@ option go_package = "stream.api/internal/gen/proto/app/v1;appv1";
|
||||
import "google/protobuf/wrappers.proto";
|
||||
import "app/v1/common.proto";
|
||||
|
||||
service AccountService {
|
||||
service Account {
|
||||
rpc GetMe(GetMeRequest) returns (GetMeResponse);
|
||||
rpc UpdateMe(UpdateMeRequest) returns (UpdateMeResponse);
|
||||
rpc DeleteMe(DeleteMeRequest) returns (MessageResponse);
|
||||
rpc ClearMyData(ClearMyDataRequest) returns (MessageResponse);
|
||||
rpc GetUserById (google.protobuf.StringValue) returns (User) {}
|
||||
}
|
||||
|
||||
service PreferencesService {
|
||||
rpc GetPreferences(GetPreferencesRequest) returns (GetPreferencesResponse);
|
||||
rpc UpdatePreferences(UpdatePreferencesRequest) returns (UpdatePreferencesResponse);
|
||||
}
|
||||
|
||||
service UsageService {
|
||||
service Usage {
|
||||
rpc GetUsage(GetUsageRequest) returns (GetUsageResponse);
|
||||
}
|
||||
|
||||
service NotificationsService {
|
||||
service Notifications {
|
||||
rpc ListNotifications(ListNotificationsRequest) returns (ListNotificationsResponse);
|
||||
rpc MarkNotificationRead(MarkNotificationReadRequest) returns (MessageResponse);
|
||||
rpc MarkAllNotificationsRead(MarkAllNotificationsReadRequest) returns (MessageResponse);
|
||||
|
||||
@@ -6,7 +6,7 @@ option go_package = "stream.api/internal/gen/proto/app/v1;appv1";
|
||||
|
||||
import "app/v1/common.proto";
|
||||
|
||||
service AdminService {
|
||||
service Admin {
|
||||
rpc GetAdminDashboard(GetAdminDashboardRequest) returns (GetAdminDashboardResponse);
|
||||
rpc ListAdminUsers(ListAdminUsersRequest) returns (ListAdminUsersResponse);
|
||||
rpc GetAdminUser(GetAdminUserRequest) returns (GetAdminUserResponse);
|
||||
|
||||
@@ -6,7 +6,7 @@ option go_package = "stream.api/internal/gen/proto/app/v1;appv1";
|
||||
|
||||
import "app/v1/common.proto";
|
||||
|
||||
service AuthService {
|
||||
service Auth {
|
||||
rpc Login(LoginRequest) returns (LoginResponse);
|
||||
rpc Register(RegisterRequest) returns (RegisterResponse);
|
||||
rpc Logout(LogoutRequest) returns (MessageResponse);
|
||||
|
||||
@@ -6,27 +6,27 @@ option go_package = "stream.api/internal/gen/proto/app/v1;appv1";
|
||||
|
||||
import "app/v1/common.proto";
|
||||
|
||||
service DomainsService {
|
||||
service Domains {
|
||||
rpc ListDomains(ListDomainsRequest) returns (ListDomainsResponse);
|
||||
rpc CreateDomain(CreateDomainRequest) returns (CreateDomainResponse);
|
||||
rpc DeleteDomain(DeleteDomainRequest) returns (MessageResponse);
|
||||
}
|
||||
|
||||
service AdTemplatesService {
|
||||
service AdTemplates {
|
||||
rpc ListAdTemplates(ListAdTemplatesRequest) returns (ListAdTemplatesResponse);
|
||||
rpc CreateAdTemplate(CreateAdTemplateRequest) returns (CreateAdTemplateResponse);
|
||||
rpc UpdateAdTemplate(UpdateAdTemplateRequest) returns (UpdateAdTemplateResponse);
|
||||
rpc DeleteAdTemplate(DeleteAdTemplateRequest) returns (MessageResponse);
|
||||
}
|
||||
|
||||
service PlayerConfigsService {
|
||||
service PlayerConfigs {
|
||||
rpc ListPlayerConfigs(ListPlayerConfigsRequest) returns (ListPlayerConfigsResponse);
|
||||
rpc CreatePlayerConfig(CreatePlayerConfigRequest) returns (CreatePlayerConfigResponse);
|
||||
rpc UpdatePlayerConfig(UpdatePlayerConfigRequest) returns (UpdatePlayerConfigResponse);
|
||||
rpc DeletePlayerConfig(DeletePlayerConfigRequest) returns (MessageResponse);
|
||||
}
|
||||
|
||||
service PlansService {
|
||||
service Plans {
|
||||
rpc ListPlans(ListPlansRequest) returns (ListPlansResponse);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ option go_package = "stream.api/internal/gen/proto/app/v1;appv1";
|
||||
|
||||
import "app/v1/common.proto";
|
||||
|
||||
service PaymentsService {
|
||||
service Payments {
|
||||
rpc CreatePayment(CreatePaymentRequest) returns (CreatePaymentResponse);
|
||||
rpc ListPaymentHistory(ListPaymentHistoryRequest) returns (ListPaymentHistoryResponse);
|
||||
rpc TopupWallet(TopupWalletRequest) returns (TopupWalletResponse);
|
||||
|
||||
@@ -6,7 +6,7 @@ option go_package = "stream.api/internal/gen/proto/app/v1;appv1";
|
||||
|
||||
import "app/v1/common.proto";
|
||||
|
||||
service VideosService {
|
||||
service Videos {
|
||||
rpc GetUploadUrl(GetUploadUrlRequest) returns (GetUploadUrlResponse);
|
||||
rpc CreateVideo(CreateVideoRequest) returns (CreateVideoResponse);
|
||||
rpc ListVideos(ListVideosRequest) returns (ListVideosResponse);
|
||||
|
||||
Reference in New Issue
Block a user