Skip to content

Commit

Permalink
Update: Reading of OCI URLs for cuemods from a const instead of a .en…
Browse files Browse the repository at this point in the history
…v file

This behaviour is for testing the commands and would be updated to read the URLs for all commands from a .env file
stored in a repo

Signed-off-by: santoshkal <[email protected]>
  • Loading branch information
santoshkal committed Jun 20, 2024
1 parent 471c6d5 commit ac14579
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
13 changes: 6 additions & 7 deletions cmd/cuemod_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"os"

"github.com/intelops/genval/pkg/cuecore"
"github.com/intelops/genval/pkg/oci"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -37,7 +36,7 @@ and provide the directory to --policy flag in cue command.
for validating and generating the Kubernetes resources.
# Curently, available flags for cuemod init are:
--tool=k8s:1.29
--tool=k8s:1.30
--tool=argocd:2.10.4
--tool=tektoncd:0.58.0
--too=crosplane:1.15.0
Expand Down Expand Up @@ -83,11 +82,11 @@ func runInitCmd(cmd *cobra.Command, args []string) error {
if initArgs.tool == "" {
return errors.New("atleast one tool needs to be provided to initialize")
}
desiredTool, ociURL, err := cuecore.ParseTools(initArgs.tool)

ociURL, err := oci.FetchPolicyFromRegistry(initArgs.tool)
if err != nil {
log.Errorf("Error prsing provided tool %s: %v", initArgs.tool, err)
return fmt.Errorf("error fetching module for '%v': %v", initArgs.tool, err)
}
// key := ""
verified, err := oci.VerifyArifact(context.Background(), ociURL, initArgs.key)
if err != nil {
return fmt.Errorf("error varifying artifact: %v", err)
Expand All @@ -106,7 +105,7 @@ func runInitCmd(cmd *cobra.Command, args []string) error {
if input == "y" {
fmt.Println("Proceeding...")

if err := oci.CreateWorkspace(desiredTool, ociURL, initArgs.creds); err != nil {
if err := oci.CreateWorkspace(initArgs.tool, ociURL, initArgs.creds); err != nil {
log.Errorf("Error creating workspace: %v", err)
}
log.Infof("Workspace verified and created")
Expand All @@ -116,7 +115,7 @@ func runInitCmd(cmd *cobra.Command, args []string) error {
} else {
fmt.Println("Invalid input. Please enter 'y' or 'n'.")
}
} else if err := oci.CreateWorkspace(desiredTool, ociURL, initArgs.creds); err != nil {
} else if err := oci.CreateWorkspace(initArgs.tool, ociURL, initArgs.creds); err != nil {
log.Errorf("Error creating workspace: %v", err)
}
return nil
Expand Down
3 changes: 3 additions & 0 deletions pkg/oci/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ const (

URLPrefix = "oci://"

// TODO: Move all the URLs to a .env file to read from
// OCI URLs for Rego policies
DockerfilePolicies = URLPrefix + "ghcr.io/intelops/policyhub/genval/dockerfile_policies:v0.0.1"
InfrafilePolicies = URLPrefix + "ghcr.io/intelops/policyhub/genval/infrafile_policies:v0.0.1"
TerraformPolicies = URLPrefix + "ghcr.io/intelops/policyhub/genval/terraform_policies:v0.0.1"
InputPolicies = URLPrefix + "ghcr.io/intelops/policyhub/genval/input_policies:v0.0.1"
k8sLatestModule = URLPrefix + "ghcr.io/intelops/policyhub/genval/k8s-cuemods:v0.0.1"
)

// FetchPolicyFromRegistry fetches the policy based on the command provided
Expand All @@ -35,6 +37,7 @@ func FetchPolicyFromRegistry(cmd string) (string, error) {
"infrafile": InfrafilePolicies,
"terraform": TerraformPolicies,
"inputPolicy": InputPolicies,
"k8s:1.30": k8sLatestModule,
}

policy, ok := policies[cmd]
Expand Down
3 changes: 1 addition & 2 deletions pkg/oci/ociClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/crane"
"github.com/google/go-containerregistry/pkg/name"
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/remote/transport"
"github.com/intelops/genval/pkg/cuecore"
Expand All @@ -41,7 +40,7 @@ func ParseAnnotations(args []string) (map[string]string, error) {
// CheckTagAndPullArchive checks for provided tag to be available in the remote, if available pulls the archive
// and stores it in the specified directory and retuens an error if encountered.
func CheckTagAndPullArchive(url, tool, creds string, archivePath *os.File) error {
ref, err := name.ParseReference(url)
ref, err := ParseOCIReference(url)
if err != nil {
return fmt.Errorf("error parsing url %s: %v", url, err)
}
Expand Down

0 comments on commit ac14579

Please sign in to comment.