mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Added basic auth to data source edit/create, add support for basic auth in data source proxy code, Closes #1510
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"crypto/md5"
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"hash"
|
||||
@@ -74,3 +75,8 @@ func PBKDF2(password, salt []byte, iter, keyLen int, h func() hash.Hash) []byte
|
||||
}
|
||||
return dk[:keyLen]
|
||||
}
|
||||
|
||||
func GetBasicAuthHeader(user string, password string) string {
|
||||
var userAndPass = user + ":" + password
|
||||
return "Basic " + base64.StdEncoding.EncodeToString([]byte(userAndPass))
|
||||
}
|
||||
|
||||
16
pkg/util/encoding_test.go
Normal file
16
pkg/util/encoding_test.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
)
|
||||
|
||||
func TestEncoding(t *testing.T) {
|
||||
|
||||
Convey("When generating base64 header", t, func() {
|
||||
result := GetBasicAuthHeader("grafana", "1234")
|
||||
|
||||
So(result, ShouldEqual, "Z3JhZmFuYToxMjM0")
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user