Skip to content

Commit

Permalink
Merge pull request #213 from intelops/add-license-related-changes
Browse files Browse the repository at this point in the history
feat: added license related changes from metadata
  • Loading branch information
mahendraintelops authored Apr 21, 2024
2 parents e32c008 + 124efc2 commit 8728f7d
Show file tree
Hide file tree
Showing 27 changed files with 278 additions and 159 deletions.
12 changes: 6 additions & 6 deletions api/v1/project.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ service ProjectService {
}

message GenerateCodeRequest {
string projectVersion = 1;
string compageCoreVersion = 1;
string projectName = 2;
string projectJSON = 3;
string gitRepositoryName = 4;
string gitPlatformName = 5;
string gitPlatformURL = 6;
string gitPlatformUserName = 7;
string projectMetadata = 8;
string projectMetadata = 4;
string gitRepositoryName = 5;
string gitPlatformName = 6;
string gitPlatformURL = 7;
string gitPlatformUserName = 8;
}

message GenerateCodeResponse{
Expand Down
2 changes: 1 addition & 1 deletion cmd/dotnet-config.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: {{.ProjectName}}
version: v1.0.0
compageCoreVersion: v1.0.0
git:
repository:
name: {{.GitRepositoryName}}
Expand Down
72 changes: 57 additions & 15 deletions cmd/generate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"encoding/json"
ociregistry "github.com/intelops/compage/cmd/artifacts"
"github.com/intelops/compage/cmd/models"
"github.com/intelops/compage/internal/converter/cmd"
Expand Down Expand Up @@ -62,38 +63,79 @@ func GenerateCode() error {
return err
}

if len(coreProject.License.Path) > 0 {
// assign absolute path to the license file Path if it's not
absPath, err := filepath.Abs(coreProject.License.Path)
if err != nil {
log.Errorf("error while getting absolute path [" + err.Error() + "]")
return err
if project.Metadata != nil {
license := &models.License{}
l, ok := project.Metadata["license"]
if ok {
// convert the license data to byte array
licenseData, err1 := json.Marshal(l)
if err1 != nil {
log.Errorf("error while marshalling license data [" + err1.Error() + "]")
return err1
}
// convert the license data to license struct
err1 = json.Unmarshal(licenseData, license)
if err1 != nil {
log.Errorf("error while unmarshalling license data [" + err1.Error() + "]")
return err1
}
// assign absolute path to the license file Path if it's not set
if len(license.Path) > 0 {
// assign absolute path to the license file Path if it's not
absPath, err2 := filepath.Abs(license.Path)
if err2 != nil {
log.Errorf("error while getting absolute path [" + err2.Error() + "]")
return err2
}
license.Path = absPath
}
project.Metadata["license"] = license
} else {
log.Warn("license data not found in project metadata")
}
coreProject.License.Path = absPath
}

// assign absolute path to the license file path if it's not (if supplied for the nodes)
for _, node := range coreProject.CompageJSON.Nodes {
if len(node.License.Path) > 0 {
absPath, err := filepath.Abs(node.License.Path)
if err != nil {
log.Errorf("error while getting absolute path [" + err.Error() + "]")
return err
license := &models.License{}
l, ok := node.Metadata["license"]
if ok {
// convert the license data to byte array
licenseData, err1 := json.Marshal(l)
if err1 != nil {
log.Errorf("error while marshalling license data [" + err1.Error() + "]")
return err1
}
// convert the license data to license struct
err1 = json.Unmarshal(licenseData, license)
if err1 != nil {
log.Errorf("error while unmarshalling license data [" + err1.Error() + "]")
return err1
}
// assign absolute path to the license file Path if it's not set
if len(license.Path) > 0 {
// assign absolute path to the license file Path if it's not
absPath, err2 := filepath.Abs(license.Path)
if err2 != nil {
log.Errorf("error while getting absolute path [" + err2.Error() + "]")
return err2
}
license.Path = absPath
}
node.License.Path = absPath
node.Metadata["license"] = license
}
}

// pull all required templates
// pull the common templates
err = ociregistry.PullOCIArtifact("common", project.Version)
err = ociregistry.PullOCIArtifact("common", project.CompageCoreVersion)
if err != nil {
log.Errorf("error while pulling the common templates [" + err.Error() + "]")
return err
}
for _, node := range coreProject.CompageJSON.Nodes {
// make sure that the latest template is pulled
err = ociregistry.PullOCIArtifact(node.Language, project.Version)
err = ociregistry.PullOCIArtifact(node.Language, project.CompageCoreVersion)
if err != nil {
log.Errorf("error while pulling the template [" + err.Error() + "]")
return err
Expand Down
2 changes: 1 addition & 1 deletion cmd/go-config.yaml.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: {{.ProjectName}}
version: v1.0.0
compageCoreVersion: v1.0.0
git:
repository:
name: {{.GitRepositoryName}}
Expand Down
17 changes: 8 additions & 9 deletions cmd/models/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,17 @@ type GitDetails struct {
}

type License struct {
Name string `yaml:"name,omitempty"`
URL string `yaml:"url,omitempty"`
Path string `yaml:"path,omitempty"`
Name string `yaml:"name,omitempty" json:"name,omitempty"`
URL string `yaml:"url,omitempty" json:"url,omitempty"`
Path string `yaml:"path,omitempty" json:"path,omitempty"`
}

type Project struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
License License `yaml:"license"`
GitDetails GitDetails `yaml:"git"`
CompageJSON map[string]interface{} `yaml:"compageJSON"`
ProjectMetadata string `yaml:"projectMetadata"`
Name string `yaml:"name"`
CompageCoreVersion string `yaml:"compageCoreVersion"`
GitDetails GitDetails `yaml:"git"`
CompageJSON map[string]interface{} `yaml:"compageJSON"`
Metadata map[string]interface{} `yaml:"metadata"`
}

func ReadConfigYAMLFile(configFile string) (*Project, error) {
Expand Down
29 changes: 17 additions & 12 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,33 @@ This command will start thr gRPC server and allow the gRPC clients to get connec

// this will be the version same as release (as the version is not configurable from the ui)
// for local development, you can set the version in the environment variable
version := os.Getenv("COMPAGE_CORE_VERSION")
if version == "" {
compageCoreVersion := os.Getenv("COMPAGE_CORE_VERSION")
if compageCoreVersion == "" {
// default version
version = "v1.0.0"
compageCoreVersion = "v1.0.0"
err := os.Setenv("COMPAGE_CORE_VERSION", compageCoreVersion)
if err != nil {
log.Errorf("error while setting environment variable COMPAGE_CORE_VERSION [%v]", err)
return
}
}
err := ociregistry.PullOCIArtifact("common", version)
err := ociregistry.PullOCIArtifact("common", compageCoreVersion)
cobra.CheckErr(err)
err = ociregistry.PullOCIArtifact("go", version)
err = ociregistry.PullOCIArtifact("go", compageCoreVersion)
cobra.CheckErr(err)
err = ociregistry.PullOCIArtifact("python", version)
err = ociregistry.PullOCIArtifact("python", compageCoreVersion)
cobra.CheckErr(err)
err = ociregistry.PullOCIArtifact("java", version)
err = ociregistry.PullOCIArtifact("java", compageCoreVersion)
cobra.CheckErr(err)
err = ociregistry.PullOCIArtifact("javascript", version)
err = ociregistry.PullOCIArtifact("javascript", compageCoreVersion)
cobra.CheckErr(err)
err = ociregistry.PullOCIArtifact("ruby", version)
err = ociregistry.PullOCIArtifact("ruby", compageCoreVersion)
cobra.CheckErr(err)
err = ociregistry.PullOCIArtifact("rust", version)
err = ociregistry.PullOCIArtifact("rust", compageCoreVersion)
cobra.CheckErr(err)
err = ociregistry.PullOCIArtifact("typescript", version)
err = ociregistry.PullOCIArtifact("typescript", compageCoreVersion)
cobra.CheckErr(err)
err = ociregistry.PullOCIArtifact("dotnet", version)
err = ociregistry.PullOCIArtifact("dotnet", compageCoreVersion)
cobra.CheckErr(err)

// check if the language templates have been pulled (mainly need to check this on developer's machine)
Expand Down
112 changes: 56 additions & 56 deletions gen/api/v1/project.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions internal/converter/cmd/converter.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cmd

import (
"github.com/intelops/compage/internal/converter"
log "github.com/sirupsen/logrus"
"time"

"github.com/intelops/compage/cmd/models"
"github.com/intelops/compage/internal/converter"
"github.com/intelops/compage/internal/core"
)

Expand All @@ -20,14 +20,13 @@ func GetProject(input *models.Project) (*core.Project, error) {
return &core.Project{
CompageJSON: compageJSON,
Name: input.Name,
Version: input.Version,
License: &input.License,
CompageCoreVersion: input.CompageCoreVersion,
GitPlatformName: input.GitDetails.Platform.Name,
GitPlatformURL: input.GitDetails.Platform.URL,
GitPlatformUserName: input.GitDetails.Platform.UserName,
GitRepositoryName: input.GitDetails.Repository.Name,
GitRepositoryURL: input.GitDetails.Repository.URL,
Metadata: converter.GetMetadata(input.ProjectMetadata),
Metadata: input.Metadata,
ModificationDetails: core.ModificationDetails{
CreatedBy: input.GitDetails.Platform.UserName,
UpdatedBy: input.GitDetails.Platform.UserName,
Expand Down
Loading

0 comments on commit 8728f7d

Please sign in to comment.