Browse Source

fix the way we're checking if the provider metadata are empty or not

Signed-off-by: Guillaume Lours <[email protected]>
Guillaume Lours 5 months ago
parent
commit
c626befee1
1 changed files with 13 additions and 3 deletions
  1. 13 3
      pkg/compose/plugins.go

+ 13 - 3
pkg/compose/plugins.go

@@ -170,7 +170,7 @@ func (s *composeService) getPluginBinaryPath(provider string) (path string, err
 }
 
 func (s *composeService) setupPluginCommand(ctx context.Context, project *types.Project, service types.ServiceConfig, path, command string) (*exec.Cmd, error) {
-	cmdOptionsMetadata := s.getPluginMetadata(path, service.Provider.Type)
+	cmdOptionsMetadata := s.getPluginMetadata(path, service.Provider.Type, project)
 	var currentCommandMetadata CommandMetadata
 	switch command {
 	case "up":
@@ -178,8 +178,9 @@ func (s *composeService) setupPluginCommand(ctx context.Context, project *types.
 	case "down":
 		currentCommandMetadata = cmdOptionsMetadata.Down
 	}
-	commandMetadataIsEmpty := len(currentCommandMetadata.Parameters) == 0
+
 	provider := *service.Provider
+	commandMetadataIsEmpty := cmdOptionsMetadata.IsEmpty()
 	if err := currentCommandMetadata.CheckRequiredParameters(provider); !commandMetadataIsEmpty && err != nil {
 		return nil, err
 	}
@@ -203,8 +204,13 @@ func (s *composeService) setupPluginCommand(ctx context.Context, project *types.
 	return cmd, nil
 }
 
-func (s *composeService) getPluginMetadata(path, command string) ProviderMetadata {
+func (s *composeService) getPluginMetadata(path, command string, project *types.Project) ProviderMetadata {
 	cmd := exec.Command(path, "compose", "metadata")
+	err := s.prepareShellOut(context.Background(), project, cmd)
+	if err != nil {
+		logrus.Debugf("failed to prepare plugin metadata command: %v", err)
+		return ProviderMetadata{}
+	}
 	stdout := &bytes.Buffer{}
 	cmd.Stdout = stdout
 
@@ -239,6 +245,10 @@ type ProviderMetadata struct {
 	Down        CommandMetadata `json:"down"`
 }
 
+func (p ProviderMetadata) IsEmpty() bool {
+	return p.Description == "" && p.Up.Parameters == nil && p.Down.Parameters == nil
+}
+
 type CommandMetadata struct {
 	Parameters []ParameterMetadata `json:"parameters"`
 }