Skip to content

Commit e32c008

Browse files
Merge pull request #212 from intelops/add-license-per-node
Add license per node
2 parents 23f0f17 + 283b0a4 commit e32c008

File tree

15 files changed

+246
-12
lines changed

15 files changed

+246
-12
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"mode": "debug",
99
"program": "${workspaceRoot}/main.go",
1010
"cwd": "${workspaceRoot}",
11-
"args": ["pullTemplates"]
11+
"args": ["generate"]
1212
}
1313
]
1414
}

cmd/generate.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
log "github.com/sirupsen/logrus"
1010
"github.com/spf13/cobra"
1111
"os"
12+
"path/filepath"
1213
)
1314

1415
// generateCmd represents the generate command
@@ -61,6 +62,28 @@ func GenerateCode() error {
6162
return err
6263
}
6364

65+
if len(coreProject.License.Path) > 0 {
66+
// assign absolute path to the license file Path if it's not
67+
absPath, err := filepath.Abs(coreProject.License.Path)
68+
if err != nil {
69+
log.Errorf("error while getting absolute path [" + err.Error() + "]")
70+
return err
71+
}
72+
coreProject.License.Path = absPath
73+
}
74+
75+
// assign absolute path to the license file path if it's not (if supplied for the nodes)
76+
for _, node := range coreProject.CompageJSON.Nodes {
77+
if len(node.License.Path) > 0 {
78+
absPath, err := filepath.Abs(node.License.Path)
79+
if err != nil {
80+
log.Errorf("error while getting absolute path [" + err.Error() + "]")
81+
return err
82+
}
83+
node.License.Path = absPath
84+
}
85+
}
86+
6487
// pull all required templates
6588
// pull the common templates
6689
err = ociregistry.PullOCIArtifact("common", project.Version)

cmd/models/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ type GitDetails struct {
2222
Platform Platform `yaml:"platform,omitempty"`
2323
}
2424

