Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Volume management API & example #43

Merged
merged 1 commit into from
Sep 29, 2020
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
61 changes: 61 additions & 0 deletions examples/volume.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
Copyright 2020 The Authors

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.
*/

import * as grpc from '@grpc/grpc-js';

import { Volumes } from '../src/index';
import {
AciVolumeCreateOptions,
VolumesCreateRequest,
VolumesCreateResponse,
VolumesListRequest,
VolumesListResponse,
} from '../src/volumes';

const client = new Volumes();

client.volumesList(
new VolumesListRequest(),
(error: grpc.ServiceError | null, response: VolumesListResponse) => {
if (error != null) {
throw error;
}
response.getVolumesList().forEach((volume) => {
console.log(
volume.getId() + " : " + volume.getDescription()
);
});
}
);

let request = new VolumesCreateRequest();
request.setName("test-volume")
let aciVolumeCreateOptions = new AciVolumeCreateOptions();
aciVolumeCreateOptions.setStorageAccount("mystorageaccount")
request.setAciOption(aciVolumeCreateOptions)

client.volumesCreate(
request,
(error: grpc.ServiceError | null, response: VolumesCreateResponse) => {
if (error != null) {
console.log(error.message);
} else {
console.log(
response.getVolume()?.getId()
);
}
}
);
2 changes: 2 additions & 0 deletions protos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ node_modules/.bin/grpc_tools_node_protoc \
src/protos/contexts/v1/*.proto \
src/protos/containers/v1/*.proto \
src/protos/compose/v1/*.proto \
src/protos/volumes/v1/*.proto \
src/protos/streams/v1/*.proto

# generate d.ts codes
Expand All @@ -31,4 +32,5 @@ node_modules/.bin/grpc_tools_node_protoc \
src/protos/contexts/v1/*.proto \
src/protos/containers/v1/*.proto \
src/protos/compose/v1/*.proto \
src/protos/volumes/v1/*.proto \
src/protos/streams/v1/*.proto
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { homedir, platform } from 'os';

import { credentials } from '@grpc/grpc-js';
import { ContainersClient } from './protos/containers/v1/containers_grpc_pb';
import { VolumesClient } from './protos/volumes/v1/volumes_grpc_pb';
import { ContextsClient } from './protos/contexts/v1/contexts_grpc_pb';
import { ComposeClient } from './protos/compose/v1/compose_grpc_pb';
import { StreamingClient } from './protos/streams/v1/streams_grpc_pb';
Expand All @@ -33,6 +34,12 @@ export class Containers extends ContainersClient {
}
}

export class Volumes extends VolumesClient {
constructor(address: string = addr) {
super(address, credentials.createInsecure());
}
}

export class Contexts extends ContextsClient {
constructor(address: string = addr) {
super(address, credentials.createInsecure());
Expand Down
62 changes: 62 additions & 0 deletions src/protos/volumes/v1/volumes.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// Copyright 2020 Docker Compose CLI authors

// 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";

package com.docker.api.protos.volumes.v1;

import "google/protobuf/any.proto";

option go_package = "github.com/docker/compose-cli/protos/volumes/v1;v1";

service Volumes {
rpc VolumesCreate(VolumesCreateRequest) returns (VolumesCreateResponse);
rpc VolumesList(VolumesListRequest) returns (VolumesListResponse);
rpc VolumesDelete(VolumesDeleteRequest) returns (VolumesDeleteResponse);
}

message Volume {
string id = 1;
string description = 2;
}

message AciVolumeCreateOptions {
string storage_account = 1;
}

message VolumesCreateRequest {
string name = 1;
oneof options {
AciVolumeCreateOptions aci_option = 2;
}
}

message VolumesCreateResponse {
Volume volume = 1;
}

message VolumesListRequest {
}

message VolumesListResponse {
repeated Volume volumes = 1;
}

message VolumesDeleteRequest {
string id = 1;
}

message VolumesDeleteResponse {
}
77 changes: 77 additions & 0 deletions src/protos/volumes/v1/volumes_grpc_pb.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// package: com.docker.api.protos.volumes.v1
// file: volumes/v1/volumes.proto

/* tslint:disable */
/* eslint-disable */

