@@ -118,6 +118,45 @@ func Authenticate(c *fiber.Ctx) error {
118118 "message" : "Unauthorized" ,
119119 })
120120 }
121+ // for backward compatability
122+ if strings .HasSuffix (path , "/produce/single" ) || strings .HasSuffix (path , "/produce/batch" ) {
123+ emptyAuthSchema := models.AuthSchema {}
124+ if user == emptyAuthSchema {
125+ opts := []memphis.Option {memphis .Reconnect (true ), memphis .MaxReconnect (10 ), memphis .ReconnectInterval (3 * time .Second )}
126+ if configuration .USER_PASS_BASED_AUTH {
127+ opts = append (opts , memphis .Password (configuration .ROOT_PASSWORD ))
128+ } else {
129+ opts = append (opts , memphis .ConnectionToken (configuration .CONNECTION_TOKEN ))
130+ }
131+ if configuration .CLIENT_CERT_PATH != "" && configuration .CLIENT_KEY_PATH != "" && configuration .ROOT_CA_PATH != "" {
132+ opts = append (opts , memphis .Tls (configuration .CLIENT_CERT_PATH , configuration .CLIENT_KEY_PATH , configuration .ROOT_CA_PATH ))
133+ }
134+ conn , _ := memphis .Connect (configuration .MEMPHIS_HOST , configuration .ROOT_USER , opts ... )
135+
136+ if handlers .ConnectionsCache ["1" ] == nil {
137+ handlers .ConnectionsCacheLock .Lock ()
138+ handlers .ConnectionsCache ["1" ] = make (map [string ]handlers.Connection )
139+ handlers .ConnectionsCacheLock .Unlock ()
140+ }
141+
142+ handlers .ConnectionsCache ["1" ][configuration .ROOT_USER ] = handlers.Connection {Connection : conn , ExpirationTime : int64 (user .TokenExpiryMins )}
143+
144+ if ! configuration .USER_PASS_BASED_AUTH {
145+ user = models.AuthSchema {
146+ Username : configuration .ROOT_USER ,
147+ ConnectionToken : configuration .CONNECTION_TOKEN ,
148+ AccountId : 1 ,
149+ }
150+ } else {
151+ user = models.AuthSchema {
152+ Username : configuration .ROOT_USER ,
153+ Password : configuration .ROOT_PASSWORD ,
154+ AccountId : 1 ,
155+ }
156+ }
157+ }
158+ }
159+
121160 } else if path == "/auth/refreshtoken" {
122161 var body models.RefreshTokenSchema
123162 if err := c .BodyParser (& body ); err != nil {
@@ -154,42 +193,6 @@ func Authenticate(c *fiber.Ctx) error {
154193 user .AccountId = 1
155194 }
156195
157- // for backward compatability
158- if user .Username == "" {
159- opts := []memphis.Option {memphis .Reconnect (true ), memphis .MaxReconnect (10 ), memphis .ReconnectInterval (3 * time .Second )}
160- if configuration .USER_PASS_BASED_AUTH {
161- opts = append (opts , memphis .Password (configuration .ROOT_PASSWORD ))
162- } else {
163- opts = append (opts , memphis .ConnectionToken (configuration .CONNECTION_TOKEN ))
164- }
165- if configuration .CLIENT_CERT_PATH != "" && configuration .CLIENT_KEY_PATH != "" && configuration .ROOT_CA_PATH != "" {
166- opts = append (opts , memphis .Tls (configuration .CLIENT_CERT_PATH , configuration .CLIENT_KEY_PATH , configuration .ROOT_CA_PATH ))
167- }
168- conn , _ := memphis .Connect (configuration .MEMPHIS_HOST , configuration .ROOT_USER , opts ... )
169-
170- if handlers .ConnectionsCache ["1" ] == nil {
171- handlers .ConnectionsCacheLock .Lock ()
172- handlers .ConnectionsCache ["1" ] = make (map [string ]handlers.Connection )
173- handlers .ConnectionsCacheLock .Unlock ()
174- }
175-
176- handlers .ConnectionsCache ["1" ][configuration .ROOT_USER ] = handlers.Connection {Connection : conn , ExpirationTime : int64 (user .TokenExpiryMins )}
177-
178- if ! configuration .USER_PASS_BASED_AUTH {
179- user = models.AuthSchema {
180- Username : configuration .ROOT_USER ,
181- ConnectionToken : configuration .CONNECTION_TOKEN ,
182- AccountId : 1 ,
183- }
184- } else {
185- user = models.AuthSchema {
186- Username : configuration .ROOT_USER ,
187- Password : configuration .ROOT_PASSWORD ,
188- AccountId : 1 ,
189- }
190- }
191- }
192-
193196 c .Locals ("userData" , user )
194197 return c .Next ()
195198}
0 commit comments