forked from intelops/compage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request intelops#212 from intelops/add-license-per-node
Add license per node
- Loading branch information
Showing
15 changed files
with
246 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package license | ||
|
||
import ( | ||
corenode "github.com/intelops/compage/internal/core/node" | ||
"github.com/intelops/compage/internal/utils" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// Copier integrations specific copier | ||
type Copier struct { | ||
NodeName string | ||
NodeDirectoryName string | ||
TemplatesRootPath string | ||
License *corenode.License | ||
Data map[string]interface{} | ||
} | ||
|
||
func NewCopier(gitRepositoryName, gitPlatformUserName, nodeName, nodeDirectoryName, templatesRootPath string, license *corenode.License) *Copier { | ||
// populate map to replace templates | ||
data := map[string]interface{}{ | ||
"GitRepositoryName": gitRepositoryName, | ||
"GitPlatformUserName": gitPlatformUserName, | ||
} | ||
|
||
return &Copier{ | ||
TemplatesRootPath: templatesRootPath, | ||
NodeDirectoryName: nodeDirectoryName, | ||
NodeName: nodeName, | ||
Data: data, | ||
License: license, | ||
} | ||
} | ||
|
||
// CreateLicenseFiles creates the required directory and copies files from language template. | ||
func (c Copier) CreateLicenseFiles() error { | ||
destDirectory := c.NodeDirectoryName | ||
if err := utils.CreateDirectories(destDirectory); err != nil { | ||
log.Errorf("error while creating directories [" + err.Error() + "]") | ||
return err | ||
} | ||
// copy license file if it's been supplied | ||
if c.License != nil && len(c.License.URL) > 0 { | ||
// read file from url in c.License.URL. This is applicable for both config.yaml file and ui flow. | ||
return utils.DownloadFile(c.NodeDirectoryName+"/LICENCE", c.License.URL) | ||
} else if c.License != nil && len(c.License.Path) > 0 { | ||
// local license file sent via config.yaml file. | ||
// get the absolute path of the license file | ||
_, err := utils.CopyFile(c.NodeDirectoryName+"/LICENCE", c.License.Path) | ||
if err != nil { | ||
log.Errorf("error while copying file [" + err.Error() + "]") | ||
return err | ||
} | ||
} | ||
// return from here as the license file has been copied | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package license | ||
|
||
import ( | ||
corenode "github.com/intelops/compage/internal/core/node" | ||
"github.com/intelops/compage/internal/utils" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
// Copier integrations specific copier | ||
type Copier struct { | ||
NodeName string | ||
NodeDirectoryName string | ||
TemplatesRootPath string | ||
License *corenode.License | ||
Data map[string]interface{} | ||
} | ||
|
||
func NewCopier(gitRepositoryName, gitPlatformUserName, nodeName, nodeDirectoryName, templatesRootPath string, license *corenode.License) *Copier { | ||
// populate map to replace templates | ||
data := map[string]interface{}{ | ||
"GitRepositoryName": gitRepositoryName, | ||
"GitPlatformUserName": gitPlatformUserName, | ||
} | ||
|
||
return &Copier{ | ||
TemplatesRootPath: templatesRootPath, | ||
NodeDirectoryName: nodeDirectoryName, | ||
NodeName: nodeName, | ||
Data: data, | ||
License: license, | ||
} | ||
} | ||
|
||
// CreateLicenseFiles creates the required directory and copies files from language template. | ||
func (c Copier) CreateLicenseFiles() error { | ||
destDirectory := c.NodeDirectoryName | ||
if err := utils.CreateDirectories(destDirectory); err != nil { | ||
log.Errorf("error while creating directories [" + err.Error() + "]") | ||
return err | ||
} | ||
// copy license file if it's been supplied | ||
if c.License != nil && len(c.License.URL) > 0 { | ||
// read file from url in c.License.URL. This is applicable for both config.yaml file and ui flow. | ||
return utils.DownloadFile(c.NodeDirectoryName+"/LICENCE", c.License.URL) | ||
} else if c.License != nil && len(c.License.Path) > 0 { | ||
// local license file sent via config.yaml file. | ||
// get the absolute path of the license file | ||
_, err := utils.CopyFile(c.NodeDirectoryName+"/LICENCE", c.License.Path) | ||
if err != nil { | ||
log.Errorf("error while copying file [" + err.Error() + "]") | ||
return err | ||
} | ||
} | ||
// return from here as the license file has been copied | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.