@@ -16,12 +16,9 @@ package communicator
16
16
17
17
import (
18
18
"errors"
19
- "net/http"
20
- "net/url"
21
19
"sync"
22
20
"time"
23
21
24
- "github.com/aws/aws-sdk-go/aws/signer/v4"
25
22
"github.com/aws/session-manager-plugin/src/config"
26
23
"github.com/aws/session-manager-plugin/src/log"
27
24
"github.com/aws/session-manager-plugin/src/websocketutil"
@@ -30,7 +27,7 @@ import (
30
27
31
28
// IWebSocketChannel is the interface for DataChannel.
32
29
type IWebSocketChannel interface {
33
- Initialize (log log.T , channelUrl string , channelToken string , region string , signer * v4. Signer )
30
+ Initialize (log log.T , channelUrl string , channelToken string )
34
31
Open (log log.T ) error
35
32
Close (log log.T ) error
36
33
SendMessage (log log.T , input []byte , inputType int ) error
@@ -52,8 +49,6 @@ type WebSocketChannel struct {
52
49
writeLock * sync.Mutex
53
50
Connection * websocket.Conn
54
51
ChannelToken string
55
- Region string
56
- Signer * v4.Signer
57
52
}
58
53
59
54
// GetChannelToken gets the channel token
@@ -82,11 +77,9 @@ func (webSocketChannel *WebSocketChannel) SetOnMessage(onMessageHandler func([]b
82
77
}
83
78
84
79
// Initialize initializes websocket channel fields
85
- func (webSocketChannel * WebSocketChannel ) Initialize (log log.T , channelUrl string , channelToken string , region string , signer * v4. Signer ) {
80
+ func (webSocketChannel * WebSocketChannel ) Initialize (log log.T , channelUrl string , channelToken string ) {
86
81
webSocketChannel .ChannelToken = channelToken
87
82
webSocketChannel .Url = channelUrl
88
- webSocketChannel .Region = region
89
- webSocketChannel .Signer = signer
90
83
}
91
84
92
85
// StartPings starts the pinging process to keep the websocket channel alive.
@@ -128,47 +121,6 @@ func (webSocketChannel *WebSocketChannel) SendMessage(log log.T, input []byte, i
128
121
return err
129
122
}
130
123
131
- // getV4SignatureHeader gets the signed header.
132
- func (webSocketChannel * WebSocketChannel ) getV4SignatureHeader (log log.T , Url string ) (http.Header , error ) {
133
- request , err := http .NewRequest ("GET" , Url , nil )
134
-
135
- if webSocketChannel .Signer != nil {
136
- _ , err = webSocketChannel .Signer .Sign (request , nil , config .ServiceName , webSocketChannel .Region , time .Now ())
137
- if err != nil {
138
- log .Errorf ("Failed to sign websocket, %v" , err )
139
- }
140
- }
141
- return request .Header , err
142
- }
143
-
144
- // isPresignedURL check is the url presigned.
145
- func isPresignedURL (rawURL string ) (bool , error ) {
146
- parsedURL , err := url .Parse (rawURL )
147
- if err != nil {
148
- return false , err
149
- }
150
-
151
- queryParams := parsedURL .Query ()
152
-
153
- presignedURLParams := []string {
154
- "X-Amz-Algorithm" ,
155
- "X-Amz-Credential" ,
156
- "X-Amz-Date" ,
157
- "X-Amz-Expires" ,
158
- "X-Amz-SignedHeaders" ,
159
- "X-Amz-Signature" ,
160
- "X-Amz-Security-Token" ,
161
- }
162
-
163
- for _ , param := range presignedURLParams {
164
- if _ , exists := queryParams [param ]; exists {
165
- return true , nil
166
- }
167
- }
168
-
169
- return false , nil
170
- }
171
-
172
124
// Close closes the corresponding connection.
173
125
func (webSocketChannel * WebSocketChannel ) Close (log log.T ) error {
174
126
@@ -187,22 +139,9 @@ func (webSocketChannel *WebSocketChannel) Close(log log.T) error {
187
139
func (webSocketChannel * WebSocketChannel ) Open (log log.T ) error {
188
140
// initialize the write mutex
189
141
webSocketChannel .writeLock = & sync.Mutex {}
190
- presigned , err := isPresignedURL (webSocketChannel .Url )
191
- if err != nil {
192
- return err
193
- }
194
-
195
- var header http.Header
196
- if ! presigned {
197
- header , err = webSocketChannel .getV4SignatureHeader (log , webSocketChannel .Url )
198
- if err != nil {
199
- log .Errorf ("Failed to get the v4 signature, %v" , err )
200
- }
201
- }
202
142
203
- ws , err := websocketutil .NewWebsocketUtil (log , nil ).OpenConnection (webSocketChannel .Url , header )
143
+ ws , err := websocketutil .NewWebsocketUtil (log , nil ).OpenConnection (webSocketChannel .Url )
204
144
if err != nil {
205
- log .Errorf ("Failed to open WebSocket connection: %v" , err )
206
145
return err
207
146
}
208
147
webSocketChannel .Connection = ws
0 commit comments