25+
type License struct {
26+
Name string `yaml:"name,omitempty"`
27+
URL string `yaml:"url,omitempty"`
28+
Path string `yaml:"path,omitempty"`
29+
}
30+
2531
type Project struct {
2632
Name string `yaml:"name"`
2733
Version string `yaml:"version"`
34+
License License `yaml:"license"`
2835
GitDetails GitDetails `yaml:"git"`
2936
CompageJSON map[string]interface{} `yaml:"compageJSON"`
3037
ProjectMetadata string `yaml:"projectMetadata"`

internal/converter/cmd/converter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func GetProject(input *models.Project) (*core.Project, error) {
2121
CompageJSON: compageJSON,
2222
Name: input.Name,
2323
Version: input.Version,
24+
License: &input.License,
2425
GitPlatformName: input.GitDetails.Platform.Name,
2526
GitPlatformURL: input.GitDetails.Platform.URL,
2627
GitPlatformUserName: input.GitDetails.Platform.UserName,

internal/core/models.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package core
22

33
import (
4+
"github.com/intelops/compage/cmd/models"
45
coreedge "github.com/intelops/compage/internal/core/edge"
56
corenode "github.com/intelops/compage/internal/core/node"
67
"time"
@@ -19,6 +20,7 @@ type ModificationDetails struct {
1920
type Project struct {
2021
Name string `json:"name"`
2122
Version string `json:"version"`
23+
License *models.License `json:"license"`
2224
CompageJSON *CompageJSON `json:"compageJSON"`
2325
GitRepositoryName string `json:"gitRepositoryName"`
2426
GitRepositoryURL string `json:"gitRepositoryURL"`

internal/core/node/node.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ type Node struct {
77
Language string `json:"language"`
88
// Name of a component (required, this will be service and deployment name).
99
Name string `json:"name"`
10+
// License of the component.
11+
License *License `json:"license"`
1012
// RestConfig holds all config related to REST. If nil, it means that the node is not REST server or has REST clients.
1113
RestConfig *RestConfig `json:"restConfig,omitempty"`
1214
// GrpcConfig holds all config related to gRPC. If nil, it means that the node is not gRPC server or has gRPC clients.
@@ -19,6 +21,12 @@ type Node struct {
1921
Annotations map[string]string `json:"annotations,omitempty"`
2022
}
2123

24+
type License struct {
25+
Name string `yaml:"name,omitempty"`
26+
URL string `yaml:"url,omitempty"`
27+
Path string `yaml:"path,omitempty"`
28+
}
29+
2230
type RestServer struct {
2331
Port string `json:"port"`
2432
SQLDB string `json:"sqlDB"`

internal/integrations/deepsource/copier.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ type Copier struct {
1818
}
1919

2020
func NewCopier(project *core.Project) (*Copier, error) {
21-
// retrieve project named directory
22-
//gitPlatformUserName, gitRepositoryName, projectDirectoryName, templatesRootPath string
2321
// populate map to replace templates
2422
data := map[string]interface{}{
2523
"GitRepositoryName": project.GitRepositoryName,

internal/integrations/license/copier.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package license
22

33
import (
4+
"github.com/intelops/compage/cmd/models"
45
"github.com/intelops/compage/internal/core"
56
"github.com/intelops/compage/internal/languages/executor"
67
"github.com/intelops/compage/internal/utils"
@@ -14,12 +15,11 @@ type Copier struct {
1415
ProjectDirectoryName string
1516
GitRepositoryName string
1617
TemplatesRootPath string
18+
License *models.License
1719
Data map[string]interface{}
1820
}
1921

2022
func NewCopier(project *core.Project) (*Copier, error) {
21-
// retrieve project named directory
22-
//gitPlatformUserName, gitRepositoryName, projectDirectoryName, templatesRootPath string
2323
// populate map to replace templates
2424
data := map[string]interface{}{
2525
"GitRepositoryName": project.GitRepositoryName,
@@ -37,6 +37,7 @@ func NewCopier(project *core.Project) (*Copier, error) {
3737
ProjectDirectoryName: utils.GetProjectDirectoryName(project.Name),
3838
GitRepositoryName: project.GitRepositoryName,
3939
Data: data,
40+
License: project.License,
4041
}, nil
4142
}
4243

@@ -47,7 +48,22 @@ func (c Copier) CreateLicenseFiles() error {
4748
log.Errorf("error while creating directories [" + err.Error() + "]")
4849
return err
4950
}
50-
51+
// copy license file if it's been supplied
52+
if c.License != nil && len(c.License.URL) > 0 {
53+
// read file from url in c.License.URL. This is applicable for both config.yaml file and ui flow.
54+
return utils.DownloadFile(c.ProjectDirectoryName+"/LICENCE", c.License.URL)
55+
} else if c.License != nil && len(c.License.Path) > 0 {
56+
// local license file sent via config.yaml file.
57+
// get the absolute path of the license file
58+
_, err := utils.CopyFile(c.ProjectDirectoryName+"/LICENCE", c.License.Path)
59+
if err != nil {
60+
log.Errorf("error while copying file [" + err.Error() + "]")
61+
return err
62+
}
63+
// return from here as the license file has been copied
64+
return nil
65+
}
66+
// copy license file from templates (the default one)
5167
var filePaths []*string
5268
// copy deployment files to generated license config files
5369
targetLicenseFileName := c.ProjectDirectoryName + "/" + File

internal/integrations/readme/copier.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ type Copier struct {
1818
}
1919

2020
func NewCopier(project *core.Project) (*Copier, error) {
21-
// retrieve project named directory
22-
//gitPlatformUserName, gitRepositoryName, projectDirectoryName, templatesRootPath string
2321
// populate map to replace templates
2422
data := map[string]interface{}{
2523
"GitRepositoryName": project.GitRepositoryName,

internal/languages/dotnet/generator.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/intelops/compage/internal/languages/dotnet/integrations/docker"
1212
"github.com/intelops/compage/internal/languages/dotnet/integrations/githubactions"
1313
"github.com/intelops/compage/internal/languages/dotnet/integrations/kubernetes"
14+
"github.com/intelops/compage/internal/languages/dotnet/integrations/license"
1415
"github.com/intelops/compage/internal/languages/templates"
1516
"github.com/intelops/compage/internal/utils"
1617
log "github.com/sirupsen/logrus"
@@ -113,6 +114,14 @@ func generateIntegrationConfig(dotNetValues *DotNetValues) error {
113114
log.Errorf("error while getting the integrations copier [" + err.Error() + "]")
114115
return err
115116
}
117+
118+
// license files need to be generated for the whole project so, it should be here.
119+
licenseCopier := m["license"].(*license.Copier)
120+
if err = licenseCopier.CreateLicenseFiles(); err != nil {
121+
log.Errorf("err : %s", err)
122+
return err
123+
}
124+
116125
// dockerfile needs to be generated for the whole project, so it should be here.
117126
dockerCopier := m["docker"].(*docker.Copier)
118127
if err = dockerCopier.CreateDockerFile(); err != nil {
@@ -159,6 +168,9 @@ func getIntegrationsCopier(dotNetValues *DotNetValues) (map[string]interface{},
159168
restServerPort = ""
160169
}
161170

171+
// create dotnet specific licenseCopier
172+
licenseCopier := license.NewCopier(gitPlatformUserName, gitRepositoryName, nodeName, nodeDirectoryName, dotNetTemplatesRootPath, dotNetValues.LDotNetLangNode.License)
173+
162174
// create dotnet specific dockerCopier
163175
dockerCopier := docker.NewCopier(gitPlatformUserName, gitRepositoryName, nodeName, nodeDirectoryName, dotNetTemplatesRootPath, isRestServer, restServerPort)
164176

@@ -172,5 +184,6 @@ func getIntegrationsCopier(dotNetValues *DotNetValues) (map[string]interface{},
172184
"docker": dockerCopier,
173185
"k8s": k8sCopier,
174186
"githubActions": githubActionsCopier,
187+
"license": licenseCopier,
175188
}, nil
176189
}

0 commit comments

Comments
 (0)