-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdira.go
More file actions
80 lines (66 loc) · 1.93 KB
/
dira.go
File metadata and controls
80 lines (66 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package dira
type RemoteAccessEntity struct {
url string
container string
command string
timeout int
removeMatching bool
}
// SetOpts insert params to execute the command
func SetOpts(hostIpOrUrl string, containerIdOrName string, cmd string) ExecutionAbstraction {
return &RemoteAccessEntity{
url: hostIpOrUrl,
container: containerIdOrName,
command: cmd,
}
}
// SetUrl set the base url/ip & port of docker container host
func (e *RemoteAccessEntity) SetUrl(hostIpOrUrl string) ExecutionAbstraction {
e.url = hostIpOrUrl
return e
}
func (e *RemoteAccessEntity) GetUrl() string {
return e.url
}
// SetContainer set the container id or name
func (e *RemoteAccessEntity) SetContainer(containerName string) ExecutionAbstraction {
e.container = containerName
return e
}
func (e *RemoteAccessEntity) GetContainer() string {
return e.container
}
// SetCommand set desired command to be run in the container
func (e *RemoteAccessEntity) SetCommand(cmd string) ExecutionAbstraction {
e.command = cmd
return e
}
func (e *RemoteAccessEntity) GetCommand() string {
return e.command
}
// SetTimeout set timeout in seconds, if it will be asserted too much time for execution
func (e *RemoteAccessEntity) SetTimeout(timeOutInSec int) ExecutionAbstraction {
e.timeout = timeOutInSec
return e
}
func (e *RemoteAccessEntity) GetTimeout() int {
return e.timeout
}
// RemoveMatching remove unwanted characters of "\n, SOH, NUL, EOT, ACK" of STDOUT
func (e *RemoteAccessEntity) RemoveMatching() ExecutionAbstraction {
e.removeMatching = true
return e
}
func (e *RemoteAccessEntity) GetRemoveMatching() bool {
return e.removeMatching
}
// Exec inquire the container name and execute the command
func (e *RemoteAccessEntity) Exec() (res string, err error) {
cmd := Command()
cmd.SetRemoteAccess(e)
cmd.InquireContainer()
if err = cmd.GetError(); err != nil {
return "", err
}
return cmd.ExecuteContainerCommand()
}