-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added isSecure field in the winrm settings. When isSecure is true, we allow HTTPs connection to end point powershell. If isSecure is false, we allow HTTP connection to end point powershell. #5
base: master
Are you sure you want to change the base?
Changes from all commits
ed045cd
3ee2786
b6d3fb8
e926485
1f5a7ac
a2a6700
7a35eeb
91fe433
cb7a0c3
0df0942
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,10 @@ const ( | |
NTLM | ||
Kerberos | ||
) | ||
const ( | ||
HTTP_PROTOCOL = "http" | ||
HTTPS_PROTOCOL = "https" | ||
) | ||
|
||
// WinRM client used for executing scripts | ||
// TODO: Add support for NTLM and Kerberos, Only basic is supported for now | ||
|
@@ -55,6 +59,8 @@ type winrmSettings struct { | |
operationTimeout string | ||
// Timeout of each HTTP call made | ||
timeout int | ||
// Whether the call is HTTP or HTTPS | ||
isSecure bool | ||
} | ||
|
||
type getEndpointDetails func() endpointDetails | ||
|
@@ -108,6 +114,13 @@ func Port(num int) winrmSettingsOption { | |
} | ||
} | ||
|
||
func IsSecure(b bool) winrmSettingsOption { | ||
return func(ws winrmSettings) winrmSettings { | ||
ws.isSecure = b | ||
return ws | ||
} | ||
} | ||
|
||
func MaxEnvelopeSize(size string) winrmSettingsOption { | ||
return func(ws winrmSettings) winrmSettings { | ||
ws.maxEnvelopeSize = size | ||
|
@@ -156,6 +169,7 @@ var defaultWinrmSettings winrmSettings = winrmSettings{ | |
maxEnvelopeSize: "153200", | ||
locale: "en-US", | ||
operationTimeout: "PT60.000S", | ||
isSecure: true, | ||
} | ||
|
||
// Creates a new WinRM client | ||
|
@@ -185,7 +199,13 @@ func NewWinRMClient(details getEndpointDetails, options ...winrmSettingsOption) | |
for _, o := range options { | ||
client.winrmSettings = o(client.winrmSettings) | ||
} | ||
client.url = fmt.Sprintf("https://%s:%d/wsman", client.ipAddress, client.port) | ||
var protocol string | ||
if client.isSecure { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a detail but to avoid repeating the whole
then use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addressed |
||
protocol = HTTPS_PROTOCOL | ||
} else { | ||
protocol = HTTP_PROTOCOL | ||
} | ||
client.url = fmt.Sprintf("%s://%s:%d/wsman", protocol, client.ipAddress, client.port) | ||
if client.endpointDetails.auth&NTLM == NTLM { | ||
client.client.Transport = ntlmssp.Negotiator{RoundTripper: client.client.Transport} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,3 +65,21 @@ func TestCaptureAttribute(t *testing.T) { | |
t.Error("invalid attribute") | ||
} | ||
} | ||
|
||
func BenchmarkHTTPRequest(b *testing.B) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how this is relevant...? |
||
for i := 0; i < b.N; i++ { | ||
p := &gopsremote.PayloadBuilder{ | ||
OpType: gopsremote.Execute, | ||
Url: "http://172.25.168.38:5986/wsman", | ||
OperationTimeout: "PT.06", | ||
Locale: "en-US", | ||
MessageId: uuid.New().String(), | ||
ShellId: uuid.New().String(), | ||
CommandId: uuid.New().String(), | ||
Command: "Get-Service", | ||
Input: "del", | ||
MaxEnvelopeSize: "1532600", | ||
} | ||
p.Execute() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a detail but http/https is usually referred as the "scheme".