Skip to content

Commit

Permalink
modify ExecuteValidateStacksCmd to handle get remote file
Browse files Browse the repository at this point in the history
  • Loading branch information
haitham911 committed Oct 20, 2024
1 parent e9950fd commit f27f4d5
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion internal/exec/validate_stacks.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package exec

import (
"context"
"fmt"
"os"
"path"
"reflect"
"strings"

"github.com/hashicorp/go-getter"
"github.com/pkg/errors"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -86,11 +89,29 @@ func ValidateStacks(cliConfig schema.CliConfiguration) error {
atmosManifestJsonSchemaFilePath = cliConfig.Schemas.Atmos.Manifest
} else if u.FileExists(atmosManifestJsonSchemaFileAbsPath) {
atmosManifestJsonSchemaFilePath = atmosManifestJsonSchemaFileAbsPath
} else if u.IsURL(cliConfig.Schemas.Atmos.Manifest) {
tempDir := os.TempDir()
fileName, err := u.GetFileNameFromURL(cliConfig.Schemas.Atmos.Manifest)
if err != nil {
return fmt.Errorf("failed to get the file name from the URL '%s': %w", cliConfig.Schemas.Atmos.Manifest, err)
}
atmosManifestJsonSchemaFilePath = path.Join(tempDir, fileName)
client := &getter.Client{
Ctx: context.Background(),
Dst: atmosManifestJsonSchemaFilePath,
Src: cliConfig.Schemas.Atmos.Manifest,
Mode: getter.ClientModeFile,
}
if err = client.Get(); err != nil {
return fmt.Errorf("failed to download the Atmos JSON Schema file '%s' from the URL '%s': %w", fileName, cliConfig.Schemas.Atmos.Manifest, err)
}

} else {
return fmt.Errorf("the Atmos JSON Schema file '%s' does not exist.\n"+
"It can be configured in the 'schemas.atmos.manifest' section in 'atmos.yaml', or provided using the 'ATMOS_SCHEMAS_ATMOS_MANIFEST' "+
"ENV variable or '--schemas-atmos-manifest' command line argument.\n"+
"The path to the schema file should be an absolute path or a path relative to the 'base_path' setting in 'atmos.yaml'.",
"The path to the schema file should be an absolute path or a path relative to the 'base_path' setting in 'atmos.yaml'. \n"+
"Alternatively, the schema file can be downloaded from the provided URL",
cliConfig.Schemas.Atmos.Manifest)
}
}
Expand Down

0 comments on commit f27f4d5

Please sign in to comment.