Skip to content

Commit 3e2d6c9

Browse files
feat: added license generation for go
1 parent 2849f22 commit 3e2d6c9

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

internal/languages/golang/generator.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/intelops/compage/internal/languages/golang/integrations/docker"
1515
"github.com/intelops/compage/internal/languages/golang/integrations/githubactions"
1616
"github.com/intelops/compage/internal/languages/golang/integrations/kubernetes"
17+
"github.com/intelops/compage/internal/languages/golang/integrations/license"
1718
"github.com/intelops/compage/internal/languages/templates"
1819
"github.com/intelops/compage/internal/utils"
1920
log "github.com/sirupsen/logrus"
@@ -68,6 +69,14 @@ func generateIntegrationConfig(goValues *GoValues) error {
6869
log.Errorf("error while getting the integrations copier [" + err.Error() + "]")
6970
return err
7071
}
72+
73+
// license files need to be generated for the whole project so, it should be here.
74+
licenseCopier := m["license"].(*license.Copier)
75+
if err = licenseCopier.CreateLicenseFiles(); err != nil {
76+
log.Errorf("err : %s", err)
77+
return err
78+
}
79+
7180
// dockerfile needs to be generated for the whole project, so it should be here.
7281
dockerCopier := m["docker"].(*docker.Copier)
7382
if err = dockerCopier.CreateDockerFile(); err != nil {
@@ -389,6 +398,9 @@ func getIntegrationsCopier(goValues *GoValues) (map[string]interface{}, error) {
389398
projectDirectoryName := utils.GetProjectDirectoryName(goValues.Values.ProjectName)
390399
projectName := goValues.Values.ProjectName
391400

401+
// create dotnet specific licenseCopier
402+
licenseCopier := license.NewCopier(gitPlatformUserName, gitRepositoryName, nodeName, nodeDirectoryName, goTemplatesRootPath, goValues.LGoLangNode.License)
403+
392404
// create golang specific dockerCopier
393405
dockerCopier := docker.NewCopier(gitPlatformUserName, gitRepositoryName, nodeName, nodeDirectoryName, goTemplatesRootPath, isRestServer, restServerPort, isGrpcServer, grpcServerPort)
394406

@@ -405,6 +417,7 @@ func getIntegrationsCopier(goValues *GoValues) (map[string]interface{}, error) {
405417
devContainerCopier := devcontainer.NewCopier(gitPlatformUserName, gitRepositoryName, projectName, nodeName, nodeDirectoryName, goTemplatesRootPath, isRestServer, restServerPort, isGrpcServer, grpcServerPort)
406418

407419
return map[string]interface{}{
420+
"license": licenseCopier,
408421
"docker": dockerCopier,
409422
"k8s": k8sCopier,
410423
"githubActions": githubActionsCopier,
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package license
2+
3+
import (
4+
corenode "github.com/intelops/compage/internal/core/node"
5+
"github.com/intelops/compage/internal/utils"
6+
log "github.com/sirupsen/logrus"
7+
)
8+
9+
// Copier integrations specific copier
10+
type Copier struct {
11+
NodeName string
12+
NodeDirectoryName string
13+
TemplatesRootPath string
14+
License *corenode.License
15+
Data map[string]interface{}
16+
}
17+
18+
func NewCopier(gitRepositoryName, gitPlatformUserName, nodeName, nodeDirectoryName, templatesRootPath string, license *corenode.License) *Copier {
19+
// populate map to replace templates
20+
data := map[string]interface{}{
21+
"GitRepositoryName": gitRepositoryName,
22+
"GitPlatformUserName": gitPlatformUserName,
23+
}
24+
25+
return &Copier{
26+
TemplatesRootPath: templatesRootPath,
27+
NodeDirectoryName: nodeDirectoryName,
28+
NodeName: nodeName,
29+
Data: data,
30+
License: license,
31+
}
32+
}
33+
34+
// CreateLicenseFiles creates the required directory and copies files from language template.
35+
func (c Copier) CreateLicenseFiles() error {
36+
destDirectory := c.NodeDirectoryName
37+
if err := utils.CreateDirectories(destDirectory); err != nil {
38+
log.Errorf("error while creating directories [" + err.Error() + "]")
39+
return err
40+
}
41+
// copy license file if it's been supplied
42+
if c.License != nil && len(c.License.URL) > 0 {
43+
// read file from url in c.License.URL. This is applicable for both config.yaml file and ui flow.
44+
return utils.DownloadFile(c.NodeDirectoryName+"/LICENCE", c.License.URL)
45+
} else if c.License != nil && len(c.License.Path) > 0 {
46+
// local license file sent via config.yaml file.
47+
// get the absolute path of the license file
48+
_, err := utils.CopyFile(c.NodeDirectoryName+"/LICENCE", c.License.Path)
49+
if err != nil {
50+
log.Errorf("error while copying file [" + err.Error() + "]")
51+
return err
52+
}
53+
}
54+
// return from here as the license file has been copied
55+
return nil
56+
}

0 commit comments

Comments
 (0)