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

feature: Allow specifying extensions in the conjure IR #411

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-411.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: feature
feature:
description: Allow specifying extensions in the conjure IR
links:
- https://github.com/palantir/godel-conjure-plugin/pull/411
18 changes: 15 additions & 3 deletions conjureplugin/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/palantir/godel-conjure-plugin/v6/conjureplugin"
v1 "github.com/palantir/godel-conjure-plugin/v6/conjureplugin/config/internal/v1"
"github.com/palantir/godel-conjure-plugin/v6/ir-gen-cli-bundler/conjureircli"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
)
Expand All @@ -42,10 +43,20 @@ func (c *ConjurePluginConfig) ToParams() (conjureplugin.ConjureProjectParams, er

params := make(map[string]conjureplugin.ConjureProjectParam)
for key, currConfig := range c.ProjectConfigs {
irProvider, err := (*IRLocatorConfig)(&currConfig.IRLocator).ToIRProvider()
var conjureCLIParams []conjureircli.Param
if param, err := conjureircli.ExtensionsParam(currConfig.Extensions); err != nil {
return conjureplugin.ConjureProjectParams{}, errors.Wrapf(err, "failed to parse extensions")
} else if param != nil {
conjureCLIParams = append(conjureCLIParams, param)
}

irProvider, err := (*IRLocatorConfig)(&currConfig.IRLocator).ToIRProvider(conjureCLIParams...)
if err != nil {
return conjureplugin.ConjureProjectParams{}, errors.Wrapf(err, "failed to convert configuration for %s to provider", key)
}
if currConfig.Extensions != nil && !irProvider.GeneratedFromYAML() {
return conjureplugin.ConjureProjectParams{}, errors.Errorf("cannot use IR extensions on conjure definitions not defined locally")
}

publishVal := false
// if value for "publish" is not specified, treat as "true" only if provider generates IR from YAML
Expand All @@ -63,6 +74,7 @@ func (c *ConjurePluginConfig) ToParams() (conjureplugin.ConjureProjectParams, er
Server: currConfig.Server,
CLI: currConfig.CLI,
Publish: publishVal,
Extensions: currConfig.Extensions,
}
}
return conjureplugin.ConjureProjectParams{
Expand All @@ -85,7 +97,7 @@ func ToIRLocatorConfig(in *IRLocatorConfig) *v1.IRLocatorConfig {
return (*v1.IRLocatorConfig)(in)
}

func (cfg *IRLocatorConfig) ToIRProvider() (conjureplugin.IRProvider, error) {
func (cfg *IRLocatorConfig) ToIRProvider(params ...conjureircli.Param) (conjureplugin.IRProvider, error) {
if cfg.Locator == "" {
return nil, errors.Errorf("locator cannot be empty")
}
Expand Down Expand Up @@ -118,7 +130,7 @@ func (cfg *IRLocatorConfig) ToIRProvider() (conjureplugin.IRProvider, error) {
case v1.LocatorTypeRemote:
return conjureplugin.NewHTTPIRProvider(cfg.Locator), nil
case v1.LocatorTypeYAML:
return conjureplugin.NewLocalYAMLIRProvider(cfg.Locator), nil
return conjureplugin.NewLocalYAMLIRProvider(cfg.Locator, params...), nil
case v1.LocatorTypeIRFile:
return conjureplugin.NewLocalFileIRProvider(cfg.Locator), nil
default:
Expand Down
130 changes: 84 additions & 46 deletions conjureplugin/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package config_test

import (
"fmt"
"testing"

"github.com/palantir/godel-conjure-plugin/v6/conjureplugin"
Expand Down Expand Up @@ -52,10 +53,10 @@ projects:
{
`
projects:
project:
output-dir: outputDir
ir-locator: local/yaml-dir
publish: false
project:
output-dir: outputDir
ir-locator: local/yaml-dir
publish: false
`,
config.ConjurePluginConfig{
ProjectConfigs: map[string]v1.SingleConjureConfig{
Expand All @@ -73,11 +74,11 @@ projects:
{
`
projects:
project:
output-dir: outputDir
ir-locator:
type: yaml
locator: explicit/yaml-dir
project:
output-dir: outputDir
ir-locator:
type: yaml
locator: explicit/yaml-dir
`,
config.ConjurePluginConfig{
ProjectConfigs: map[string]v1.SingleConjureConfig{
Expand All @@ -94,9 +95,9 @@ projects:
{
`
projects:
project:
output-dir: outputDir
ir-locator: http://foo.com/ir.json
project:
output-dir: outputDir
ir-locator: http://foo.com/ir.json
`,
config.ConjurePluginConfig{
ProjectConfigs: map[string]v1.SingleConjureConfig{
Expand All @@ -113,10 +114,10 @@ projects:
{
`
projects:
project:
output-dir: outputDir
ir-locator: http://foo.com/ir.json
publish: true
project:
output-dir: outputDir
ir-locator: http://foo.com/ir.json
publish: true
`,
config.ConjurePluginConfig{
ProjectConfigs: map[string]v1.SingleConjureConfig{
Expand All @@ -134,11 +135,11 @@ projects:
{
`
projects:
project:
output-dir: outputDir
ir-locator:
type: remote
locator: localhost:8080/ir.json
project:
output-dir: outputDir
ir-locator:
type: remote
locator: localhost:8080/ir.json
`,
config.ConjurePluginConfig{
ProjectConfigs: map[string]v1.SingleConjureConfig{
Expand All @@ -155,9 +156,9 @@ projects:
{
`
projects:
project:
output-dir: outputDir
ir-locator: local/nonexistent-ir-file.json
project:
output-dir: outputDir
ir-locator: local/nonexistent-ir-file.json
`,
config.ConjurePluginConfig{
ProjectConfigs: map[string]v1.SingleConjureConfig{
Expand All @@ -174,11 +175,11 @@ projects:
{
`
projects:
project:
output-dir: outputDir
ir-locator:
type: ir-file
locator: local/nonexistent-ir-file.json
project:
output-dir: outputDir
ir-locator:
type: ir-file
locator: local/nonexistent-ir-file.json
`,
config.ConjurePluginConfig{
ProjectConfigs: map[string]v1.SingleConjureConfig{
Expand All @@ -195,13 +196,13 @@ projects:
{
`
projects:
project:
output-dir: outputDir
ir-locator:
type: remote
locator: localhost:8080/ir.json
server: true
cli: true
project:
output-dir: outputDir
ir-locator:
type: remote
locator: localhost:8080/ir.json
server: true
cli: true
`,
config.ConjurePluginConfig{
ProjectConfigs: map[string]v1.SingleConjureConfig{
Expand All @@ -220,12 +221,12 @@ projects:
{
`
projects:
project:
output-dir: outputDir
ir-locator:
type: remote
locator: localhost:8080/ir.json
accept-funcs: true
project:
output-dir: outputDir
ir-locator:
type: remote
locator: localhost:8080/ir.json
accept-funcs: true
`,
config.ConjurePluginConfig{
ProjectConfigs: map[string]v1.SingleConjureConfig{
Expand All @@ -241,11 +242,48 @@ projects:
},
},
},
{
`
projects:
project:
output-dir: outputDir
ir-locator:
type: yaml
locator: explicit/yaml-dir
extensions:
recommended-product-dependencies:
maximum-version: "2.x.x"
minimum-version: "2.78.0"
product-group: "com.palantir.assetserver"
product-name: "asset-server"
`,
config.ConjurePluginConfig{
ProjectConfigs: map[string]v1.SingleConjureConfig{
"project": {
OutputDir: "outputDir",
IRLocator: v1.IRLocatorConfig{
Type: v1.LocatorTypeYAML,
Locator: "explicit/yaml-dir",
},
Extensions: map[string]interface{}{
"recommended-product-dependencies": map[interface{}]interface{}{
"maximum-version": "2.x.x",
"minimum-version": "2.78.0",
"product-group": "com.palantir.assetserver",
"product-name": "asset-server",
},
},
},
},
},
},
} {
var got config.ConjurePluginConfig
err := yaml.Unmarshal([]byte(tc.in), &got)
require.NoError(t, err)
assert.Equal(t, tc.want, got, "Case %d", i)
t.Run(fmt.Sprintf("Case %d", i), func(t *testing.T) {
var got config.ConjurePluginConfig
err := yaml.Unmarshal([]byte(tc.in), &got)
require.NoError(t, err)
assert.Equal(t, tc.want, got)
})
}
}

Expand Down
3 changes: 3 additions & 0 deletions conjureplugin/config/internal/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ type SingleConjureConfig struct {
// AcceptFuncs indicates if we will generate lambda based visitor code.
// Currently this is behind a feature flag and is subject to change.
AcceptFuncs *bool `yaml:"accept-funcs,omitempty"`
// Extensions are a map of key-value pairs that will be injected to the IR's extensions field.
// This is only available when the IR is generated from a YAML file.
Extensions map[string]interface{} `yaml:"extensions,omitempty"`
}

type LocatorType string
Expand Down
3 changes: 3 additions & 0 deletions conjureplugin/param.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ type ConjureProjectParam struct {
AcceptFuncs bool
// Publish specifies whether or not this Conjure project should be included in the "publish" operation.
Publish bool
// Extensions are a map of key-value pairs that will be injected to the IR's extensions field.
// This is only available when the IR is generated from a YAML file.
Extensions map[string]interface{}
}