Procházet zdrojové kódy

fix: use primary vhost if hostname not sent

ntorga před 1 rokem
rodič
revize
b571c608ee

+ 4 - 3
src/presentation/cli/controller/marketplace.go

@@ -82,8 +82,10 @@ func (controller *MarketplaceController) InstallCatalogItem() *cobra.Command {
 		Use:   "install",
 		Short: "InstallCatalogItem",
 		Run: func(cmd *cobra.Command, args []string) {
-			requestBody := map[string]interface{}{
-				"hostname": hostnameStr,
+			requestBody := map[string]interface{}{}
+
+			if hostnameStr != "" {
+				requestBody["hostname"] = hostnameStr
 			}
 
 			if catalogIdInt != 0 {
@@ -111,7 +113,6 @@ func (controller *MarketplaceController) InstallCatalogItem() *cobra.Command {
 	}
 
 	cmd.Flags().StringVarP(&hostnameStr, "hostname", "n", "", "VirtualHostName")
-	cmd.MarkFlagRequired("hostname")
 	cmd.Flags().IntVarP(&catalogIdInt, "catalogId", "i", 0, "CatalogItemId")
 	cmd.Flags().StringVarP(&slugStr, "slug", "s", "", "CatalogItemSlug")
 	cmd.Flags().StringVarP(&urlPath, "urlPath", "d", "", "UrlPath")

+ 13 - 11
src/presentation/service/marketplace.go

@@ -4,6 +4,7 @@ import (
 	"github.com/speedianet/os/src/domain/dto"
 	"github.com/speedianet/os/src/domain/useCase"
 	"github.com/speedianet/os/src/domain/valueObject"
+	infraHelper "github.com/speedianet/os/src/infra/helper"
 	internalDbInfra "github.com/speedianet/os/src/infra/internalDatabase"
 	marketplaceInfra "github.com/speedianet/os/src/infra/marketplace"
 	vhostInfra "github.com/speedianet/os/src/infra/vhost"
@@ -34,17 +35,18 @@ func (service *MarketplaceService) ReadCatalog() ServiceOutput {
 
 func (service *MarketplaceService) InstallCatalogItem(
 	input map[string]interface{},
+	shouldSchedule bool,
 ) ServiceOutput {
-	requiredParams := []string{"hostname"}
-
-	err := serviceHelper.RequiredParamsInspector(input, requiredParams)
+	hostname, err := infraHelper.GetPrimaryVirtualHost()
 	if err != nil {
-		return NewServiceOutput(UserError, err.Error())
+		return NewServiceOutput(InfraError, err.Error())
 	}
 
-	hostname, err := valueObject.NewFqdn(input["hostname"])
-	if err != nil {
-		return NewServiceOutput(UserError, err.Error())
+	if input["hostname"] != nil {
+		hostname, err = valueObject.NewFqdn(input["hostname"])
+		if err != nil {
+			return NewServiceOutput(UserError, err.Error())
+		}
 	}
 
 	var idPtr *valueObject.MarketplaceItemId
@@ -83,15 +85,15 @@ func (service *MarketplaceService) InstallCatalogItem(
 		}
 	}
 
+	dto := dto.NewInstallMarketplaceCatalogItem(
+		hostname, idPtr, slugPtr, urlPathPtr, dataFields,
+	)
+
 	marketplaceQueryRepo := marketplaceInfra.NewMarketplaceQueryRepo(service.persistentDbSvc)
 	marketplaceCmdRepo := marketplaceInfra.NewMarketplaceCmdRepo(service.persistentDbSvc)
 	vhostQueryRepo := vhostInfra.NewVirtualHostQueryRepo(service.persistentDbSvc)
 	vhostCmdRepo := vhostInfra.NewVirtualHostCmdRepo(service.persistentDbSvc)
 
-	dto := dto.NewInstallMarketplaceCatalogItem(
-		hostname, idPtr, slugPtr, urlPathPtr, dataFields,
-	)
-
 	err = useCase.InstallMarketplaceCatalogItem(
 		marketplaceQueryRepo, marketplaceCmdRepo, vhostQueryRepo, vhostCmdRepo, dto,
 	)