import * as grpc from "@grpc/grpc-js";
import {handleClientStreamingCall} from "@grpc/grpc-js/build/src/server-call";
import * as volumes_v1_volumes_pb from "../../volumes/v1/volumes_pb";
import * as google_protobuf_any_pb from "google-protobuf/google/protobuf/any_pb";

interface IVolumesService extends grpc.ServiceDefinition<grpc.UntypedServiceImplementation> {
volumesCreate: IVolumesService_IVolumesCreate;
volumesList: IVolumesService_IVolumesList;
volumesDelete: IVolumesService_IVolumesDelete;
}

interface IVolumesService_IVolumesCreate extends grpc.MethodDefinition<volumes_v1_volumes_pb.VolumesCreateRequest, volumes_v1_volumes_pb.VolumesCreateResponse> {
path: string; // "/com.docker.api.protos.volumes.v1.Volumes/VolumesCreate"
requestStream: false;
responseStream: false;
requestSerialize: grpc.serialize<volumes_v1_volumes_pb.VolumesCreateRequest>;
requestDeserialize: grpc.deserialize<volumes_v1_volumes_pb.VolumesCreateRequest>;
responseSerialize: grpc.serialize<volumes_v1_volumes_pb.VolumesCreateResponse>;
responseDeserialize: grpc.deserialize<volumes_v1_volumes_pb.VolumesCreateResponse>;
}
interface IVolumesService_IVolumesList extends grpc.MethodDefinition<volumes_v1_volumes_pb.VolumesListRequest, volumes_v1_volumes_pb.VolumesListResponse> {
path: string; // "/com.docker.api.protos.volumes.v1.Volumes/VolumesList"
requestStream: false;
responseStream: false;
requestSerialize: grpc.serialize<volumes_v1_volumes_pb.VolumesListRequest>;
requestDeserialize: grpc.deserialize<volumes_v1_volumes_pb.VolumesListRequest>;
responseSerialize: grpc.serialize<volumes_v1_volumes_pb.VolumesListResponse>;
responseDeserialize: grpc.deserialize<volumes_v1_volumes_pb.VolumesListResponse>;
}
interface IVolumesService_IVolumesDelete extends grpc.MethodDefinition<volumes_v1_volumes_pb.VolumesDeleteRequest, volumes_v1_volumes_pb.VolumesDeleteResponse> {
path: string; // "/com.docker.api.protos.volumes.v1.Volumes/VolumesDelete"
requestStream: false;
responseStream: false;
requestSerialize: grpc.serialize<volumes_v1_volumes_pb.VolumesDeleteRequest>;
requestDeserialize: grpc.deserialize<volumes_v1_volumes_pb.VolumesDeleteRequest>;
responseSerialize: grpc.serialize<volumes_v1_volumes_pb.VolumesDeleteResponse>;
responseDeserialize: grpc.deserialize<volumes_v1_volumes_pb.VolumesDeleteResponse>;
}

export const VolumesService: IVolumesService;

export interface IVolumesServer {
volumesCreate: grpc.handleUnaryCall<volumes_v1_volumes_pb.VolumesCreateRequest, volumes_v1_volumes_pb.VolumesCreateResponse>;
volumesList: grpc.handleUnaryCall<volumes_v1_volumes_pb.VolumesListRequest, volumes_v1_volumes_pb.VolumesListResponse>;
volumesDelete: grpc.handleUnaryCall<volumes_v1_volumes_pb.VolumesDeleteRequest, volumes_v1_volumes_pb.VolumesDeleteResponse>;
}

export interface IVolumesClient {
volumesCreate(request: volumes_v1_volumes_pb.VolumesCreateRequest, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesCreateResponse) => void): grpc.ClientUnaryCall;
volumesCreate(request: volumes_v1_volumes_pb.VolumesCreateRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesCreateResponse) => void): grpc.ClientUnaryCall;
volumesCreate(request: volumes_v1_volumes_pb.VolumesCreateRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesCreateResponse) => void): grpc.ClientUnaryCall;
volumesList(request: volumes_v1_volumes_pb.VolumesListRequest, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesListResponse) => void): grpc.ClientUnaryCall;
volumesList(request: volumes_v1_volumes_pb.VolumesListRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesListResponse) => void): grpc.ClientUnaryCall;
volumesList(request: volumes_v1_volumes_pb.VolumesListRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesListResponse) => void): grpc.ClientUnaryCall;
volumesDelete(request: volumes_v1_volumes_pb.VolumesDeleteRequest, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesDeleteResponse) => void): grpc.ClientUnaryCall;
volumesDelete(request: volumes_v1_volumes_pb.VolumesDeleteRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesDeleteResponse) => void): grpc.ClientUnaryCall;
volumesDelete(request: volumes_v1_volumes_pb.VolumesDeleteRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesDeleteResponse) => void): grpc.ClientUnaryCall;
}

