11package license
22
33import (
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
2022func 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
0 commit comments