-
Notifications
You must be signed in to change notification settings - Fork 2
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
14 changed files
with
165 additions
and
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package custom_handlers | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/gameap/daemon/internal/app/config" | ||
"github.com/gameap/daemon/internal/app/contracts" | ||
"github.com/gameap/daemon/internal/app/domain" | ||
"github.com/hashicorp/go-getter" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
type GetTool struct { | ||
cfg *config.Config | ||
} | ||
|
||
func NewGetTool(cfg *config.Config) *GetTool { | ||
return &GetTool{cfg: cfg} | ||
} | ||
|
||
func (g *GetTool) Handle(ctx context.Context, args []string, out io.Writer, _ contracts.ExecutorOptions) (int, error) { | ||
source := args[0] | ||
fileName := filepath.Base(source) | ||
destination := filepath.Join(g.cfg.ToolsPath, fileName) | ||
|
||
c := getter.Client{ | ||
Ctx: ctx, | ||
Src: args[0], | ||
Dst: destination, | ||
Mode: getter.ClientModeFile, | ||
} | ||
|
||
_, _ = out.Write([]byte("Getting tool from " + source + " to " + destination + " ...")) | ||
err := c.Get() | ||
if err != nil { | ||
return int(domain.ErrorResult), errors.WithMessage(err, "[components.GetTool] failed to get tool") | ||
} | ||
|
||
err = os.Chmod(destination, 0700) | ||
if err != nil { | ||
_, _ = out.Write([]byte("Failed to chmod tool")) | ||
return int(domain.ErrorResult), errors.WithMessage(err, "[components.GetTool] failed to chmod tool") | ||
} | ||
|
||
return int(domain.ErrorResult), 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,48 @@ | ||
package custom_handlers | ||
|
||
import ( | ||
"context" | ||
"io" | ||
|
||
"github.com/gameap/daemon/internal/app/config" | ||
"github.com/gameap/daemon/internal/app/contracts" | ||
"github.com/gameap/daemon/internal/app/domain" | ||
) | ||
|
||
type outputReader interface { | ||
GetOutput(ctx context.Context, server *domain.Server, out io.Writer) (domain.Result, error) | ||
} | ||
|
||
type OutputReader struct { | ||
cfg *config.Config | ||
getter outputReader | ||
} | ||
|
||
func NewOutputReader(cfg *config.Config, getter outputReader) *OutputReader { | ||
return &OutputReader{cfg: cfg, getter: getter} | ||
} | ||
|
||
func (g *OutputReader) Handle( | ||
_ context.Context, _ []string, _ io.Writer, _ contracts.ExecutorOptions, | ||
) (int, error) { | ||
return 0, nil | ||
} | ||
|
||
type commandSender interface { | ||
SendCommand(ctx context.Context, server *domain.Server, out io.Writer) (domain.Result, error) | ||
} | ||
|
||
type CommandSender struct { | ||
cfg *config.Config | ||
sender commandSender | ||
} | ||
|
||
func NewCommandSender(cfg *config.Config, sender commandSender) *CommandSender { | ||
return &CommandSender{cfg: cfg, sender: sender} | ||
} | ||
|
||
func (g *CommandSender) Handle( | ||
_ context.Context, _ []string, _ io.Writer, _ contracts.ExecutorOptions, | ||
) (int, error) { | ||
return 0, 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.