Skip to content
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
94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,100 @@ pbuf modules delete [module_name]

The command deletes all the tags and proto files associated with the module.

##### Get Metadata

The metadata command allows you to get parsed metadata (packages) for a module tag.

```bash
pbuf metadata get [module_name] [tag]
```

Replace `[module_name]` with the name of the module. Replace `[tag]` with the tag to get metadata for.

> If `module_name` is not provided, the `name` from `pbuf.yaml` is used.

#### Users / Bots

The `users` command group allows you to manage users, bots, and permissions.

##### Create User or Bot

```bash
pbuf users create [name] --type user|bot
```

Replace `[name]` with the user or bot name. The `--type` flag defaults to `user`.

##### List Users

```bash
pbuf users list [--page-size 50] [--page 0]
```

##### Get User

```bash
pbuf users get [id]
```

##### Update User

```bash
pbuf users update [id] [--name new_name] [--active] [--inactive]
```

Only one of `--active` or `--inactive` can be set at a time.

##### Delete User

```bash
pbuf users delete [id]
```

##### Regenerate Token

```bash
pbuf users regenerate-token [id]
```

##### Grant Permission

```bash
pbuf users grant-permission [user_id] [module_name] --permission read|write|admin
```

##### Revoke Permission

```bash
pbuf users revoke-permission [user_id] [module_name]
```

##### List Permissions

```bash
pbuf users list-permissions [user_id]
```

#### Drift Detection

The `drift` command group allows you to manage drift detection events.

##### List Drift Events

```bash
pbuf drift list [--unacknowledged-only]
```

The `--unacknowledged-only` flag defaults to `true` and filters to only unacknowledged events.

##### Get Module Drift Events

```bash
pbuf drift module [module_name] [--tag tag_name]
```

Replace `[module_name]` with the name of the module. Use the optional `--tag` flag to filter by tag name.

---

### Configuration (`pbuf.yaml`)
Expand Down
57 changes: 57 additions & 0 deletions cmd/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package cmd

import (
v1 "github.com/pbufio/pbuf-cli/gen/pbuf-registry/v1"
"github.com/pbufio/pbuf-cli/internal/model"
"github.com/spf13/cobra"
)

func NewMetadataCmd(config *model.Config, client v1.MetadataServiceClient) *cobra.Command {
metadataCmd := &cobra.Command{
Use: "metadata",
Short: "Metadata",
Long: "Metadata is a command to interact with module metadata",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}

metadataCmd.AddCommand(newGetMetadataCmd(config, client))

return metadataCmd
}

func newGetMetadataCmd(config *model.Config, client v1.MetadataServiceClient) *cobra.Command {
getCmd := &cobra.Command{
Use: "get [module_name] [tag]",
Short: "Get metadata",
Long: "Get is a command to get parsed metadata (packages) for a module tag",
Args: cobra.RangeArgs(0, 2),
RunE: func(cmd *cobra.Command, args []string) error {
moduleName := config.Name
if len(args) > 0 {
moduleName = args[0]
}
if moduleName == "" {
return cmd.Help()
}

tag := ""
if len(args) > 1 {
tag = args[1]
}

resp, err := client.GetMetadata(cmd.Context(), &v1.GetMetadataRequest{
Name: moduleName,
Tag: tag,
})
if err != nil {
return err
}

return printJSON(resp)
},
}

return getCmd
}
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ func NewRootCmd() *cobra.Command {
registryClient := v1.NewRegistryClient(conn)
usersClient := v1.NewUserServiceClient(conn)
driftClient := v1.NewDriftServiceClient(conn)
metadataClient := v1.NewMetadataServiceClient(conn)

rootCmd.AddCommand(NewModuleCmd(modulesConfig, registryClient))
rootCmd.AddCommand(NewVendorCmd(modulesConfig, netrcAuth, registryClient))
rootCmd.AddCommand(NewAuthCmd(modulesConfig, usr, netrcAuth))
rootCmd.AddCommand(NewUsersCmd(modulesConfig, usersClient))
rootCmd.AddCommand(NewDriftCmd(modulesConfig, driftClient))
rootCmd.AddCommand(NewMetadataCmd(modulesConfig, metadataClient))
} else {
rootCmd.AddCommand(NewVendorCmd(modulesConfig, netrcAuth, nil))
}
Expand Down