Skip to content

Commit

Permalink
Add archive registry support for curated plugin (#2797)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyinma authored Mar 6, 2024
1 parent eb3622e commit 421ed0a
Show file tree
Hide file tree
Showing 7 changed files with 723 additions and 566 deletions.
22 changes: 22 additions & 0 deletions private/bufpkg/bufplugin/bufplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func PluginToProtoPluginRegistryType(plugin Plugin) registryv1alpha1.PluginRegis
registryType = registryv1alpha1.PluginRegistryType_PLUGIN_REGISTRY_TYPE_SWIFT
} else if plugin.Registry().Python != nil {
registryType = registryv1alpha1.PluginRegistryType_PLUGIN_REGISTRY_TYPE_PYTHON
} else if plugin.Registry().Archive != nil {
registryType = registryv1alpha1.PluginRegistryType_PLUGIN_REGISTRY_TYPE_ARCHIVE
}
}
return registryType
Expand Down Expand Up @@ -195,6 +197,12 @@ func PluginRegistryToProtoRegistryConfig(pluginRegistry *bufpluginconfig.Registr
return nil, err
}
registryConfig.RegistryConfig = &registryv1alpha1.RegistryConfig_PythonConfig{PythonConfig: pythonConfig}
} else if pluginRegistry.Archive != nil {
archiveConfig, err := ArchiveRegistryConfigToProtoArchiveConfig(pluginRegistry.Archive)
if err != nil {
return nil, err
}
registryConfig.RegistryConfig = &registryv1alpha1.RegistryConfig_ArchiveConfig{ArchiveConfig: archiveConfig}
}
return registryConfig, nil
}
Expand Down Expand Up @@ -264,6 +272,12 @@ func ProtoRegistryConfigToPluginRegistry(config *registryv1alpha1.RegistryConfig
return nil, err
}
registryConfig.Python = pythonConfig
} else if protoArchiveConfig := config.GetArchiveConfig(); protoArchiveConfig != nil {
archiveConfig, err := ProtoArchiveConfigToArchiveRegistryConfig(protoArchiveConfig)
if err != nil {
return nil, err
}
registryConfig.Archive = archiveConfig
}
return registryConfig, nil
}
Expand Down Expand Up @@ -306,6 +320,14 @@ func PythonRegistryConfigToProtoPythonConfig(pythonConfig *bufpluginconfig.Pytho
return protoPythonConfig, nil
}

func ProtoArchiveConfigToArchiveRegistryConfig(protoArchiveConfig *registryv1alpha1.ArchiveConfig) (*bufpluginconfig.ArchiveRegistryConfig, error) {
return &bufpluginconfig.ArchiveRegistryConfig{}, nil
}

func ArchiveRegistryConfigToProtoArchiveConfig(archiveConfig *bufpluginconfig.ArchiveRegistryConfig) (*registryv1alpha1.ArchiveConfig, error) {
return &registryv1alpha1.ArchiveConfig{}, nil
}

