-
Notifications
You must be signed in to change notification settings - Fork 35
feat: add support for BearerToken and TOTP authentication #351
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bfa42e8
feat: add support for BearerToken in restful connection
huskar-t 5328b71
feat: add support for BearerToken and TOTP authentication in websocke…
huskar-t 4454d22
chore: update Commit constant to reflect current commit hash
huskar-t c7a9c9c
feat: add GitHub Actions workflow for enterprise testing and deployment
huskar-t 4f707ba
feat: update process name handling in tests to ensure proper length
huskar-t 6c895e7
feat: fix environment variable setting for enterprise test flag
huskar-t c4da046
feat: ensure proper database closure in test cases
huskar-t d179de0
test: add HTTPQuery function and update tests
huskar-t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| name: enterprise.yml | ||
| on: | ||
| pull_request: | ||
| branches: | ||
| - '3.0' | ||
| - 'main' | ||
| push: | ||
| branches: | ||
| - '3.0' | ||
| - 'main' | ||
| jobs: | ||
| test: | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| matrix: | ||
| os: [ 'ubuntu-latest' ] | ||
| go: [ 'stable' ] | ||
| name: enterprise-${{ matrix.os }}-${{ matrix.go }} | ||
| steps: | ||
| - name: get branch push | ||
| id: get-branch | ||
| run: | | ||
| if [[ "${{ github.event_name }}" == "push" ]]; then | ||
| echo "branch=${{ github.ref_name }}" >> $GITHUB_OUTPUT | ||
| elif [[ "${{ github.event_name }}" == "pull_request" ]]; then | ||
| echo "branch=${{ github.base_ref }}" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "branch=main" >> $GITHUB_OUTPUT | ||
| fi | ||
|
|
||
| - name: get TDengine | ||
| run: | | ||
| wget "${{ secrets.NIGHTLY_TDENGINE_ENTERPRISE_BASE_URL }}/tsdb-nightly-${{ steps.get-branch.outputs.branch }}.tar.gz?v=$(date +%s)" -O tsdb-nightly-${{ steps.get-branch.outputs.branch }}.tar.gz | ||
|
|
||
| - name: install | ||
| run: | | ||
| tar -zxf tsdb-nightly-${{ steps.get-branch.outputs.branch }}.tar.gz | ||
| cd tsdb-nightly-${{ steps.get-branch.outputs.branch }} | ||
| ls -al | ||
| sudo ./install.sh | ||
|
|
||
| - name: checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: copy taos cfg | ||
| run: | | ||
| sudo mkdir -p /etc/taos | ||
| sudo cp ./.github/workflows/taos.cfg /etc/taos/taos.cfg | ||
|
|
||
| - name: shell | ||
| run: | | ||
| cat >start.sh<<EOF | ||
| ulimit -n 65535 && taosd | ||
| EOF | ||
|
|
||
| - name: taosd | ||
| run: nohup sudo sh ./start.sh & | ||
|
|
||
| - name: taosadapter | ||
| run: nohup sudo taosadapter & | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| go-version: ${{ matrix.go }} | ||
| cache-dependency-path: go.sum | ||
|
|
||
| - name: Test | ||
| id: test | ||
| env: | ||
| GO_TEST_DISABLE_DISPLAY_LOG: "true" | ||
| GO_TEST_ENTERPRISE: "true" | ||
| run: | | ||
| go mod download | ||
| go test -coverpkg=./... -v --count=1 -coverprofile=coverage.txt -covermode=atomic ./... | ||
|
|
||
| - name: Upload coverage to Codecov | ||
| uses: codecov/codecov-action@v5 | ||
| with: | ||
| files: ./coverage.txt | ||
| env: | ||
| CODECOV_TOKEN: ${{ secrets.CODECOV_ORG_TOKEN }} | ||
| OS: linux | ||
|
|
||
| - uses: actions/upload-artifact@v4 | ||
| if: always() && (steps.test.outcome == 'failure' || steps.test.outcome == 'cancelled') | ||
| with: | ||
| name: enterprise-${{ matrix.os }}-${{ matrix.go }}-log | ||
| path: /var/log/taos/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package testenv | ||
|
|
||
| import "os" | ||
|
|
||
| const EnterpriseTestEnvVar = "GO_TEST_ENTERPRISE" | ||
|
|
||
| func IsEnterpriseTest() bool { | ||
| if _, ok := os.LookupEnv(EnterpriseTestEnvVar); ok { | ||
| return true | ||
| } | ||
| return false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package testenv | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestIsEnterpriseTest(t *testing.T) { | ||
| old, exists := os.LookupEnv(EnterpriseTestEnvVar) | ||
| if exists { | ||
| defer func() { | ||
| _ = os.Setenv(EnterpriseTestEnvVar, old) | ||
| }() | ||
| } else { | ||
| defer func() { | ||
| _ = os.Unsetenv(EnterpriseTestEnvVar) | ||
| }() | ||
| } | ||
| _ = os.Setenv(EnterpriseTestEnvVar, "true") | ||
| assert.True(t, IsEnterpriseTest()) | ||
| _ = os.Unsetenv(EnterpriseTestEnvVar) | ||
| assert.False(t, IsEnterpriseTest()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package testtool | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/http" | ||
| "strings" | ||
|
|
||
| "github.com/taosdata/driver-go/v3/common" | ||
| ) | ||
|
|
||
| func HTTPQuery(payload string) (*common.TDEngineRestfulResp, error) { | ||
| body := strings.NewReader(payload) | ||
| req, _ := http.NewRequest(http.MethodPost, "http://127.0.0.1:6041/rest/sql", body) | ||
| req.Header.Set("Authorization", "Taosd /KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04") | ||
| resp, err := http.DefaultClient.Do(req) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer func() { | ||
| _ = resp.Body.Close() | ||
| }() | ||
| if resp.StatusCode != http.StatusOK { | ||
| return nil, fmt.Errorf("http code: %d", resp.StatusCode) | ||
| } | ||
| return common.UnmarshalRestfulBody(resp.Body, 512) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package testtool | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestHTTPQuery(t *testing.T) { | ||
| resp, err := HTTPQuery("select 1") | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, int64(1), resp.Data[0][0]) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "crypto/hmac" | ||
| "crypto/sha1" | ||
| "crypto/sha256" | ||
| "encoding/base32" | ||
| "encoding/binary" | ||
| ) | ||
|
|
||
| // GenerateTOTPCode generates a TOTP code based on the provided key, counter, and number of digits. | ||
| func GenerateTOTPCode(key []byte, counter uint64, digits int) int { | ||
| h := hmac.New(sha1.New, key) | ||
| counterBytes := make([]byte, 8) | ||
| binary.BigEndian.PutUint64(counterBytes, counter) | ||
| h.Write(counterBytes) | ||
| sum := h.Sum(nil) | ||
| offset := sum[len(sum)-1] & 0x0F | ||
| v := binary.BigEndian.Uint32(sum[offset:]) & 0x7FFFFFFF | ||
| d := uint32(1) | ||
| for i := 0; i < digits && i < 8; i++ { | ||
| d *= 10 | ||
| } | ||
| return int(v % d) | ||
| } | ||
|
huskar-t marked this conversation as resolved.
|
||
|
|
||
| // GenerateTOTPSecret generates a TOTP secret using HMAC-SHA256 with the provided seed. | ||
| func GenerateTOTPSecret(seed []byte) []byte { | ||
| h := hmac.New(sha256.New, nil) | ||
| h.Write(seed) | ||
| hmacResult := h.Sum(nil) | ||
| return hmacResult | ||
| } | ||
|
huskar-t marked this conversation as resolved.
|
||
|
|
||
|
huskar-t marked this conversation as resolved.
|
||
| // TOTPSecretStr converts the given TOTP secret bytes into a base32-encoded | ||
| // string without padding and returns the resulting string representation. | ||
| func TOTPSecretStr(secret []byte) string { | ||
| return base32.StdEncoding.WithPadding(base32.NoPadding).EncodeToString(secret) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.