Skip to content

Commit

Permalink
fix: fixes authentication errors with amt devices
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdmike committed Jul 15, 2024
1 parent 3f3e29d commit 314af98
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.10.0
github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.11.0
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.10.0 h1:W+gGMkbbr6zzcvYkUIkkA6SBf2IpW2cDhukFX/DLh/Y=
github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.10.0/go.mod h1:LyY8fOvYBt5gawHYuivROR7EBySRuSR0u/k8QosnCeU=
github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.11.0 h1:k02GXmlNFGwRqT2GOcmwvbQf84nkccwISQme96Abkco=
github.com/open-amt-cloud-toolkit/go-wsman-messages/v2 v2.11.0/go.mod h1:LyY8fOvYBt5gawHYuivROR7EBySRuSR0u/k8QosnCeU=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
Expand Down
32 changes: 28 additions & 4 deletions internal/usecase/devices/wsman/message.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package wsman

import (
"fmt"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -100,11 +101,34 @@ func (g GoWSMANMessages) SetupWsmanClient(device dto.Device, isRedirection, logA
defer connectionsMu.Unlock()

if entry, ok := connections[device.GUID]; ok {
entry.Timer.Stop() // Stop the previous timer
entry.Timer = time.AfterFunc(expireAfter, func() {
removeConnection(device.GUID)
})
if entry.WsmanMessages.Client.IsAuthenticated() {
fmt.Println("Am i Authenticated? Apparently yes.")
entry.Timer.Stop() // Stop the previous timer
entry.Timer = time.AfterFunc(expireAfter, func() {
removeConnection(device.GUID)
})
} else {
duration := 3 * time.Second
ticker := time.NewTicker(500 * time.Millisecond)
defer ticker.Stop()

timeout := time.After(duration)
for {
select {
case <-ticker.C:
if entry.WsmanMessages.Client.IsAuthenticated() {
// Your logic when the function check is successful
fmt.Println("Authenticated.")
return connections[device.GUID]
}
case <-timeout:
fmt.Println("Time period elapsed. Failed to auth.")
return connections[device.GUID]
}
}
}
} else {
fmt.Println("I AM NOT AUTHENTICATED, I SHOULD ONLY BE HERE ONCE")
wsmanMsgs := wsman.NewMessages(clientParams)
timer := time.AfterFunc(expireAfter, func() {
removeConnection(device.GUID)
Expand Down

0 comments on commit 314af98

Please sign in to comment.