diff --git a/pkg/spore-drive/clients/js/gen/config/v1/config_connect.ts b/pkg/spore-drive/clients/js/gen/config/v1/config_connect.ts index 06eb4162..abd89d74 100644 --- a/pkg/spore-drive/clients/js/gen/config/v1/config_connect.ts +++ b/pkg/spore-drive/clients/js/gen/config/v1/config_connect.ts @@ -14,6 +14,15 @@ import { MethodKind } from "@bufbuild/protobuf"; export const ConfigService = { typeName: "config.v1.ConfigService", methods: { + /** + * @generated from rpc config.v1.ConfigService.New + */ + new: { + name: "New", + I: Empty, + O: Config, + kind: MethodKind.Unary, + }, /** * @generated from rpc config.v1.ConfigService.Load */ diff --git a/pkg/spore-drive/clients/js/src/Config.ts b/pkg/spore-drive/clients/js/src/Config.ts index 6262d2d4..96d68d9f 100644 --- a/pkg/spore-drive/clients/js/src/Config.ts +++ b/pkg/spore-drive/clients/js/src/Config.ts @@ -7,23 +7,38 @@ import { StringSlice, BundleConfig, Bundle, + SourceUpload } from "../gen/config/v1/config_pb"; import { RPCClient } from "./ConfigClient"; +async function* uploadAsyncIterator(stream: ReadableStream): AsyncIterable { + yield new SourceUpload({data:{case:"path", value:"/"}}); + + for await (const chunk of stream) { + yield new SourceUpload({data: {case:"chunk", value:chunk}}); + } +} + // Main Config class export class Config { private client: RPCClient; - private source: Source; + private source?: string | ReadableStream; private config?: ConfigMessage; - constructor(client: RPCClient, source: Source) { - this.client = client; + constructor(url: string, source?: string | ReadableStream) { + this.client = new RPCClient(url); this.source = source; } - async load(): Promise { - this.config = await this.client.load(this.source); + async init(): Promise { + if (typeof this.source === 'string') { + this.config = await this.client.load(new Source({ root: this.source, path: "/" })) + } else if (this.source instanceof ReadableStream) { + this.config = await this.client.upload(uploadAsyncIterator(this.source)) + } else { + this.config = await this.client.new(); + } } async free(): Promise { diff --git a/pkg/spore-drive/clients/js/src/ConfigClient.ts b/pkg/spore-drive/clients/js/src/ConfigClient.ts index 4138e765..08196bcc 100644 --- a/pkg/spore-drive/clients/js/src/ConfigClient.ts +++ b/pkg/spore-drive/clients/js/src/ConfigClient.ts @@ -25,6 +25,10 @@ export class RPCClient { this.client = createPromiseClient(ConfigService, transport); } + async new(): Promise { + return await this.client.new(new Empty()); + } + async load(source: Source): Promise { return await this.client.load(source); } diff --git a/pkg/spore-drive/clients/js/src/Drive.ts b/pkg/spore-drive/clients/js/src/Drive.ts index ae3a57f9..58614c03 100644 --- a/pkg/spore-drive/clients/js/src/Drive.ts +++ b/pkg/spore-drive/clients/js/src/Drive.ts @@ -40,16 +40,20 @@ export { TauBinarySource, TauLatest, TauVersion, TauUrl, TauPath }; export class Drive { private client: RPCClient; private drive?: DriveMessage; + private config: Config; + private tau?: TauBinarySource; - constructor(client: RPCClient) { - this.client = client; + constructor(url: string,config: Config,tau?: TauBinarySource) { + this.client = new RPCClient(url); + this.config = config; + this.tau = tau; } - async init(config: Config, tau?: TauBinarySource): Promise { + async init(): Promise { this.drive = await this.client.new( new DriveRequest({ - config: new ConfigMessage({ id: config.id() }), - tau: tau, + config: new ConfigMessage({ id: this.config.id() }), + tau: this.tau, }) ); } diff --git a/pkg/spore-drive/clients/js/src/config.test.ts b/pkg/spore-drive/clients/js/src/config.test.ts index 60244b0e..a0fcbcfd 100644 --- a/pkg/spore-drive/clients/js/src/config.test.ts +++ b/pkg/spore-drive/clients/js/src/config.test.ts @@ -8,6 +8,8 @@ import * as os from "os"; import { mkdtemp, rm } from "fs/promises"; import * as unzipper from "unzipper"; import * as yaml from "js-yaml"; +import { Readable } from 'stream'; + export const createConfig = async (config: Config) => { // Set Cloud Domain @@ -78,7 +80,6 @@ export const createConfig = async (config: Config) => { describe("Config Class Integration Tests", () => { let client: RPCClient; let config: Config; - let source: Source; let rpcUrl: string; let mockServerProcess: ChildProcess; let tempDir: string; @@ -117,9 +118,8 @@ describe("Config Class Integration Tests", () => { beforeEach(async () => { tempDir = await mkdtemp(path.join(os.tmpdir(), "cloud-")); // Create a temporary directory - source = new Source({ root: tempDir, path: "/" }); - config = new Config(client, source); - await config.load(); + config = new Config(rpcUrl, tempDir); + await config.init(); }); afterEach(async () => { @@ -174,7 +174,7 @@ describe("Config Class Integration Tests", () => { expect(result).toBeDefined(); }); - it("should download configuration bundle and verify it", async () => { + it("should download configuration bundle and verify it locally and through upload", async () => { await createConfig(config); const bundleIterator = await config.Download(); @@ -219,6 +219,11 @@ describe("Config Class Integration Tests", () => { const yamlObject: any = yaml.load(yamlContent.toString()); expect(yamlObject.domain.root).toBe("test.com"); + + const config_from_zip = new Config(rpcUrl, Readable.toWeb(fs.createReadStream(zipPath))); + await config_from_zip.init(); + expect(await config_from_zip.Cloud().Domain().Root().Get()).toBe("test.com"); + await config_from_zip.free() }); it("should set and get Swarm Key", async () => { diff --git a/pkg/spore-drive/clients/js/src/drive.test.ts b/pkg/spore-drive/clients/js/src/drive.test.ts index fe629a74..980a1906 100644 --- a/pkg/spore-drive/clients/js/src/drive.test.ts +++ b/pkg/spore-drive/clients/js/src/drive.test.ts @@ -111,10 +111,8 @@ export const createConfig = async ( describe("Drive Class Integration Tests", () => { let mock_client: PromiseClient; - let config_client: ConfigClient; - let drive_client: DriveClient; let drive: Drive; - let source: Source; + let config :Config; let rpcUrl: string; let mockServerProcess: ChildProcess; let tempDir: string; @@ -147,8 +145,6 @@ describe("Drive Class Integration Tests", () => { }); mock_client = createPromiseClient(MockSSHService, transport); - config_client = new ConfigClient(rpcUrl); - drive_client = new DriveClient(rpcUrl); touchFile("/tmp/faketau") }); @@ -162,19 +158,21 @@ describe("Drive Class Integration Tests", () => { beforeEach(async () => { tempDir = await mkdtemp(path.join(os.tmpdir(), "cloud-")); // Create a temporary directory - source = new Source({ root: tempDir, path: "/" }); - const config = new Config(config_client, source); - drive = new Drive(drive_client); - await config.load(); + config = new Config(rpcUrl, tempDir); + await config.init(); await createConfig(mock_client, config); - await drive.init(config, TauPath("/tmp/faketau")); - await config.free(); + + drive = new Drive(rpcUrl,config, TauPath("/tmp/faketau")); + await drive.init(); }); afterEach(async () => { await mock_client.free(new Hostname({ name: "host1" })); await mock_client.free(new Hostname({ name: "host2" })); + await config.free(); + await drive.free(); + if (tempDir) { await rm(tempDir, { recursive: true, force: true }); } diff --git a/pkg/spore-drive/config/service/serve.go b/pkg/spore-drive/config/service/serve.go index 36ce307f..9eb62357 100644 --- a/pkg/spore-drive/config/service/serve.go +++ b/pkg/spore-drive/config/service/serve.go @@ -127,6 +127,15 @@ func (s *Service) Upload(ctx context.Context, stream *connect.ClientStream[pb.So return connect.NewResponse(&pb.Config{Id: c.id}), nil } +func (s *Service) New(context.Context, *connect.Request[pb.Empty]) (*connect.Response[pb.Config], error) { + cnf, err := s.newConfig(afero.NewMemMapFs(), "") + if err != nil { + return nil, fmt.Errorf("failed to create config: %w", err) + } + + return connect.NewResponse(&pb.Config{Id: cnf.id}), nil +} + func (s *Service) Load(ctx context.Context, req *connect.Request[pb.Source]) (*connect.Response[pb.Config], error) { root := req.Msg.GetRoot() if root == "" { diff --git a/pkg/spore-drive/proto/config/v1/config.proto b/pkg/spore-drive/proto/config/v1/config.proto index 28b9909c..e16a97d5 100644 --- a/pkg/spore-drive/proto/config/v1/config.proto +++ b/pkg/spore-drive/proto/config/v1/config.proto @@ -296,6 +296,7 @@ message Port { // Service service ConfigService { + rpc New(Empty) returns (Config); rpc Load(Source) returns (Config); rpc Upload(stream SourceUpload) returns (Config); rpc Download(BundleConfig) returns (stream Bundle); diff --git a/pkg/spore-drive/proto/gen/config/v1/config.pb.go b/pkg/spore-drive/proto/gen/config/v1/config.pb.go index 1025000d..5617fb70 100644 --- a/pkg/spore-drive/proto/gen/config/v1/config.pb.go +++ b/pkg/spore-drive/proto/gen/config/v1/config.pb.go @@ -3586,37 +3586,40 @@ var file_config_v1_config_proto_rawDesc = []byte{ 0x04, 0x0a, 0x02, 0x6f, 0x70, 0x2a, 0x2c, 0x0a, 0x0a, 0x42, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0e, 0x0a, 0x0a, 0x42, 0x55, 0x4e, 0x44, 0x4c, 0x45, 0x5f, 0x5a, 0x49, 0x50, 0x10, 0x00, 0x12, 0x0e, 0x0a, 0x0a, 0x42, 0x55, 0x4e, 0x44, 0x4c, 0x45, 0x5f, 0x54, 0x41, - 0x52, 0x10, 0x01, 0x32, 0xb3, 0x02, 0x0a, 0x0d, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x53, 0x65, - 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x2c, 0x0a, 0x04, 0x4c, 0x6f, 0x61, 0x64, 0x12, 0x11, 0x2e, - 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, - 0x1a, 0x11, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, - 0x66, 0x69, 0x67, 0x12, 0x36, 0x0a, 0x06, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x17, 0x2e, - 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, - 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x1a, 0x11, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, - 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x28, 0x01, 0x12, 0x38, 0x0a, 0x08, 0x44, - 0x6f, 0x77, 0x6e, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x17, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, - 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, - 0x1a, 0x11, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x75, 0x6e, - 0x64, 0x6c, 0x65, 0x30, 0x01, 0x12, 0x2d, 0x0a, 0x06, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x12, - 0x11, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0x1a, 0x10, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x45, - 0x6d, 0x70, 0x74, 0x79, 0x12, 0x2b, 0x0a, 0x04, 0x46, 0x72, 0x65, 0x65, 0x12, 0x11, 0x2e, 0x63, - 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x1a, - 0x10, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6d, 0x70, 0x74, - 0x79, 0x12, 0x26, 0x0a, 0x02, 0x44, 0x6f, 0x12, 0x0d, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, - 0x2e, 0x76, 0x31, 0x2e, 0x4f, 0x70, 0x1a, 0x11, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, - 0x76, 0x31, 0x2e, 0x52, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x42, 0xa6, 0x01, 0x0a, 0x0d, 0x63, 0x6f, - 0x6d, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x43, 0x6f, 0x6e, - 0x66, 0x69, 0x67, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x43, 0x67, 0x69, 0x74, 0x68, - 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x74, 0x61, 0x75, 0x62, 0x79, 0x74, 0x65, 0x2f, 0x74, - 0x61, 0x75, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x73, 0x70, 0x6f, 0x72, 0x65, 0x2d, 0x64, 0x72, 0x69, - 0x76, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x63, 0x6f, 0x6e, - 0x66, 0x69, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x76, 0x31, 0xa2, - 0x02, 0x03, 0x43, 0x58, 0x58, 0xaa, 0x02, 0x09, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x56, - 0x31, 0xca, 0x02, 0x09, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x15, - 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, - 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x0a, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x3a, 0x3a, - 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x10, 0x01, 0x32, 0xdf, 0x02, 0x0a, 0x0d, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x2a, 0x0a, 0x03, 0x4e, 0x65, 0x77, 0x12, 0x10, 0x2e, 0x63, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x11, + 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, + 0x67, 0x12, 0x2c, 0x0a, 0x04, 0x4c, 0x6f, 0x61, 0x64, 0x12, 0x11, 0x2e, 0x63, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x1a, 0x11, 0x2e, 0x63, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, + 0x36, 0x0a, 0x06, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x17, 0x2e, 0x63, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x55, 0x70, 0x6c, 0x6f, + 0x61, 0x64, 0x1a, 0x11, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x28, 0x01, 0x12, 0x38, 0x0a, 0x08, 0x44, 0x6f, 0x77, 0x6e, 0x6c, + 0x6f, 0x61, 0x64, 0x12, 0x17, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x42, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x1a, 0x11, 0x2e, 0x63, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x42, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x30, + 0x01, 0x12, 0x2d, 0x0a, 0x06, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x12, 0x11, 0x2e, 0x63, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x1a, 0x10, + 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, + 0x12, 0x2b, 0x0a, 0x04, 0x46, 0x72, 0x65, 0x65, 0x12, 0x11, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, + 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x1a, 0x10, 0x2e, 0x63, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x26, 0x0a, + 0x02, 0x44, 0x6f, 0x12, 0x0d, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, + 0x4f, 0x70, 0x1a, 0x11, 0x2e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x52, + 0x65, 0x74, 0x75, 0x72, 0x6e, 0x42, 0xa6, 0x01, 0x0a, 0x0d, 0x63, 0x6f, 0x6d, 0x2e, 0x63, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x76, 0x31, 0x42, 0x0b, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x50, + 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x43, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, + 0x6f, 0x6d, 0x2f, 0x74, 0x61, 0x75, 0x62, 0x79, 0x74, 0x65, 0x2f, 0x74, 0x61, 0x75, 0x2f, 0x70, + 0x6b, 0x67, 0x2f, 0x73, 0x70, 0x6f, 0x72, 0x65, 0x2d, 0x64, 0x72, 0x69, 0x76, 0x65, 0x2f, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2f, + 0x76, 0x31, 0x3b, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x43, 0x58, + 0x58, 0xaa, 0x02, 0x09, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x09, + 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x15, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x5c, 0x56, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, + 0x61, 0xea, 0x02, 0x0a, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -3731,20 +3734,22 @@ var file_config_v1_config_proto_depIdxs = []int32{ 37, // 53: config.v1.Shape.ports:type_name -> config.v1.Ports 7, // 54: config.v1.Shape.plugins:type_name -> config.v1.StringSliceOp 38, // 55: config.v1.Ports.select:type_name -> config.v1.Port - 1, // 56: config.v1.ConfigService.Load:input_type -> config.v1.Source - 2, // 57: config.v1.ConfigService.Upload:input_type -> config.v1.SourceUpload - 11, // 58: config.v1.ConfigService.Download:input_type -> config.v1.BundleConfig - 3, // 59: config.v1.ConfigService.Commit:input_type -> config.v1.Config - 3, // 60: config.v1.ConfigService.Free:input_type -> config.v1.Config - 14, // 61: config.v1.ConfigService.Do:input_type -> config.v1.Op - 3, // 62: config.v1.ConfigService.Load:output_type -> config.v1.Config - 3, // 63: config.v1.ConfigService.Upload:output_type -> config.v1.Config - 4, // 64: config.v1.ConfigService.Download:output_type -> config.v1.Bundle - 12, // 65: config.v1.ConfigService.Commit:output_type -> config.v1.Empty - 12, // 66: config.v1.ConfigService.Free:output_type -> config.v1.Empty - 13, // 67: config.v1.ConfigService.Do:output_type -> config.v1.Return - 62, // [62:68] is the sub-list for method output_type - 56, // [56:62] is the sub-list for method input_type + 12, // 56: config.v1.ConfigService.New:input_type -> config.v1.Empty + 1, // 57: config.v1.ConfigService.Load:input_type -> config.v1.Source + 2, // 58: config.v1.ConfigService.Upload:input_type -> config.v1.SourceUpload + 11, // 59: config.v1.ConfigService.Download:input_type -> config.v1.BundleConfig + 3, // 60: config.v1.ConfigService.Commit:input_type -> config.v1.Config + 3, // 61: config.v1.ConfigService.Free:input_type -> config.v1.Config + 14, // 62: config.v1.ConfigService.Do:input_type -> config.v1.Op + 3, // 63: config.v1.ConfigService.New:output_type -> config.v1.Config + 3, // 64: config.v1.ConfigService.Load:output_type -> config.v1.Config + 3, // 65: config.v1.ConfigService.Upload:output_type -> config.v1.Config + 4, // 66: config.v1.ConfigService.Download:output_type -> config.v1.Bundle + 12, // 67: config.v1.ConfigService.Commit:output_type -> config.v1.Empty + 12, // 68: config.v1.ConfigService.Free:output_type -> config.v1.Empty + 13, // 69: config.v1.ConfigService.Do:output_type -> config.v1.Return + 63, // [63:70] is the sub-list for method output_type + 56, // [56:63] is the sub-list for method input_type 56, // [56:56] is the sub-list for extension type_name 56, // [56:56] is the sub-list for extension extendee 0, // [0:56] is the sub-list for field type_name diff --git a/pkg/spore-drive/proto/gen/config/v1/configv1connect/config.connect.go b/pkg/spore-drive/proto/gen/config/v1/configv1connect/config.connect.go index 06174d75..3b31c374 100644 --- a/pkg/spore-drive/proto/gen/config/v1/configv1connect/config.connect.go +++ b/pkg/spore-drive/proto/gen/config/v1/configv1connect/config.connect.go @@ -33,6 +33,8 @@ const ( // reflection-formatted method names, remove the leading slash and convert the remaining slash to a // period. const ( + // ConfigServiceNewProcedure is the fully-qualified name of the ConfigService's New RPC. + ConfigServiceNewProcedure = "/config.v1.ConfigService/New" // ConfigServiceLoadProcedure is the fully-qualified name of the ConfigService's Load RPC. ConfigServiceLoadProcedure = "/config.v1.ConfigService/Load" // ConfigServiceUploadProcedure is the fully-qualified name of the ConfigService's Upload RPC. @@ -50,6 +52,7 @@ const ( // These variables are the protoreflect.Descriptor objects for the RPCs defined in this package. var ( configServiceServiceDescriptor = v1.File_config_v1_config_proto.Services().ByName("ConfigService") + configServiceNewMethodDescriptor = configServiceServiceDescriptor.Methods().ByName("New") configServiceLoadMethodDescriptor = configServiceServiceDescriptor.Methods().ByName("Load") configServiceUploadMethodDescriptor = configServiceServiceDescriptor.Methods().ByName("Upload") configServiceDownloadMethodDescriptor = configServiceServiceDescriptor.Methods().ByName("Download") @@ -60,6 +63,7 @@ var ( // ConfigServiceClient is a client for the config.v1.ConfigService service. type ConfigServiceClient interface { + New(context.Context, *connect.Request[v1.Empty]) (*connect.Response[v1.Config], error) Load(context.Context, *connect.Request[v1.Source]) (*connect.Response[v1.Config], error) Upload(context.Context) *connect.ClientStreamForClient[v1.SourceUpload, v1.Config] Download(context.Context, *connect.Request[v1.BundleConfig]) (*connect.ServerStreamForClient[v1.Bundle], error) @@ -78,6 +82,12 @@ type ConfigServiceClient interface { func NewConfigServiceClient(httpClient connect.HTTPClient, baseURL string, opts ...connect.ClientOption) ConfigServiceClient { baseURL = strings.TrimRight(baseURL, "/") return &configServiceClient{ + new: connect.NewClient[v1.Empty, v1.Config]( + httpClient, + baseURL+ConfigServiceNewProcedure, + connect.WithSchema(configServiceNewMethodDescriptor), + connect.WithClientOptions(opts...), + ), load: connect.NewClient[v1.Source, v1.Config]( httpClient, baseURL+ConfigServiceLoadProcedure, @@ -119,6 +129,7 @@ func NewConfigServiceClient(httpClient connect.HTTPClient, baseURL string, opts // configServiceClient implements ConfigServiceClient. type configServiceClient struct { + new *connect.Client[v1.Empty, v1.Config] load *connect.Client[v1.Source, v1.Config] upload *connect.Client[v1.SourceUpload, v1.Config] download *connect.Client[v1.BundleConfig, v1.Bundle] @@ -127,6 +138,11 @@ type configServiceClient struct { do *connect.Client[v1.Op, v1.Return] } +// New calls config.v1.ConfigService.New. +func (c *configServiceClient) New(ctx context.Context, req *connect.Request[v1.Empty]) (*connect.Response[v1.Config], error) { + return c.new.CallUnary(ctx, req) +} + // Load calls config.v1.ConfigService.Load. func (c *configServiceClient) Load(ctx context.Context, req *connect.Request[v1.Source]) (*connect.Response[v1.Config], error) { return c.load.CallUnary(ctx, req) @@ -159,6 +175,7 @@ func (c *configServiceClient) Do(ctx context.Context, req *connect.Request[v1.Op // ConfigServiceHandler is an implementation of the config.v1.ConfigService service. type ConfigServiceHandler interface { + New(context.Context, *connect.Request[v1.Empty]) (*connect.Response[v1.Config], error) Load(context.Context, *connect.Request[v1.Source]) (*connect.Response[v1.Config], error) Upload(context.Context, *connect.ClientStream[v1.SourceUpload]) (*connect.Response[v1.Config], error) Download(context.Context, *connect.Request[v1.BundleConfig], *connect.ServerStream[v1.Bundle]) error @@ -173,6 +190,12 @@ type ConfigServiceHandler interface { // By default, handlers support the Connect, gRPC, and gRPC-Web protocols with the binary Protobuf // and JSON codecs. They also support gzip compression. func NewConfigServiceHandler(svc ConfigServiceHandler, opts ...connect.HandlerOption) (string, http.Handler) { + configServiceNewHandler := connect.NewUnaryHandler( + ConfigServiceNewProcedure, + svc.New, + connect.WithSchema(configServiceNewMethodDescriptor), + connect.WithHandlerOptions(opts...), + ) configServiceLoadHandler := connect.NewUnaryHandler( ConfigServiceLoadProcedure, svc.Load, @@ -211,6 +234,8 @@ func NewConfigServiceHandler(svc ConfigServiceHandler, opts ...connect.HandlerOp ) return "/config.v1.ConfigService/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.URL.Path { + case ConfigServiceNewProcedure: + configServiceNewHandler.ServeHTTP(w, r) case ConfigServiceLoadProcedure: configServiceLoadHandler.ServeHTTP(w, r) case ConfigServiceUploadProcedure: @@ -232,6 +257,10 @@ func NewConfigServiceHandler(svc ConfigServiceHandler, opts ...connect.HandlerOp // UnimplementedConfigServiceHandler returns CodeUnimplemented from all methods. type UnimplementedConfigServiceHandler struct{} +func (UnimplementedConfigServiceHandler) New(context.Context, *connect.Request[v1.Empty]) (*connect.Response[v1.Config], error) { + return nil, connect.NewError(connect.CodeUnimplemented, errors.New("config.v1.ConfigService.New is not implemented")) +} + func (UnimplementedConfigServiceHandler) Load(context.Context, *connect.Request[v1.Source]) (*connect.Response[v1.Config], error) { return nil, connect.NewError(connect.CodeUnimplemented, errors.New("config.v1.ConfigService.Load is not implemented")) }