-
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.
- Loading branch information
Showing
11 changed files
with
336 additions
and
226 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/sofyan48/maklo/entity" | ||
"github.com/sofyan48/maklo/libs/ssmlib" | ||
"github.com/sofyan48/maklo/libs/tool" | ||
) | ||
|
||
// CMDLibrary ... | ||
type CMDLibrary struct { | ||
SSMLib ssmlib.SSManagerInterface | ||
Tools tool.ToolsInterface | ||
} | ||
|
||
// CMDLibraryHandler ... | ||
func CMDLibraryHandler() *CMDLibrary { | ||
return &CMDLibrary{ | ||
SSMLib: ssmlib.SSManagerHandler(), | ||
Tools: tool.ToolsHandler(), | ||
} | ||
} | ||
|
||
// CMDLibraryInterface ... | ||
type CMDLibraryInterface interface { | ||
InsertParametersByPath(path, types string, overwrite bool) error | ||
GenerateByTemplates(path, types string) error | ||
DeleteParameterByTemplate(path, types string) | ||
GenerateParametersByPath(appname, stage, path string, decryption bool) error | ||
GenerateParametersToEnvirontment(appname, stage, path string, decryption bool) error | ||
} | ||
|
||
// InsertParametersByPath ... | ||
func (cmd *CMDLibrary) InsertParametersByPath(path, types string, overwrite bool) error { | ||
data := &entity.TemplatesModels{} | ||
if types == "json" { | ||
data, _ = cmd.Tools.ParsingJSON(path) | ||
} else { | ||
data, _ = cmd.Tools.ParsingYAML(path) | ||
} | ||
cmd.SSMLib.InsertParameter(data.Parameters, overwrite) | ||
return nil | ||
} | ||
|
||
// GenerateByTemplates ... | ||
func (cmd *CMDLibrary) GenerateByTemplates(path, types string) error { | ||
data := &entity.TemplatesModels{} | ||
if types == "json" { | ||
data, _ = cmd.Tools.ParsingJSON(path) | ||
} else { | ||
data, _ = cmd.Tools.ParsingYAML(path) | ||
} | ||
file := cmd.Tools.Storage(data.Stage, data.Name) | ||
for _, i := range data.Parameters { | ||
cmd.Tools.GenerateAWK(i.Path, i.IsEncrypt, file) | ||
} | ||
return nil | ||
} | ||
|
||
// DeleteParameterByTemplate ... | ||
func (cmd *CMDLibrary) DeleteParameterByTemplate(path, types string) { | ||
data := &entity.TemplatesModels{} | ||
if types == "json" { | ||
data, _ = cmd.Tools.ParsingJSON(path) | ||
} else { | ||
data, _ = cmd.Tools.ParsingYAML(path) | ||
} | ||
cmd.SSMLib.DeleteParameter(data.Parameters) | ||
} | ||
|
||
// GenerateParametersByPath ... | ||
func (cmd *CMDLibrary) GenerateParametersByPath(appname, stage, path string, decryption bool) error { | ||
file := cmd.Tools.Storage(stage, appname) | ||
data, err := cmd.SSMLib.GenerateParameters(path, stage, appname, decryption) | ||
if err != nil { | ||
return err | ||
} | ||
for _, i := range data { | ||
cmd.Tools.GenerateAWK(i.Name, decryption, file) | ||
} | ||
return nil | ||
} | ||
|
||
// GenerateParametersToEnvirontment ... | ||
func (cmd *CMDLibrary) GenerateParametersToEnvirontment(appname, stage, path string, decryption bool) error { | ||
file := cmd.Tools.Storage(stage, appname) | ||
data, err := cmd.SSMLib.GenerateParameters(path, stage, appname, decryption) | ||
if err != nil { | ||
return err | ||
} | ||
for _, i := range data { | ||
cmd.Tools.GenerateDotEnvirontment(i.Name, file) | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package ssmlib | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/aws/aws-sdk-go/service/ssm" | ||
"github.com/sofyan48/maklo/entity" | ||
"github.com/sofyan48/maklo/libs/aws" | ||
"github.com/sofyan48/maklo/libs/tool" | ||
) | ||
|
||
// SSManager ... | ||
type SSManager struct { | ||
AWS aws.AWSLibraryInterface | ||
Tools tool.ToolsInterface | ||
} | ||
|
||
// SSManagerHandler ... | ||
func SSManagerHandler() *SSManager { | ||
return &SSManager{ | ||
AWS: aws.AWSLibraryHandler(), | ||
Tools: tool.ToolsHandler(), | ||
} | ||
} | ||
|
||
// SSManagerInterface ... | ||
type SSManagerInterface interface { | ||
InsertParameter(dataJSON []entity.InsertDataModels, overwrite bool) | ||
DeleteParameter(dataJSON []entity.InsertDataModels) | ||
GenerateParameters(path, stage, appname string, decryption bool) ([]entity.GenerateOutputs, error) | ||
} | ||
|
||
// GenerateParameters ... | ||
func (ssmtool *SSManager) GenerateParameters(path, stage, appname string, decryption bool) ([]entity.GenerateOutputs, error) { | ||
svc := ssmtool.AWS.GetSystemManagerStore() | ||
results := []entity.GenerateOutputs{} | ||
input := &ssm.GetParametersByPathInput{} | ||
input.SetPath(path) | ||
input.SetWithDecryption(decryption) | ||
data, err := svc.GetParametersByPath(input) | ||
if err != nil { | ||
return results, err | ||
} | ||
for _, i := range data.Parameters { | ||
dataTemps := entity.GenerateOutputs{} | ||
dataTemps.Name = *i.Name | ||
dataTemps.Value = *i.Value | ||
dataTemps.Version = *i.Version | ||
dataTemps.Type = *i.Type | ||
dataTemps.LastModified = *&i.LastModifiedDate | ||
results = append(results, dataTemps) | ||
} | ||
return results, nil | ||
} | ||
|
||
// InsertParameter ... | ||
func (ssmtool *SSManager) InsertParameter(dataJSON []entity.InsertDataModels, overwrite bool) { | ||
svc := ssmtool.AWS.GetSystemManagerStore() | ||
for _, i := range dataJSON { | ||
inputFormat := &ssm.PutParameterInput{} | ||
inputFormat.SetName(i.Path) | ||
inputFormat.SetValue(i.Value) | ||
inputFormat.SetOverwrite(overwrite) | ||
if i.IsEncrypt { | ||
inputFormat.SetType("SecureString") | ||
} else { | ||
inputFormat.SetType("String") | ||
} | ||
result, err := svc.PutParameter(inputFormat) | ||
if err != nil { | ||
log.Println("Not Uploaded Parameter: ", err) | ||
} | ||
log.Println("Uploaded Parameter: ", result) | ||
} | ||
} | ||
|
||
// DeleteParameter .. | ||
func (ssmtool *SSManager) DeleteParameter(dataJSON []entity.InsertDataModels) { | ||
svc := ssmtool.AWS.GetSystemManagerStore() | ||
for _, i := range dataJSON { | ||
inputFormat := &ssm.DeleteParameterInput{} | ||
inputFormat.SetName(i.Path) | ||
result, err := svc.DeleteParameter(inputFormat) | ||
if err != nil { | ||
log.Println("Not Deleted Parameter: ", err) | ||
} | ||
log.Println("Deleted Parameter: ", result) | ||
} | ||
|
||
} |
Oops, something went wrong.