func ProtoSwiftConfigToSwiftRegistryConfig(protoSwiftConfig *registryv1alpha1.SwiftConfig) (*bufpluginconfig.SwiftRegistryConfig, error) {
swiftConfig := &bufpluginconfig.SwiftRegistryConfig{}
runtimeLibs := protoSwiftConfig.GetRuntimeLibraries()
Expand Down
28 changes: 17 additions & 11 deletions private/bufpkg/bufplugin/bufpluginconfig/bufpluginconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ type Config struct {
//
// Only one field will be set.
type RegistryConfig struct {
Go *GoRegistryConfig
NPM *NPMRegistryConfig
Maven *MavenRegistryConfig
Swift *SwiftRegistryConfig
Python *PythonRegistryConfig
Go *GoRegistryConfig
NPM *NPMRegistryConfig
Maven *MavenRegistryConfig
Swift *SwiftRegistryConfig
Python *PythonRegistryConfig
Archive *ArchiveRegistryConfig
// Options is the set of options passed into the plugin for the
// remote registry.
//
Expand Down Expand Up @@ -241,6 +242,8 @@ type PythonRegistryConfig struct {
PackageType string
}

type ArchiveRegistryConfig struct{}

// ConfigOption is an optional option used when loading a Config.
type ConfigOption func(*configOptions)

Expand Down Expand Up @@ -366,12 +369,13 @@ type ExternalDependency struct {
// ExternalRegistryConfig is the external configuration for the registry
// of a plugin.
type ExternalRegistryConfig struct {
Go *ExternalGoRegistryConfig `json:"go,omitempty" yaml:"go,omitempty"`
NPM *ExternalNPMRegistryConfig `json:"npm,omitempty" yaml:"npm,omitempty"`
Maven *ExternalMavenRegistryConfig `json:"maven,omitempty" yaml:"maven,omitempty"`
Swift *ExternalSwiftRegistryConfig `json:"swift,omitempty" yaml:"swift,omitempty"`
Python *ExternalPythonRegistryConfig `json:"python,omitempty" yaml:"python,omitempty"`
Opts []string `json:"opts,omitempty" yaml:"opts,omitempty"`
Go *ExternalGoRegistryConfig `json:"go,omitempty" yaml:"go,omitempty"`
NPM *ExternalNPMRegistryConfig `json:"npm,omitempty" yaml:"npm,omitempty"`
Maven *ExternalMavenRegistryConfig `json:"maven,omitempty" yaml:"maven,omitempty"`
Swift *ExternalSwiftRegistryConfig `json:"swift,omitempty" yaml:"swift,omitempty"`
Python *ExternalPythonRegistryConfig `json:"python,omitempty" yaml:"python,omitempty"`
Archive *ExternalArchiveRegistryConfig `json:"archive,omitempty" yaml:"archive,omitempty"`
Opts []string `json:"opts,omitempty" yaml:"opts,omitempty"`
}

// ExternalGoRegistryConfig is the external registry configuration for a Go plugin.
Expand Down Expand Up @@ -489,6 +493,8 @@ type ExternalPythonRegistryConfig struct {
PackageType string `json:"package_type,omitempty" yaml:"package_type,omitempty"`
}

type ExternalArchiveRegistryConfig struct{}

type externalConfigVersion struct {
Version string `json:"version,omitempty" yaml:"version,omitempty"`
}
Expand Down
23 changes: 23 additions & 0 deletions private/bufpkg/bufplugin/bufpluginconfig/bufpluginconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,29 @@ func TestParsePluginConfigPythonYAML(t *testing.T) {
)
}

func TestParsePluginConfigArchiveYAML(t *testing.T) {
t.Parallel()
pluginConfig, err := ParseConfig(filepath.Join("testdata", "success", "archive", "buf.plugin.yaml"))
require.NoError(t, err)
pluginIdentity, err := bufpluginref.PluginIdentityForString("buf.build/community/pseudomuto-doc")
require.NoError(t, err)
require.Equal(
t,
&Config{
Name: pluginIdentity,
PluginVersion: "v1.5.1",
SourceURL: "https://github.com/pseudomuto/protoc-gen-doc",
Description: "Documentation generator plugin for Google Protocol Buffers.",
SPDXLicenseID: "MIT",
LicenseURL: "https://github.com/pseudomuto/protoc-gen-doc/blob/v1.5.1/LICENSE.md",
Registry: &RegistryConfig{
Archive: &ArchiveRegistryConfig{},
},
},
pluginConfig,
)
}

func TestParsePluginConfigOptionsYAML(t *testing.T) {
t.Parallel()
pluginConfig, err := ParseConfig(filepath.Join("testdata", "success", "options", "buf.plugin.yaml"))
Expand Down
25 changes: 20 additions & 5 deletions private/bufpkg/bufplugin/bufpluginconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,12 @@ func newConfig(externalConfig ExternalConfig, options []ConfigOption) (*Config,

func newRegistryConfig(externalRegistryConfig ExternalRegistryConfig) (*RegistryConfig, error) {
var (
isGoEmpty = externalRegistryConfig.Go == nil
isNPMEmpty = externalRegistryConfig.NPM == nil
isMavenEmpty = externalRegistryConfig.Maven == nil
isSwiftEmpty = externalRegistryConfig.Swift == nil
isPythonEmpty = externalRegistryConfig.Python == nil
isGoEmpty = externalRegistryConfig.Go == nil
isNPMEmpty = externalRegistryConfig.NPM == nil
isMavenEmpty = externalRegistryConfig.Maven == nil
isSwiftEmpty = externalRegistryConfig.Swift == nil
isPythonEmpty = externalRegistryConfig.Python == nil
isArchiveEmpty = externalRegistryConfig.Archive == nil
)
var registryCount int
for _, isEmpty := range []bool{
Expand All @@ -100,6 +101,7 @@ func newRegistryConfig(externalRegistryConfig ExternalRegistryConfig) (*Registry
isMavenEmpty,
isSwiftEmpty,
isPythonEmpty,
isArchiveEmpty,
} {
if !isEmpty {
registryCount++
Expand Down Expand Up @@ -161,6 +163,15 @@ func newRegistryConfig(externalRegistryConfig ExternalRegistryConfig) (*Registry
Python: pythonRegistryConfig,
Options: options,
}, nil
case !isArchiveEmpty:
archiveRegistryConfig, err := newArchiveRegistryConfig(externalRegistryConfig.Archive)
if err != nil {
return nil, err
}
return &RegistryConfig{
Archive: archiveRegistryConfig,
Options: options,
}, nil
default:
return nil, errors.New("unknown registry configuration")
}
Expand Down Expand Up @@ -357,6 +368,10 @@ func newPythonRegistryConfig(externalPythonRegistryConfig *ExternalPythonRegistr
}, nil
}

func newArchiveRegistryConfig(externalArchiveRegistryConfig *ExternalArchiveRegistryConfig) (*ArchiveRegistryConfig, error) {
return &ArchiveRegistryConfig{}, nil
}

func pluginIdentityForStringWithOverrideRemote(identityStr string, overrideRemote string) (bufpluginref.PluginIdentity, error) {
identity, err := bufpluginref.PluginIdentityForString(identityStr)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: v1
name: buf.build/community/pseudomuto-doc
plugin_version: v1.5.1
source_url: https://github.com/pseudomuto/protoc-gen-doc
description: Documentation generator plugin for Google Protocol Buffers.
spdx_license_id: MIT
license_url: https://github.com/pseudomuto/protoc-gen-doc/blob/v1.5.1/LICENSE.md
registry:
archive: {}
Loading

0 comments on commit 421ed0a

Please sign in to comment.