-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
58 changed files
with
2,401 additions
and
1,149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,12 @@ jobs: | |
federation: | ||
name: federation | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
# Repeat the test with in-process plugins and the test gRPC plugin. | ||
plugin: | ||
- "" | ||
- "cofidectl-test-plugin" | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
@@ -80,6 +86,10 @@ jobs: | |
push: false | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
|
||
- name: Build and install test plugin | ||
run: just install-test-plugin | ||
if: ${{ matrix.plugin == 'cofidectl-test-plugin' }} | ||
|
||
- name: Install ko | ||
uses: ko-build/[email protected] | ||
|
@@ -91,3 +101,6 @@ jobs: | |
|
||
- name: Test | ||
run: just integration-test federation | ||
env: | ||
DATA_SOURCE_PLUGIN: ${{ matrix.plugin }} | ||
PROVISION_PLUGIN: ${{ matrix.plugin }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ cofide.yaml | |
|
||
# Plugins | ||
cofidectl-connect | ||
cofidectl-test-plugin | ||
|
||
# cofide-demos repository | ||
demos/cofide-demos/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2024 Cofide Limited. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/cofide/cofidectl/internal/pkg/config" | ||
cmdcontext "github.com/cofide/cofidectl/pkg/cmd/context" | ||
"github.com/cofide/cofidectl/pkg/plugin" | ||
"github.com/cofide/cofidectl/pkg/plugin/datasource" | ||
"github.com/cofide/cofidectl/pkg/plugin/local" | ||
"github.com/cofide/cofidectl/pkg/plugin/provision" | ||
"github.com/cofide/cofidectl/pkg/plugin/provision/spirehelm" | ||
"github.com/hashicorp/go-hclog" | ||
go_plugin "github.com/hashicorp/go-plugin" | ||
) | ||
|
||
const ( | ||
cofideConfigFile = "cofide.yaml" | ||
) | ||
|
||
func main() { | ||
log.SetFlags(0) | ||
if err := run(); err != nil { | ||
// This should be the only place that calls os.Exit, to ensure proper clean up. | ||
// This includes functions that call os.Exit, e.g. cobra.CheckErr, log.Fatal | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func run() error { | ||
cmdCtx := cmdcontext.NewCommandContext(cofideConfigFile) | ||
defer cmdCtx.Shutdown() | ||
go cmdCtx.HandleSignals() | ||
|
||
// If the CLI is invoked with arguments plugin serve, the gRPC plugins are served. | ||
if plugin.IsPluginServeCmd(os.Args[1:]) { | ||
return serveDataSource() | ||
} | ||
return fmt.Errorf("unexpected command arguments: %v", os.Args[1:]) | ||
} | ||
|
||
func serveDataSource() error { | ||
// go-plugin client expects logs on stdout. | ||
log.SetOutput(os.Stdout) | ||
|
||
logger := hclog.New(&hclog.LoggerOptions{ | ||
Output: os.Stderr, | ||
// Log at trace level in the plugin, it will be filtered in the host. | ||
Level: hclog.Trace, | ||
JSONFormat: true, | ||
}) | ||
|
||
lds, err := local.NewLocalDataSource(config.NewFileLoader(cofideConfigFile)) | ||
if err != nil { | ||
return err | ||
} | ||
spireHelm := spirehelm.NewSpireHelm(nil) | ||
|
||
go_plugin.Serve(&go_plugin.ServeConfig{ | ||
HandshakeConfig: plugin.HandshakeConfig, | ||
Plugins: map[string]go_plugin.Plugin{ | ||
datasource.DataSourcePluginName: &datasource.DataSourcePlugin{Impl: lds}, | ||
provision.ProvisionPluginName: &provision.ProvisionPlugin{Impl: spireHelm}, | ||
}, | ||
Logger: logger, | ||
GRPCServer: go_plugin.DefaultGRPCServer, | ||
}) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import ( | |
"fmt" | ||
"os" | ||
|
||
pluginspb "github.com/cofide/cofide-api-sdk/gen/go/proto/plugins/v1alpha1" | ||
"github.com/cofide/cofidectl/pkg/cmd/context" | ||
"github.com/cofide/cofidectl/pkg/plugin" | ||
"github.com/cofide/cofidectl/pkg/plugin/manager" | ||
|
@@ -33,7 +34,9 @@ directory | |
` | ||
|
||
type Opts struct { | ||
enableConnect bool | ||
enableConnect bool | ||
dataSourcePlugin string | ||
provisionPlugin string | ||
} | ||
|
||
func (i *InitCommand) GetRootCommand() *cobra.Command { | ||
|
@@ -44,26 +47,28 @@ func (i *InitCommand) GetRootCommand() *cobra.Command { | |
Long: initRootCmdDesc, | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var pluginName string | ||
if opts.enableConnect { | ||
if ok, _ := plugin.PluginExists(connectPluginName); ok { | ||
pluginName = connectPluginName | ||
fmt.Println(`Please run "cofidectl connect init"`) | ||
} else { | ||
fmt.Println("👀 get in touch with us at [email protected] to find out more") | ||
os.Exit(1) | ||
} | ||
} else { | ||
// Default to the local file data source. | ||
pluginName = manager.LocalPluginName | ||
os.Exit(1) | ||
} | ||
|
||
_, err := i.cmdCtx.PluginManager.Init(pluginName, nil) | ||
return err | ||
plugins := &pluginspb.Plugins{ | ||
DataSource: &opts.dataSourcePlugin, | ||
Provision: &opts.provisionPlugin, | ||
} | ||
return i.cmdCtx.PluginManager.Init(cmd.Context(), plugins, nil) | ||
}, | ||
} | ||
|
||
defaultPlugins := manager.GetDefaultPlugins() | ||
f := cmd.Flags() | ||
f.BoolVar(&opts.enableConnect, "enable-connect", false, "Enables Cofide Connect") | ||
f.StringVar(&opts.dataSourcePlugin, "data-source-plugin", defaultPlugins.GetDataSource(), "Data source plugin") | ||
f.StringVar(&opts.provisionPlugin, "provision-plugin", defaultPlugins.GetProvision(), "Provision plugin") | ||
|
||
return cmd | ||
} |
Oops, something went wrong.