export class VolumesClient extends grpc.Client implements IVolumesClient {
constructor(address: string, credentials: grpc.ChannelCredentials, options?: object);
public volumesCreate(request: volumes_v1_volumes_pb.VolumesCreateRequest, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesCreateResponse) => void): grpc.ClientUnaryCall;
public volumesCreate(request: volumes_v1_volumes_pb.VolumesCreateRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesCreateResponse) => void): grpc.ClientUnaryCall;
public volumesCreate(request: volumes_v1_volumes_pb.VolumesCreateRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesCreateResponse) => void): grpc.ClientUnaryCall;
public volumesList(request: volumes_v1_volumes_pb.VolumesListRequest, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesListResponse) => void): grpc.ClientUnaryCall;
public volumesList(request: volumes_v1_volumes_pb.VolumesListRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesListResponse) => void): grpc.ClientUnaryCall;
public volumesList(request: volumes_v1_volumes_pb.VolumesListRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesListResponse) => void): grpc.ClientUnaryCall;
public volumesDelete(request: volumes_v1_volumes_pb.VolumesDeleteRequest, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesDeleteResponse) => void): grpc.ClientUnaryCall;
public volumesDelete(request: volumes_v1_volumes_pb.VolumesDeleteRequest, metadata: grpc.Metadata, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesDeleteResponse) => void): grpc.ClientUnaryCall;
public volumesDelete(request: volumes_v1_volumes_pb.VolumesDeleteRequest, metadata: grpc.Metadata, options: Partial<grpc.CallOptions>, callback: (error: grpc.ServiceError | null, response: volumes_v1_volumes_pb.VolumesDeleteResponse) => void): grpc.ClientUnaryCall;
}
127 changes: 127 additions & 0 deletions src/protos/volumes/v1/volumes_grpc_pb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// GENERATED CODE -- DO NOT EDIT!

// Original file comments:
//
// Copyright 2020 Docker Compose CLI authors
//
// 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.
//
'use strict';
var grpc = require('@grpc/grpc-js');
var volumes_v1_volumes_pb = require('../../volumes/v1/volumes_pb.js');
var google_protobuf_any_pb = require('google-protobuf/google/protobuf/any_pb.js');

function serialize_com_docker_api_protos_volumes_v1_VolumesCreateRequest(arg) {
if (!(arg instanceof volumes_v1_volumes_pb.VolumesCreateRequest)) {
throw new Error('Expected argument of type com.docker.api.protos.volumes.v1.VolumesCreateRequest');
}
return Buffer.from(arg.serializeBinary());
}

