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,6 +15,7 @@ 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
@@ -37,6 +39,7 @@ func NewCopier(project *core.Project) (*Copier, error) {
37
39
ProjectDirectoryName : utils .GetProjectDirectoryName (project .Name ),
38
40
GitRepositoryName : project .GitRepositoryName ,
39
41
Data : data ,
42
+ License : project .License ,
40
43
}, nil
41
44
}
42
45
@@ -47,7 +50,22 @@ func (c Copier) CreateLicenseFiles() error {
47
50
log .Errorf ("error while creating directories [" + err .Error () + "]" )
48
51
return err
49
52
}
50
-
53
+ // copy license file if it's been supplied
54
+ if c .License != nil && len (c .License .URL ) > 0 {
55
+ // read file from url in c.License.URL. This is applicable for both config.yaml file and ui flow.
56
+ return utils .DownloadFile (c .ProjectDirectoryName + "/LICENCE" , c .License .URL )
57
+ } else if c .License != nil && len (c .License .Path ) > 0 {
58
+ // local license file sent via config.yaml file.
59
+ // get the absolute path of the license file
60
+ _ , err := utils .CopyFile (c .ProjectDirectoryName + "/LICENCE" , c .License .Path )
61
+ if err != nil {
62
+ log .Errorf ("error while copying file [" + err .Error () + "]" )
63
+ return err
64
+ }
65
+ // return from here as the license file has been copied
66
+ return nil
67
+ }
68
+ // copy license file from templates (the default one)
51
69
var filePaths []* string
52
70
// copy deployment files to generated license config files
53
71
targetLicenseFileName := c .ProjectDirectoryName + "/" + File
0 commit comments