Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a3276e4
add YamlPlugin
smarchone Jul 20, 2022
8b90a90
add yamlMod in models.Plugin
smarchone Jul 26, 2022
bcbb190
fix plugin fallback (first bin else yaml)
smarchone Jul 26, 2022
6a64e60
add default assets in yaml plugin
smarchone Jul 26, 2022
89b32ad
add validations
smarchone Jul 27, 2022
7eaa34a
add default config
smarchone Jul 27, 2022
0a9dd58
add sortplugins; dir (.plugins); migratePlugins
smarchone Jul 28, 2022
9372d12
fix: lint, remove yamlpluginrepo
smarchone Aug 1, 2022
d555c1c
add DefaultConfig, fix lint, sort plugin multiselect in survey
smarchone Aug 2, 2022
5faef85
add validations, remove defaultconfig
smarchone Aug 4, 2022
a927fe6
add job hook from yaml
smarchone Aug 4, 2022
2733060
add plugin validation (init & model)
smarchone Aug 8, 2022
d64fc33
fix lint
smarchone Aug 8, 2022
d622028
add defaultconfig; log yaml plugin in validation
smarchone Aug 8, 2022
7feaa80
refactor pluginMod; make validations strict
smarchone Aug 9, 2022
2fa0bfb
refactor and add tests
smarchone Aug 9, 2022
29b1b00
add/fix tests
smarchone Aug 10, 2022
b29daba
fix lint
smarchone Aug 10, 2022
738e877
add version override in yaml; add review changes
smarchone Aug 16, 2022
cb7fd66
review changes
smarchone Aug 17, 2022
3740f7f
fix rebase
smarchone Aug 25, 2022
d031090
fix : feedback
smarchone Aug 25, 2022
5120902
feat : cli syncs yaml plugins from server (#530)
smarchone Sep 1, 2022
675110b
fix: remove pluginversion override; --print; and IYamlmod naming
smarchone Sep 1, 2022
10507bf
fix: remove pluginversion override; --print; and IYamlmod naming (#554)
smarchone Sep 2, 2022
8a84ad6
fix error on sync without project
smarchone Sep 2, 2022
8c1cd86
fix error msg
smarchone Sep 2, 2022
e68e31e
minor display fix in cmd
smarchone Sep 2, 2022
8a87f8d
exit with status 1 on plugin validation
smarchone Sep 6, 2022
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ __pycache__
optimus.yaml
config.yaml
coverage.txt

.plugins
yaml-plugins.zip
/api/proto/odpf/**/*

!/api/proto/odpf/optimus/
Expand Down
2 changes: 1 addition & 1 deletion cmd/internal/survey/job_addhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (j *JobAddHookSurvey) AskToAddHook(jobSpec models.JobSpec, pluginRepo model
}

var jobSpecConfigs models.JobSpecConfigs
if cliMod := selectedHook.CLIMod; cliMod != nil {
if cliMod := selectedHook.GetSurveyMod(); cliMod != nil {
ctx := context.Background()
hookAnswers, err := j.askHookQuestions(ctx, cliMod, jobSpec.Name)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions cmd/internal/survey/job_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ func (*JobCreateSurvey) getTaskConfig(cliMod models.CommandLineMod, answers mode

func (*JobCreateSurvey) getAvailableTaskNames() []string {
pluginRepo := models.PluginRegistry
plugins := pluginRepo.GetTasks()
var output []string
for _, task := range pluginRepo.GetTasks() {
for _, task := range plugins {
output = append(output, task.Info().Name)
}
return output
Expand Down Expand Up @@ -215,11 +216,11 @@ func (j *JobCreateSurvey) askCreateQuestions(questions []*survey.Question) (loca

func (*JobCreateSurvey) getPluginCLIMod(taskName string) (models.CommandLineMod, error) {
pluginRepo := models.PluginRegistry
executionTask, err := pluginRepo.GetByName(taskName)
plugin, err := pluginRepo.GetByName(taskName)
if err != nil {
return nil, err
}
return executionTask.CLIMod, nil
return plugin.GetSurveyMod(), nil
}

func (j *JobCreateSurvey) askPluginQuestions(cliMod models.CommandLineMod, jobName string) (models.PluginAnswers, error) {
Expand Down
32 changes: 15 additions & 17 deletions cmd/plugin/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,39 @@ import (

"github.com/odpf/optimus/cmd/internal/logger"
"github.com/odpf/optimus/config"
"github.com/odpf/optimus/plugin"
)

type installCommand struct {
logger log.Logger
serverConfig *config.ServerConfig
logger log.Logger
serverConfig *config.ServerConfig
configFilePath string `default:"config.yaml"`
}

// NewInstallCommand initializes plugin install command
func NewInstallCommand(serverConfig *config.ServerConfig) *cobra.Command {
install := &installCommand{
serverConfig: serverConfig,
}
func NewInstallCommand() *cobra.Command {
install := &installCommand{}
cmd := &cobra.Command{
Use: "install",
Short: "install and extract plugins to a dir",
Short: "download and extract plugins to a dir (on server)",
Example: "optimus plugin install",
RunE: install.RunE,
PreRunE: install.PreRunE,
}
cmd.PersistentFlags().StringVarP(&install.configFilePath, "config", "c", install.configFilePath, "File path for server configuration")
return cmd
}

func (i *installCommand) PreRunE(_ *cobra.Command, _ []string) error {
i.logger = logger.NewClientLogger(i.serverConfig.Log)
c, err := config.LoadServerConfig(i.configFilePath)
if err != nil {
return err
}
i.serverConfig = c
i.logger = logger.NewClientLogger(c.Log)
return nil
}

// also used during server start
func InstallPlugins(conf *config.ServerConfig, logger log.Logger) error {
dst := conf.Plugin.Dir
sources := conf.Plugin.Artifacts
pluginManger := NewPluginManager(logger)
return pluginManger.Install(dst, sources...)
}

func (i *installCommand) RunE(_ *cobra.Command, _ []string) error {
return InstallPlugins(i.serverConfig, i.logger)
return plugin.InstallPlugins(i.serverConfig)
}
31 changes: 7 additions & 24 deletions cmd/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,22 @@ import (
oPlugin "github.com/odpf/optimus/plugin"
)

type pluginCommand struct {
configFilePath string
serverConfig *config.ServerConfig
}

// NewPluginCommand initializes command for plugin
func NewPluginCommand() *cobra.Command {
plugin := pluginCommand{
serverConfig: &config.ServerConfig{},
}
cmd := &cobra.Command{
Use: "plugin",
Short: "Manage plugins",
Hidden: true,
Use: "plugin",
Short: "Manage plugins",
Annotations: map[string]string{
"group:dev": "true",
},
PersistentPreRunE: plugin.PersistentPreRunE,
}
cmd.PersistentFlags().StringVarP(&plugin.configFilePath, "config", "c", plugin.configFilePath, "File path for server configuration")
cmd.AddCommand(NewInstallCommand(plugin.serverConfig))
cmd.AddCommand(
NewInstallCommand(),
NewValidateCommand(),
NewSyncCommand(),
)
return cmd
}

func (p *pluginCommand) PersistentPreRunE(_ *cobra.Command, _ []string) error {
c, err := config.LoadServerConfig(p.configFilePath)
if err != nil {
return err
}
*p.serverConfig = *c
return nil
}

// TriggerClientPluginsInit triggers initialization of all available plugins
func TriggerClientPluginsInit(logLevel config.LogLevel) (cleanFn func(), err error) {
pluginLogLevel := hclog.Info
Expand Down
60 changes: 0 additions & 60 deletions cmd/plugin/plugin_manager.go

This file was deleted.

103 changes: 103 additions & 0 deletions cmd/plugin/sync.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package plugin

import (
"context"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"os"
"strings"

"github.com/odpf/salt/log"
"github.com/spf13/cobra"

"github.com/odpf/optimus/cmd/internal/logger"
"github.com/odpf/optimus/config"
"github.com/odpf/optimus/plugin"
)

func NewSyncCommand() *cobra.Command {
sync := &syncCommand{}
cmd := &cobra.Command{
Use: "sync",
Short: "sync plugins from server",
Example: "optimus plugin sync -c optimus.yaml",
PreRunE: sync.PreRunE,
RunE: sync.RunE,
}
cmd.PersistentFlags().StringVarP(&sync.configFilePath, "config", "c", sync.configFilePath, "File path for optimus configuration")
return cmd
}

type syncCommand struct {
configFilePath string
clientConfig *config.ClientConfig
logger log.Logger
}

func (s *syncCommand) PreRunE(_ *cobra.Command, _ []string) error {
c, err := config.LoadClientConfig(s.configFilePath)
if err != nil {
return errors.New("project not initialized or error in loading config : \n" + err.Error())
}
s.clientConfig = c
s.logger = logger.NewClientLogger(c.Log)
return nil
}

func getPluginDownloadURL(host string) (*url.URL, error) {
var downloadURL *url.URL
var err error
pluginPath := "plugins"
if strings.HasPrefix(host, "http://") || strings.HasPrefix(host, "https://") {
downloadURL, err = url.Parse(host)
if err != nil {
return nil, err
}
downloadURL.Path = pluginPath
} else {
downloadURL = &url.URL{
Scheme: "http",
Host: host,
Path: pluginPath,
}
}
return downloadURL, nil
}

func (s *syncCommand) downloadArchiveFromServer() error {
downloadURL, err := getPluginDownloadURL(s.clientConfig.Host)
s.logger.Info(fmt.Sprintf("download URL : %s", downloadURL.String()))
if err != nil {
return err
}
req, err := http.NewRequestWithContext(context.Background(), "GET", downloadURL.String(), nil)
if err != nil {
return err
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
out, err := os.Create(plugin.PluginsArchiveName)
if err != nil {
return err
}
defer out.Close()
_, err = io.Copy(out, resp.Body)
return err
}

func (s *syncCommand) RunE(_ *cobra.Command, _ []string) error {
err := s.downloadArchiveFromServer()
if err != nil {
return err
}
return plugin.NewPluginManager().UnArchive(
plugin.PluginsArchiveName,
plugin.PluginsDir,
)
}
Loading