function deserialize_com_docker_api_protos_volumes_v1_VolumesCreateRequest(buffer_arg) {
return volumes_v1_volumes_pb.VolumesCreateRequest.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_com_docker_api_protos_volumes_v1_VolumesCreateResponse(arg) {
if (!(arg instanceof volumes_v1_volumes_pb.VolumesCreateResponse)) {
throw new Error('Expected argument of type com.docker.api.protos.volumes.v1.VolumesCreateResponse');
}
return Buffer.from(arg.serializeBinary());
}

function deserialize_com_docker_api_protos_volumes_v1_VolumesCreateResponse(buffer_arg) {
return volumes_v1_volumes_pb.VolumesCreateResponse.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_com_docker_api_protos_volumes_v1_VolumesDeleteRequest(arg) {
if (!(arg instanceof volumes_v1_volumes_pb.VolumesDeleteRequest)) {
throw new Error('Expected argument of type com.docker.api.protos.volumes.v1.VolumesDeleteRequest');
}
return Buffer.from(arg.serializeBinary());
}

function deserialize_com_docker_api_protos_volumes_v1_VolumesDeleteRequest(buffer_arg) {
return volumes_v1_volumes_pb.VolumesDeleteRequest.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_com_docker_api_protos_volumes_v1_VolumesDeleteResponse(arg) {
if (!(arg instanceof volumes_v1_volumes_pb.VolumesDeleteResponse)) {
throw new Error('Expected argument of type com.docker.api.protos.volumes.v1.VolumesDeleteResponse');
}
return Buffer.from(arg.serializeBinary());
}

function deserialize_com_docker_api_protos_volumes_v1_VolumesDeleteResponse(buffer_arg) {
return volumes_v1_volumes_pb.VolumesDeleteResponse.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_com_docker_api_protos_volumes_v1_VolumesListRequest(arg) {
if (!(arg instanceof volumes_v1_volumes_pb.VolumesListRequest)) {
throw new Error('Expected argument of type com.docker.api.protos.volumes.v1.VolumesListRequest');
}
return Buffer.from(arg.serializeBinary());
}

function deserialize_com_docker_api_protos_volumes_v1_VolumesListRequest(buffer_arg) {
return volumes_v1_volumes_pb.VolumesListRequest.deserializeBinary(new Uint8Array(buffer_arg));
}

function serialize_com_docker_api_protos_volumes_v1_VolumesListResponse(arg) {
if (!(arg instanceof volumes_v1_volumes_pb.VolumesListResponse)) {
throw new Error('Expected argument of type com.docker.api.protos.volumes.v1.VolumesListResponse');
}
return Buffer.from(arg.serializeBinary());
}

function deserialize_com_docker_api_protos_volumes_v1_VolumesListResponse(buffer_arg) {
return volumes_v1_volumes_pb.VolumesListResponse.deserializeBinary(new Uint8Array(buffer_arg));
}


var VolumesService = exports.VolumesService = {
volumesCreate: {
path: '/com.docker.api.protos.volumes.v1.Volumes/VolumesCreate',
requestStream: false,
responseStream: false,
requestType: volumes_v1_volumes_pb.VolumesCreateRequest,
responseType: volumes_v1_volumes_pb.VolumesCreateResponse,
requestSerialize: serialize_com_docker_api_protos_volumes_v1_VolumesCreateRequest,
requestDeserialize: deserialize_com_docker_api_protos_volumes_v1_VolumesCreateRequest,
responseSerialize: serialize_com_docker_api_protos_volumes_v1_VolumesCreateResponse,
responseDeserialize: deserialize_com_docker_api_protos_volumes_v1_VolumesCreateResponse,
},
volumesList: {
path: '/com.docker.api.protos.volumes.v1.Volumes/VolumesList',
requestStream: false,
responseStream: false,
requestType: volumes_v1_volumes_pb.VolumesListRequest,
responseType: volumes_v1_volumes_pb.VolumesListResponse,
requestSerialize: serialize_com_docker_api_protos_volumes_v1_VolumesListRequest,
requestDeserialize: deserialize_com_docker_api_protos_volumes_v1_VolumesListRequest,
responseSerialize: serialize_com_docker_api_protos_volumes_v1_VolumesListResponse,
responseDeserialize: deserialize_com_docker_api_protos_volumes_v1_VolumesListResponse,
},
volumesDelete: {
path: '/com.docker.api.protos.volumes.v1.Volumes/VolumesDelete',
requestStream: false,
responseStream: false,
requestType: volumes_v1_volumes_pb.VolumesDeleteRequest,
responseType: volumes_v1_volumes_pb.VolumesDeleteResponse,
requestSerialize: serialize_com_docker_api_protos_volumes_v1_VolumesDeleteRequest,
requestDeserialize: deserialize_com_docker_api_protos_volumes_v1_VolumesDeleteRequest,
responseSerialize: serialize_com_docker_api_protos_volumes_v1_VolumesDeleteResponse,
responseDeserialize: deserialize_com_docker_api_protos_volumes_v1_VolumesDeleteResponse,
},
};

exports.VolumesClient = grpc.makeGenericClientConstructor(VolumesService);
Loading