1
1
package license
2
2
3
3
import (
4
+ "github.com/intelops/compage/cmd/models"
4
5
"github.com/intelops/compage/internal/core"
5
6
"github.com/intelops/compage/internal/languages/executor"
6
7
"github.com/intelops/compage/internal/utils"
@@ -14,12 +15,11 @@ type Copier struct {
14
15
ProjectDirectoryName string
15
16
GitRepositoryName string
16
17
TemplatesRootPath string
18
+ License * models.License
17
19
Data map [string ]interface {}
18
20
}
19
21
20
22
func NewCopier (project * core.Project ) (* Copier , error ) {
21
- // retrieve project named directory
22
- //gitPlatformUserName, gitRepositoryName, projectDirectoryName, templatesRootPath string
23
23
// populate map to replace templates
24
24
data := map [string ]interface {}{
25
25
"GitRepositoryName" : project .GitRepositoryName ,
@@ -37,6 +37,7 @@ func NewCopier(project *core.Project) (*Copier, error) {
37
37
ProjectDirectoryName : utils .GetProjectDirectoryName (project .Name ),
38
38
GitRepositoryName : project .GitRepositoryName ,
39
39
Data : data ,
40
+ License : project .License ,
40
41
}, nil
41
42
}
42
43
@@ -47,7 +48,22 @@ func (c Copier) CreateLicenseFiles() error {
47
48
log .Errorf ("error while creating directories [" + err .Error () + "]" )
48
49
return err
49
50
}
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)
51
67
var filePaths []* string
52
68
// copy deployment files to generated license config files
53
69
targetLicenseFileName := c .ProjectDirectoryName + "/" + File
0 commit comments