Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
emcfarlane committed Oct 12, 2024
1 parent a66b688 commit c095694
Show file tree
Hide file tree
Showing 48 changed files with 3,153 additions and 15 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ toolchain go1.23.2
require (
buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-20240928190436-5e8abcfd7a7e.2
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.2-20240920164238-5a7b106cbb87.2
buf.build/gen/go/bufbuild/registry/connectrpc/go v1.17.0-20240925012807-1610ffa05635.1
buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.34.2-20240925012807-1610ffa05635.2
buf.build/gen/go/bufbuild/registry/connectrpc/go v1.17.0-00000000000000-f384556653e6.1
buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.34.2-00000000000000-f384556653e6.2
buf.build/go/bufplugin v0.5.0
buf.build/go/protoyaml v0.2.0
buf.build/go/spdx v0.2.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-20240928190436-5e
buf.build/gen/go/bufbuild/bufplugin/protocolbuffers/go v1.34.2-20240928190436-5e8abcfd7a7e.2/go.mod h1:B+9TKHRYqoAUW57pLjhkLOnBCu0DQYMV+f7imQ9nXwI=
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.2-20240920164238-5a7b106cbb87.2 h1:hl0FrmGlNpQZIGvU1/jDz0lsPDd0BhCE0QDRwPfLZcA=
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.34.2-20240920164238-5a7b106cbb87.2/go.mod h1:ylS4c28ACSI59oJrOdW4pHS4n0Hw4TgSPHn8rpHl4Yw=
buf.build/gen/go/bufbuild/registry/connectrpc/go v1.17.0-20240925012807-1610ffa05635.1 h1:p4A9QnhBrKjCquBt1mKqfO37QseLwgWqQp+Wb9ZjasE=
buf.build/gen/go/bufbuild/registry/connectrpc/go v1.17.0-20240925012807-1610ffa05635.1/go.mod h1:7WtU+waNF+dyxDsuNaqmG3d0w3y2poNju8cvun1/jLs=
buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.34.2-20240925012807-1610ffa05635.2 h1:3sSS9z8k6zVe7rNNt9R6DN2fOFBVClEflmICIjbXwms=
buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.34.2-20240925012807-1610ffa05635.2/go.mod h1:psseUmlKRo9v5LZJtR/aTpdTLuyp9o3X7rnLT87SZEo=
buf.build/gen/go/bufbuild/registry/connectrpc/go v1.17.0-00000000000000-f384556653e6.1 h1:Rh6uADIMohx6myydsQ+VDRovAEs8wxO7CWuggBON0Vo=
buf.build/gen/go/bufbuild/registry/connectrpc/go v1.17.0-00000000000000-f384556653e6.1/go.mod h1:LM8iUDMDNerdWwvuUeujsuKbYEM9Tcy9V41/NNQ6n6Y=
buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.34.2-00000000000000-f384556653e6.2 h1:u6D0MOYus2seFpswpKRteA6viAWK6rYSATuxDVg7iyQ=
buf.build/gen/go/bufbuild/registry/protocolbuffers/go v1.34.2-00000000000000-f384556653e6.2/go.mod h1:psseUmlKRo9v5LZJtR/aTpdTLuyp9o3X7rnLT87SZEo=
buf.build/gen/go/pluginrpc/pluginrpc/protocolbuffers/go v1.34.2-20240828222655-5345c0a56177.2 h1:oSi+Adw4xvIjXrW8eY8QGR3sBdfWeY5HN/RefnRt52M=
buf.build/gen/go/pluginrpc/pluginrpc/protocolbuffers/go v1.34.2-20240828222655-5345c0a56177.2/go.mod h1:GjH0gjlY/ns16X8d6eaXV2W+6IFwsO5Ly9WVnzyd1E0=
buf.build/go/bufplugin v0.5.0 h1:pmK1AloAMp+4woH5hEisK9qVmDdLySzIKexUUVZLJ2Q=
Expand Down
50 changes: 50 additions & 0 deletions private/buf/bufcli/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import (
"github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmoduleapi"
"github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmodulecache"
"github.com/bufbuild/buf/private/bufpkg/bufmodule/bufmodulestore"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
"github.com/bufbuild/buf/private/bufpkg/bufplugin/bufpluginapi"
"github.com/bufbuild/buf/private/bufpkg/bufplugin/bufplugincache"
"github.com/bufbuild/buf/private/bufpkg/bufplugin/bufpluginstore"
"github.com/bufbuild/buf/private/pkg/app/appext"
"github.com/bufbuild/buf/private/pkg/command"
"github.com/bufbuild/buf/private/pkg/filelock"
Expand Down Expand Up @@ -103,6 +107,10 @@ var (
//
// Normalized.
v3CacheModuleLockRelDirPath = normalpath.Join("v3", "modulelocks")
// v3CachePluginRelDirPath is the relative path to the files cache directory in its newest iteration.
//
// Normalized.
v3CachePluginRelDirPath = normalpath.Join("v3", "plugins")
// v3CacheWasmRuntimeRelDirPath is the relative path to the Wasm runtime cache directory in its newest iteration.
// This directory is used to store the Wasm runtime cache. This is an implementation specific cache and opaque outside of the runtime.
//
Expand Down Expand Up @@ -140,6 +148,21 @@ func NewCommitProvider(container appext.Container) (bufmodule.CommitProvider, er
)
}

// NewPluginDataProvider returns a new PluginDataProvider while creating the
// required cache directories.
func NewPluginDataProvider(container appext.Container) (bufplugin.PluginDataProvider, error) {
clientConfig, err := NewConnectClientConfig(container)
if err != nil {
return nil, err
}
return newPluginDataProvider(
container,
bufapi.NewClientProvider(
clientConfig,
),
)
}

// CreateWasmRuntimeCacheDir creates the cache directory for the Wasm runtime.
//
// This is used by the Wasm runtime to cache compiled Wasm plugins. This is an
Expand Down Expand Up @@ -209,6 +232,33 @@ func newModuleDataProvider(
), nil
}

func newPluginDataProvider(
container appext.Container,
clientProvider bufapi.ClientProvider,
) (bufplugin.PluginDataProvider, error) {
if err := createCacheDir(container.CacheDirPath(), v3CachePluginRelDirPath); err != nil {
return nil, err
}
fullCacheDirPath := normalpath.Join(container.CacheDirPath(), v3CachePluginRelDirPath)
storageosProvider := storageos.NewProvider() // No symlinks.
cacheBucket, err := storageosProvider.NewReadWriteBucket(fullCacheDirPath)
if err != nil {
return nil, err
}
delegateModuleDataProvider := bufpluginapi.NewPluingDataProvider(
container.Logger(),
clientProvider,
)
return bufplugincache.NewPluginDataProvider(
container.Logger(),
delegateModuleDataProvider,
bufpluginstore.NewPluginDataStore(
container.Logger(),
cacheBucket,
),
), nil
}

func newCommitProvider(
container appext.Container,
clientProvider bufapi.ClientProvider,
Expand Down
12 changes: 12 additions & 0 deletions private/buf/bufcli/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ func NewLabelNameAlreadyExistsError(name string) error {
return fmt.Errorf("a label named %q already exists", name)
}

// NewPluginNameAlreadyExistsError informs the user that a plugin
// with that name already exists.
func NewPluginNameAlreadyExistsError(name string) error {
return fmt.Errorf("a plugin named %q already exists", name)
}

// NewOrganizationNotFoundError informs the user that an organization with
// that name does not exist.
func NewOrganizationNotFoundError(name string) error {
Expand Down Expand Up @@ -88,6 +94,12 @@ func NewTokenNotFoundError(tokenID string) error {
return fmt.Errorf("a token with ID %q does not exist", tokenID)
}

// NewPluginNotFoundError informs the user that a plugin with
// that name does not exist.
func NewPluginNotFoundError(name string) error {
return fmt.Errorf("a plugin named %q does not exist", name)
}

// NewInvalidRemoteError informs the user that the given remote is invalid.
func NewInvalidRemoteError(err error, remote string, moduleFullName string) error {
var connectErr *connect.Error
Expand Down
16 changes: 16 additions & 0 deletions private/buf/bufcli/flags_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"

modulev1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/module/v1"
pluginv1beta1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/plugin/v1beta1"
"github.com/bufbuild/buf/private/buf/buffetch"
"github.com/bufbuild/buf/private/pkg/app"
"github.com/bufbuild/buf/private/pkg/app/appcmd"
Expand Down Expand Up @@ -302,6 +303,21 @@ func VisibilityFlagToVisibilityAllowUnspecified(visibility string) (modulev1.Mod
}
}

// VisibilityFlagToPluginVisibilityAllowUnspecified parses the given string as a pluginv1.PluginVisibility
// where an empty string will be parsed as unspecified.
func VisibilityFlagToPluginVisibilityAllowUnspecified(visibility string) (pluginv1beta1.PluginVisibility, error) {
switch visibility {
case publicVisibility:
return pluginv1beta1.PluginVisibility_PLUGIN_VISIBILITY_PUBLIC, nil
case privateVisibility:
return pluginv1beta1.PluginVisibility_PLUGIN_VISIBILITY_PRIVATE, nil
case "":
return pluginv1beta1.PluginVisibility_PLUGIN_VISIBILITY_UNSPECIFIED, nil
default:
return 0, fmt.Errorf("invalid visibility: %s", visibility)
}
}

// ArchiveStatusFlagToArchiveStatusFilter parses the given string as a modulev1.ListLabelsRequest_ArchiveFilter.
func ArchiveStatusFlagToArchiveStatusFilter(archiveStatus string) (modulev1.ListLabelsRequest_ArchiveFilter, error) {
switch archiveStatus {
Expand Down
27 changes: 27 additions & 0 deletions private/buf/bufprint/bufprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import (

modulev1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/module/v1"
ownerv1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/owner/v1"
pluginv1beta1 "buf.build/gen/go/bufbuild/registry/protocolbuffers/go/buf/registry/plugin/v1beta1"
"github.com/bufbuild/buf/private/bufpkg/bufmodule"
"github.com/bufbuild/buf/private/bufpkg/bufplugin"
registryv1alpha1 "github.com/bufbuild/buf/private/gen/proto/go/buf/alpha/registry/v1alpha1"
"github.com/bufbuild/buf/private/pkg/protoencoding"
"github.com/bufbuild/buf/private/pkg/protostat"
Expand Down Expand Up @@ -248,6 +250,18 @@ func NewOrganizationEntity(organization *ownerv1.Organization, remote string) En
}
}

// NewPluginEntity returns a new plugin entity to print.
func NewPluginEntity(plugin *pluginv1beta1.Plugin, pluginFullName bufplugin.PluginFullName) Entity {
return outputPlugin{
ID: plugin.Id,
Remote: pluginFullName.Registry(),
Owner: pluginFullName.Owner(),
Name: pluginFullName.Name(),
FullName: pluginFullName.String(),
CreateTime: plugin.CreateTime.AsTime(),
}
}

// CuratedPluginPrinter is a printer for curated plugins.
type CuratedPluginPrinter interface {
PrintCuratedPlugin(ctx context.Context, format Format, plugin *registryv1alpha1.CuratedPlugin) error
Expand Down Expand Up @@ -456,3 +470,16 @@ type outputOrganization struct {
func (o outputOrganization) fullName() string {
return o.FullName
}

type outputPlugin struct {
ID string `json:"id,omitempty"`
Remote string `json:"remote,omitempty"`
Owner string `json:"owner,omitempty"`
Name string `json:"name,omitempty"`
FullName string `json:"-" bufprint:"Name"`
CreateTime time.Time `json:"create_time,omitempty" bufprint:"Create Time"`
}

func (m outputPlugin) fullName() string {
return m.FullName
}
30 changes: 26 additions & 4 deletions private/buf/cmd/buf/buf.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import (
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/bufpluginv2"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/lsp"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/price"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/plugin/plugindelete"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/plugin/pluginpush"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/plugin/betaplugindelete"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/plugin/betapluginpush"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/webhook/webhookcreate"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/webhook/webhookdelete"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/beta/registry/webhook/webhooklist"
Expand All @@ -62,6 +62,7 @@ import (
"github.com/bufbuild/buf/private/buf/cmd/buf/command/mod/modlsbreakingrules"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/mod/modlslintrules"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/mod/modopen"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/plugin/pluginpush"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/push"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/commit/commitaddlabel"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/commit/commitinfo"
Expand All @@ -81,6 +82,10 @@ import (
"github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/organization/organizationdelete"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/organization/organizationinfo"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/organization/organizationupdate"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/plugin/plugincreate"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/plugin/plugindelete"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/plugin/plugininfo"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/plugin/pluginupdate"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/registrycc"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/registrylogin"
"github.com/bufbuild/buf/private/buf/cmd/buf/command/registry/registrylogout"
Expand Down Expand Up @@ -224,6 +229,16 @@ func NewRootCommand(name string) *appcmd.Command {
moduleupdate.NewCommand("update", builder),
},
},
{
Use: "plugin",
Short: "Manage BSR plugins",
SubCommands: []*appcmd.Command{
plugincreate.NewCommand("create", builder),
plugininfo.NewCommand("info", builder),
plugindelete.NewCommand("delete", builder),
pluginupdate.NewCommand("update", builder),
},
},
},
},
{
Expand Down Expand Up @@ -254,8 +269,8 @@ func NewRootCommand(name string) *appcmd.Command {
Use: "plugin",
Short: "Manage plugins on the Buf Schema Registry",
SubCommands: []*appcmd.Command{
pluginpush.NewCommand("push", builder),
plugindelete.NewCommand("delete", builder),
betapluginpush.NewCommand("push", builder),
betaplugindelete.NewCommand("delete", builder),
},
},
},
Expand Down Expand Up @@ -285,6 +300,13 @@ func NewRootCommand(name string) *appcmd.Command {
},
},
},
{
Use: "plugin",
Short: "Work with buf plugins",
SubCommands: []*appcmd.Command{
pluginpush.NewCommand("push", builder),
},
},
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package plugindelete
package betaplugindelete

import (
"context"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package pluginpush
package betapluginpush

import (
"context"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c095694

Please sign in to comment.