Skip to content

Commit fbc6098

Browse files
hyun98hackerwins
authored andcommitted
Show Server Version in Yorkie CLI (#938)
This commit adds the functionality to display the version of connected Yorkie server in the version command. The version information can be viewed by converting it into yaml or json format using the --output, -o flag. This flag accepts json and yaml strings and converts them to the appropriate format for display. In order to solely check the version of the client CLI without considering the server's version, the --client flag has been included. The development of this feature was inspired by examining the kubectl.
1 parent db9da1e commit fbc6098

File tree

12 files changed

+579
-129
lines changed

12 files changed

+579
-129
lines changed

admin/client.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,20 @@ func (c *Client) ListChangeSummaries(
354354
return summaries, nil
355355
}
356356

357+
// GetServerVersion gets the server version.
358+
func (c *Client) GetServerVersion(ctx context.Context) (*types.VersionDetail, error) {
359+
response, err := c.client.GetServerVersion(ctx, connect.NewRequest(&api.GetServerVersionRequest{}))
360+
if err != nil {
361+
return nil, err
362+
}
363+
364+
return &types.VersionDetail{
365+
YorkieVersion: response.Msg.YorkieVersion,
366+
GoVersion: response.Msg.GoVersion,
367+
BuildDate: response.Msg.BuildDate,
368+
}, nil
369+
}
370+
357371
/**
358372
* withShardKey returns a context with the given shard key in metadata.
359373
*/

api/docs/yorkie/v1/admin.openapi.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ paths:
8282
$ref: '#/components/responses/connect.error'
8383
tags:
8484
- yorkie.v1.AdminService
85+
/yorkie.v1.AdminService/GetServerVersion:
86+
post:
87+
description: ""
88+
requestBody:
89+
$ref: '#/components/requestBodies/yorkie.v1.AdminService.GetServerVersion.yorkie.v1.GetServerVersionRequest'
90+
responses:
91+
"200":
92+
$ref: '#/components/responses/yorkie.v1.AdminService.GetServerVersion.yorkie.v1.GetServerVersionResponse'
93+
default:
94+
$ref: '#/components/responses/connect.error'
95+
tags:
96+
- yorkie.v1.AdminService
8597
/yorkie.v1.AdminService/GetSnapshotMeta:
8698
post:
8799
description: ""
@@ -246,6 +258,15 @@ components:
246258
schema:
247259
$ref: '#/components/schemas/yorkie.v1.GetProjectRequest'
248260
required: true
261+
yorkie.v1.AdminService.GetServerVersion.yorkie.v1.GetServerVersionRequest:
262+
content:
263+
application/json:
264+
schema:
265+
$ref: '#/components/schemas/yorkie.v1.GetServerVersionRequest'
266+
application/proto:
267+
schema:
268+
$ref: '#/components/schemas/yorkie.v1.GetServerVersionRequest'
269+
required: true
249270
yorkie.v1.AdminService.GetSnapshotMeta.yorkie.v1.GetSnapshotMetaRequest:
250271
content:
251272
application/json:
@@ -391,6 +412,15 @@ components:
391412
schema:
392413
$ref: '#/components/schemas/yorkie.v1.GetProjectResponse'
393414
description: ""
415+
yorkie.v1.AdminService.GetServerVersion.yorkie.v1.GetServerVersionResponse:
416+
content:
417+
application/json:
418+
schema:
419+
$ref: '#/components/schemas/yorkie.v1.GetServerVersionResponse'
420+
application/proto:
421+
schema:
422+
$ref: '#/components/schemas/yorkie.v1.GetServerVersionResponse'
423+
description: ""
394424
yorkie.v1.AdminService.GetSnapshotMeta.yorkie.v1.GetSnapshotMetaResponse:
395425
content:
396426
application/json:
@@ -868,6 +898,32 @@ components:
868898
type: object
869899
title: GetProjectResponse
870900
type: object
901+
yorkie.v1.GetServerVersionRequest:
902+
additionalProperties: false
903+
description: ""
904+
title: GetServerVersionRequest
905+
type: object
906+
yorkie.v1.GetServerVersionResponse:
907+
additionalProperties: false
908+
description: ""
909+
properties:
910+
buildDate:
911+
additionalProperties: false
912+
description: ""
913+
title: build_date
914+
type: string
915+
goVersion:
916+
additionalProperties: false
917+
description: ""
918+
title: go_version
919+
type: string
920+
yorkieVersion:
921+
additionalProperties: false
922+
description: ""
923+
title: yorkie_version
924+
type: string
925+
title: GetServerVersionResponse
926+
type: object
871927
yorkie.v1.GetSnapshotMetaRequest:
872928
additionalProperties: false
873929
description: ""

api/types/version_info.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package types
2+
3+
// VersionInfo represents information of version.
4+
type VersionInfo struct {
5+
// ClientVersion is the yorkie cli version.
6+
ClientVersion *VersionDetail `json:"clientVersion,omitempty" yaml:"clientVersion,omitempty"`
7+
8+
// ServerVersion is the yorkie server version.
9+
ServerVersion *VersionDetail `json:"serverVersion,omitempty" yaml:"serverVersion,omitempty"`
10+
}
11+
12+
// VersionDetail represents detail information of version.
13+
type VersionDetail struct {
14+
// YorkieVersion
15+
YorkieVersion string `json:"yorkieVersion" yaml:"yorkieVersion"`
16+
17+
// GoVersion
18+
GoVersion string `json:"goVersion" yaml:"goVersion"`
19+
20+
// BuildDate
21+
BuildDate string `json:"buildDate" yaml:"buildDate"`
22+
}

api/yorkie/v1/admin.pb.go

Lines changed: 265 additions & 121 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/yorkie/v1/admin.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ service AdminService {
4444
rpc SearchDocuments (SearchDocumentsRequest) returns (SearchDocumentsResponse) {}
4545

4646
rpc ListChanges (ListChangesRequest) returns (ListChangesResponse) {}
47+
48+
rpc GetServerVersion (GetServerVersionRequest) returns (GetServerVersionResponse) {}
4749
}
4850

4951
message SignUpRequest {
@@ -184,3 +186,11 @@ message ListChangesRequest {
184186
message ListChangesResponse {
185187
repeated Change changes = 1;
186188
}
189+
190+
message GetServerVersionRequest {}
191+
192+
message GetServerVersionResponse {
193+
string yorkie_version = 1;
194+
string go_version = 2;
195+
string build_date = 3;
196+
}

api/yorkie/v1/v1connect/admin.connect.go

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/yorkie/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func LoadAuth(addr string) (Auth, error) {
7979

8080
auth, ok := config.Auths[addr]
8181
if !ok {
82-
return Auth{}, fmt.Errorf("auth for %s does not exist", addr)
82+
return Auth{}, fmt.Errorf("auth for '%s' does not exist", addr)
8383
}
8484

8585
return auth, nil

0 commit comments

Comments
 (0)