-
Notifications
You must be signed in to change notification settings - Fork 206
chore: Enable OAuth token test #3777
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
Changes from all commits
bea559d
70e3991
163b0ad
31ff87e
f824278
3f0102c
35703fa
980b0ca
867e456
b38a6e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -548,6 +548,38 @@ jobs: | |
ACCTEST_REGEX_RUN: '^TestAccServiceAccount' | ||
ACCTEST_PACKAGES: ./internal/provider | ||
run: make testacc | ||
- name: Generate OAuth2 Token | ||
id: generate-token | ||
shell: bash | ||
env: | ||
MONGODB_ATLAS_BASE_URL: ${{ inputs.mongodb_atlas_base_url }} | ||
MONGODB_ATLAS_CLIENT_ID: ${{ secrets.mongodb_atlas_client_id }} | ||
MONGODB_ATLAS_CLIENT_SECRET: ${{ secrets.mongodb_atlas_client_secret }} | ||
run: | | ||
if ! ACCESS_TOKEN=$(make generate-oauth2-token); then | ||
echo "Error: Failed to generate access token" | ||
exit 1 | ||
fi | ||
if [ -z "$ACCESS_TOKEN" ]; then | ||
echo "Error: Generated access token is empty" | ||
exit 1 | ||
fi | ||
{ | ||
echo "access_token<<EOF" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just double checking: no token will be output in the console, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can check last run logs: link - all good 👌 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correct, it'll show the typical *** |
||
echo "$ACCESS_TOKEN" | ||
echo "EOF" | ||
} >> "$GITHUB_OUTPUT" | ||
- name: Acceptance Tests (Access Token) | ||
env: | ||
MONGODB_ATLAS_PUBLIC_KEY: "" | ||
MONGODB_ATLAS_PRIVATE_KEY: "" | ||
MONGODB_ATLAS_CLIENT_ID: "" | ||
MONGODB_ATLAS_CLIENT_SECRET: "" | ||
lantoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
MONGODB_ATLAS_ACCESS_TOKEN: ${{ steps.generate-token.outputs.access_token }} | ||
MONGODB_ATLAS_LAST_VERSION: ${{ needs.get-provider-version.outputs.provider_version }} | ||
ACCTEST_REGEX_RUN: '^TestAccAccessToken' | ||
ACCTEST_PACKAGES: ./internal/provider | ||
run: make testacc | ||
- name: Acceptance Tests (Service Account smoke tests) # small selection of fast tests to run with SA | ||
env: | ||
MONGODB_ATLAS_PUBLIC_KEY: "" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/mongodb/atlas-sdk-go/auth/clientcredentials" | ||
) | ||
|
||
func main() { | ||
baseURL := strings.TrimRight(os.Getenv("MONGODB_ATLAS_BASE_URL"), "/") | ||
clientID := os.Getenv("MONGODB_ATLAS_CLIENT_ID") | ||
clientSecret := os.Getenv("MONGODB_ATLAS_CLIENT_SECRET") | ||
if baseURL == "" || clientID == "" || clientSecret == "" { | ||
fmt.Fprintln(os.Stderr, "Error: MONGODB_ATLAS_BASE_URL, MONGODB_ATLAS_CLIENT_ID, and MONGODB_ATLAS_CLIENT_SECRET environment variables are required") | ||
os.Exit(1) | ||
} | ||
conf := clientcredentials.NewConfig(clientID, clientSecret) | ||
conf.TokenURL = baseURL + clientcredentials.TokenAPIPath | ||
token, err := conf.Token(context.Background()) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Failed to generate OAuth2 token: %v\n", err) | ||
os.Exit(1) | ||
} | ||
fmt.Print(token.AccessToken) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting way of creating multiline variable. I guess access token spans multiple lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not because multi-line but because characters that need to be escaped so heredoc is used