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

List all properties in a group #296

Merged
merged 1 commit into from
Jul 6, 2023
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
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Release Notes.

## 0.5.0

### Features

- List all properties in a group.

## 0.4.0

### Features
Expand Down
2 changes: 1 addition & 1 deletion api/proto/banyandb/common/v1/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ message Metadata {
// group contains a set of options, like retention policy, max
string group = 1;
// name of the entity
string name = 2 [(validate.rules).string.min_len = 1];
string name = 2;
uint32 id = 3;
// readonly. create_revision is the revision of last creation on this key.
int64 create_revision = 4;
Expand Down
3 changes: 3 additions & 0 deletions api/proto/banyandb/property/v1/rpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ service PropertyService {
rpc List(ListRequest) returns (ListResponse) {
option (google.api.http) = {
get: "/v1/property/lists/{container.group}/{container.name}/{ids}/{tags}"
additional_bindings {
get: "/v1/property/lists/{container.group}"
}
};
}
}
6 changes: 5 additions & 1 deletion bydbctl/internal/cmd/property.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (
propertySchemaPathWithoutTagParams = propertySchemaPath + "/{group}/{name}/{id}"
propertySchemaPathWithTagParams = propertySchemaPath + "/{group}/{name}/{id}/{tag}"
propertyListSchemaPathWithTagParams = propertySchemaPath + "/lists/{group}/{name}/{ids}/{tags}"
propertyListSchemaPath = propertySchemaPath + "/lists/{group}"
)

func newPropertyCmd() *cobra.Command {
Expand Down Expand Up @@ -103,12 +104,15 @@ func newPropertyCmd() *cobra.Command {
Short: "List properties",
RunE: func(_ *cobra.Command, _ []string) (err error) {
return rest(parseFromFlags, func(request request) (*resty.Response, error) {
if len(request.name) == 0 {
return request.req.SetPathParam("group", request.group).Get(getPath(propertyListSchemaPath))
}
return request.req.SetPathParam("name", request.name).SetPathParam("group", request.group).
SetPathParam("ids", request.ids()).SetPathParam("tags", request.tags()).Get(getPath(propertyListSchemaPathWithTagParams))
}, yamlPrinter)
},
}
bindNameFlag(listCmd)
listCmd.Flags().StringVarP(&name, "name", "n", "", "the name of the resource")
listCmd.Flags().StringArrayVarP(&ids, "ids", "", nil, "id selector")
listCmd.Flags().StringArrayVarP(&tags, "tags", "t", nil, "tag selector")

Expand Down
40 changes: 39 additions & 1 deletion bydbctl/internal/cmd/property_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,44 @@ tags:
Expect(err).To(MatchError("rpc error: code = NotFound desc = banyandb: resource not found"))
})

It("list property", func() {
It("list all properties", func() {
// create another property for list operation
rootCmd.SetArgs([]string{"property", "apply", "-f", "-"})
rootCmd.SetIn(strings.NewReader(`
metadata:
container:
group: ui-template
name: service
id: spring
tags:
- key: content
value:
str:
value: bar
- key: state
value:
int:
value: 1
`))
out := capturer.CaptureStdout(func() {
err := rootCmd.Execute()
Expect(err).NotTo(HaveOccurred())
})
Expect(out).To(ContainSubstring("created: true"))
Expect(out).To(ContainSubstring("tagsNum: 2"))
// list
rootCmd.SetArgs([]string{"property", "list", "-g", "ui-template"})
out = capturer.CaptureStdout(func() {
cmd.ResetFlags()
err := rootCmd.Execute()
Expect(err).NotTo(HaveOccurred())
})
resp := new(propertyv1.ListResponse)
helpers.UnmarshalYAML([]byte(out), resp)
Expect(resp.Property).To(HaveLen(2))
})

It("list properties in a container", func() {
// create another property for list operation
rootCmd.SetArgs([]string{"property", "apply", "-f", "-"})
rootCmd.SetIn(strings.NewReader(`
Expand Down Expand Up @@ -229,6 +266,7 @@ tags:
// list
rootCmd.SetArgs([]string{"property", "list", "-g", "ui-template", "-n", "service"})
out = capturer.CaptureStdout(func() {
cmd.ResetFlags()
err := rootCmd.Execute()
Expect(err).NotTo(HaveOccurred())
})
Expand Down
8 changes: 8 additions & 0 deletions bydbctl/internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ var (
}
)

// ResetFlags resets the flags.
func ResetFlags() {
filePath = ""
name = ""
start = ""
end = ""
}

// Execute executes the root command.
func Execute() error {
return rootCmd.Execute()
Expand Down
12 changes: 10 additions & 2 deletions docs/crud/property.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,17 @@ $ bydbctl property delete -g sw -n ui_template --id General-Service --tags state

## List operation

List operation lists all properties.
List operation lists all properties in a group.

### Examples of listing
### Examples of listing in a group

```shell
$ bydbctl property list -g sw
```

List operation lists all properties in a group with a name.

### Examples of listing in a group with a name

```shell
$ bydbctl property list -g sw -n ui_template
Expand Down
9 changes: 8 additions & 1 deletion test/integration/other/property_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,14 @@ var _ = Describe("Property application", func() {
Expect(conn.Close()).To(Succeed())
deferFn()
})
It("lists properties", func() {
It("lists properties in a group", func() {
got, err := client.List(context.Background(), &propertyv1.ListRequest{Container: &commonv1.Metadata{
Group: "g",
}})
Expect(err).NotTo(HaveOccurred())
Expect(len(got.Property)).To(Equal(1))
})
It("lists properties in a container", func() {
got, err := client.List(context.Background(), &propertyv1.ListRequest{Container: md.Container})
Expect(err).NotTo(HaveOccurred())
Expect(len(got.Property)).To(Equal(1))
Expand Down