Skip to content

Commit 7fc1be7

Browse files
Merge branch 'main' into feature/alex-containers-default-cloud
2 parents 89dbaef + a2ac965 commit 7fc1be7

File tree

8 files changed

+203
-91
lines changed

8 files changed

+203
-91
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Centralized GitHub Issue Templates for Bug Reports (.github/ISSUE_TEMPLATE/bug_report.yml)
2+
name: Bug Report
3+
description: File a bug report.
4+
title: "[Bug]: "
5+
labels: ["bug"]
6+
projects: []
7+
8+
body:
9+
- type: markdown
10+
attributes:
11+
value: |
12+
Thanks for taking the time to fill out this bug report!
13+
- type: input
14+
id: contact
15+
attributes:
16+
label: Contact Details
17+
description: How can we get in touch with you if we need more info?
18+
placeholder: ex. email@example.com
19+
validations:
20+
required: false
21+
- type: textarea
22+
id: what-happened
23+
attributes:
24+
label: What happened?
25+
description: Also tell us, what did you expect to happen?
26+
placeholder: Tell us what you see!
27+
value: "A bug happened!"
28+
validations:
29+
required: true
30+
- type: input
31+
id: version
32+
attributes:
33+
label: Version
34+
description: What version of our software are you running?
35+
placeholder: Enter the version number
36+
validations:
37+
required: true
38+
- type: dropdown
39+
id: os-version
40+
attributes:
41+
label: Operating System & Version
42+
description: Select your OS and version
43+
options:
44+
- Windows 7
45+
- Windows 8
46+
- Windows 10
47+
- Windows 11
48+
- macOS Big Sur
49+
- macOS Monterey
50+
- macOS Ventura
51+
- macOS Sonoma
52+
- Ubuntu 18.04
53+
- Ubuntu 20.04
54+
- Ubuntu 22.04
55+
- Debian 10
56+
- Debian 11
57+
- Fedora 36
58+
- Fedora 37
59+
- Arch Linux (Latest)
60+
- Red Hat Enterprise Linux 8
61+
- Red Hat Enterprise Linux 9
62+
- openSUSE Leap 15
63+
- Other
64+
validations:
65+
required: true
66+
- type: input
67+
id: os-other
68+
attributes:
69+
label: Specify Other OS Version
70+
description: If you selected "Other," please specify your OS and version.
71+
placeholder: Enter your OS and version
72+
- type: textarea
73+
id: logs
74+
attributes:
75+
label: Relevant log output
76+
description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
77+
render: shell

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
blank_issues_enabled: false

.github/ISSUE_TEMPLATE/enhancement-request.md

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Centralized GitHub Issue Templates for Enhancement Requests (.github/ISSUE_TEMPLATE/enhancement_request.yml)
2+
name: Enhancement Request
3+
description: Suggest a new feature or improvement.
4+
title: "[Enhancement]: "
5+
labels: ["enhancement", "feature-request"]
6+
projects: ["octo-org/1", "octo-org/44"]
7+
assignees:
8+
- octocat
9+
body:
10+
- type: markdown
11+
attributes:
12+
value: |
13+
Thanks for taking the time to suggest an enhancement!
14+
- type: input
15+
id: contact
16+
attributes:
17+
label: Contact Details
18+
description: How can we get in touch with you if we need more info?
19+
placeholder: ex. email@example.com
20+
validations:
21+
required: false
22+
- type: textarea
23+
id: what-problem
24+
attributes:
25+
label: What problem does this solve?
26+
description: Explain the problem this feature would address.
27+
placeholder: Tell us about the problem!
28+
validations:
29+
required: true
30+
- type: textarea
31+
id: proposed-solution
32+
attributes:
33+
label: Proposed Solution
34+
description: How do you think this should be implemented?
35+
placeholder: Describe your idea in detail.
36+
validations:
37+
required: true
38+
- type: dropdown
39+
id: importance
40+
attributes:
41+
label: Importance Level
42+
description: How important is this enhancement to you?
43+
options:
44+
- Nice to have
45+
- Important
46+
- Critical
47+
default: 0
48+
validations:
49+
required: true
50+
- type: textarea
51+
id: additional-info
52+
attributes:
53+
label: Additional Information
54+
description: Any other context, related issues, or screenshots to support your request.

.github/workflows/issue_automation.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ on:
55
types: [opened]
66

77
jobs:
8-
issue:
8+
notify_jira:
99
name: Notify Jira
10-
uses: CheckmarxDev/ast-cli/.github/workflows/jira_notify.yml@main
10+
uses: Checkmarx/plugins-release-workflow/.github/workflows/jira_notify.yml@main
1111
with:
1212
title: ${{ github.event.issue.title }}
1313
body: ${{ github.event.issue.body }}
1414
html_url: ${{ github.event.issue.html_url }}
1515
repo: ${{ github.event.repository.full_name }}
16-
secrets: inherit
16+
secrets: inherit

internal/wrappers/client.go

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ const baseURLKey = "ast-base-url"
7171

7272
const audienceClaimKey = "aud"
7373

74-
var cachedAccessToken string
75-
var cachedAccessTime time.Time
74+
var CachedAccessToken string
75+
var CachedAccessTime time.Time
7676
var Domains = make(map[string]struct{})
7777

7878
func retryHTTPRequest(requestFunc func() (*http.Response, error), retries int, baseDelayInMilliSec time.Duration) (*http.Response, error) {
@@ -85,7 +85,12 @@ func retryHTTPRequest(requestFunc func() (*http.Response, error), retries int, b
8585
if err != nil {
8686
return nil, err
8787
}
88-
if resp.StatusCode != http.StatusBadGateway {
88+
if resp.StatusCode == http.StatusBadGateway {
89+
logger.PrintIfVerbose("Bad Gateway (502), retrying")
90+
} else if resp.StatusCode == http.StatusUnauthorized {
91+
logger.PrintIfVerbose("Unauthorized request (401), refreshing token")
92+
_, _ = configureClientCredentialsAndGetNewToken()
93+
} else {
8994
return resp, nil
9095
}
9196
_ = resp.Body.Close()
@@ -398,27 +403,21 @@ func GetWithQueryParamsAndCustomRequest(client *http.Client, customReq *http.Req
398403
customReq = addReqMonitor(customReq)
399404
return request(client, customReq, true)
400405
}
406+
401407
func GetAccessToken() (string, error) {
402-
authURI, err := GetAuthURI()
403-
if err != nil {
404-
return "", err
405-
}
408+
var err error
406409
tokenExpirySeconds := viper.GetInt(commonParams.TokenExpirySecondsKey)
410+
407411
accessToken := getClientCredentialsFromCache(tokenExpirySeconds)
408-
accessKeyID := viper.GetString(commonParams.AccessKeyIDConfigKey)
409-
accessKeySecret := viper.GetString(commonParams.AccessKeySecretConfigKey)
410-
astAPIKey := viper.GetString(commonParams.AstAPIKey)
411-
if accessKeyID == "" && astAPIKey == "" {
412-
return "", errors.Errorf(fmt.Sprintf(FailedToAuth, "access key ID"))
413-
} else if accessKeySecret == "" && astAPIKey == "" {
414-
return "", errors.Errorf(fmt.Sprintf(FailedToAuth, "access key secret"))
415-
}
412+
416413
if accessToken == "" {
417-
accessToken, err = getClientCredentials(accessKeyID, accessKeySecret, astAPIKey, authURI)
414+
logger.PrintIfVerbose("Fetching API access token.")
415+
accessToken, err = configureClientCredentialsAndGetNewToken()
418416
if err != nil {
419417
return "", err
420418
}
421419
}
420+
422421
return accessToken, nil
423422
}
424423

@@ -445,38 +444,45 @@ func enrichWithPasswordCredentials(
445444
return nil
446445
}
447446

448-
func getClientCredentials(accessKeyID, accessKeySecret, astAPKey, authURI string) (string, error) {
449-
logger.PrintIfVerbose("Fetching API access token.")
450-
tokenExpirySeconds := viper.GetInt(commonParams.TokenExpirySecondsKey)
447+
func configureClientCredentialsAndGetNewToken() (string, error) {
448+
accessKeyID := viper.GetString(commonParams.AccessKeyIDConfigKey)
449+
accessKeySecret := viper.GetString(commonParams.AccessKeySecretConfigKey)
450+
astAPIKey := viper.GetString(commonParams.AstAPIKey)
451+
var accessToken string
451452

452-
var err error
453-
accessToken := getClientCredentialsFromCache(tokenExpirySeconds)
453+
if accessKeyID == "" && astAPIKey == "" {
454+
return "", errors.Errorf(fmt.Sprintf(FailedToAuth, "access key ID"))
455+
} else if accessKeySecret == "" && astAPIKey == "" {
456+
return "", errors.Errorf(fmt.Sprintf(FailedToAuth, "access key secret"))
457+
}
454458

455-
if accessToken == "" {
456-
// If the token is present the default to that.
457-
if astAPKey != "" {
458-
accessToken, err = getNewToken(getAPIKeyPayload(astAPKey), authURI)
459-
} else {
460-
accessToken, err = getNewToken(getCredentialsPayload(accessKeyID, accessKeySecret), authURI)
461-
}
459+
authURI, err := GetAuthURI()
460+
if err != nil {
461+
return "", err
462+
}
462463

463-
if err != nil {
464-
return "", errors.Errorf("%s", err)
465-
}
464+
if astAPIKey != "" {
465+
accessToken, err = getNewToken(getAPIKeyPayload(astAPIKey), authURI)
466+
} else {
467+
accessToken, err = getNewToken(getCredentialsPayload(accessKeyID, accessKeySecret), authURI)
468+
}
466469

467-
writeCredentialsToCache(accessToken)
470+
if err != nil {
471+
return "", errors.Errorf("%s", err)
468472
}
469473

474+
writeCredentialsToCache(accessToken)
475+
470476
return accessToken, nil
471477
}
472478

473479
func getClientCredentialsFromCache(tokenExpirySeconds int) string {
474480
logger.PrintIfVerbose("Checking cache for API access token.")
475481

476-
expired := time.Since(cachedAccessTime) > time.Duration(tokenExpirySeconds-expiryGraceSeconds)*time.Second
482+
expired := time.Since(CachedAccessTime) > time.Duration(tokenExpirySeconds-expiryGraceSeconds)*time.Second
477483
if !expired {
478484
logger.PrintIfVerbose("Using cached API access token!")
479-
return cachedAccessToken
485+
return CachedAccessToken
480486
}
481487
logger.PrintIfVerbose("API access token not found in cache!")
482488
return ""
@@ -488,8 +494,8 @@ func writeCredentialsToCache(accessToken string) {
488494

489495
logger.PrintIfVerbose("Storing API access token to cache.")
490496
viper.Set(commonParams.AstToken, accessToken)
491-
cachedAccessToken = accessToken
492-
cachedAccessTime = time.Now()
497+
CachedAccessToken = accessToken
498+
CachedAccessTime = time.Now()
493499
}
494500

495501
func getNewToken(credentialsPayload, authServerURI string) (string, error) {
@@ -555,13 +561,13 @@ func getCredentialsPayload(accessKeyID, accessKeySecret string) string {
555561

556562
func getAPIKeyPayload(astToken string) string {
557563
logger.PrintIfVerbose("Using API key credentials.")
558-
564+
559565
clientID, err := extractAZPFromToken(astToken)
560566
if err != nil {
561567
logger.PrintIfVerbose("Failed to extract azp from token, using default client_id")
562568
clientID = "ast-app"
563569
}
564-
570+
565571
return fmt.Sprintf("grant_type=refresh_token&client_id=%s&refresh_token=%s", clientID, astToken)
566572
}
567573

test/integration/scan_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,6 +2021,30 @@ func TestCreateScanWithResubmitFlag_ProjectNotExist_ScanCreatedSuccessfullyWithD
20212021
err, _ := executeCommand(t, args...)
20222022
assert.NilError(t, err)
20232023
}
2024+
2025+
func TestCreateAsyncScan_ChangedCachedTokenAndPollingScanStatus_Success(t *testing.T) {
2026+
createASTIntegrationTestCommand(t)
2027+
configuration.LoadConfiguration()
2028+
args := []string{
2029+
"scan", "create",
2030+
flag(params.ProjectName), getProjectNameForScanTests(),
2031+
flag(params.SourcesFlag), "data/empty-folder.zip",
2032+
flag(params.ScanTypes), "sca",
2033+
flag(params.BranchFlag), "main",
2034+
flag(params.AsyncFlag),
2035+
flag(params.ScanInfoFormatFlag), printer.FormatJSON,
2036+
}
2037+
scanID, _ := executeCreateScan(t, args)
2038+
scanWrapper := wrappers.NewHTTPScansWrapper(viper.GetString(params.ScansPathKey))
2039+
wrappers.CachedAccessToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlhdCI6MTUxNjIzOTAyMiwiaXNzIjoiaHR0cHM6Ly9kZXUuaWFtLmNoZWNrbWFyeC5uZXQvYXV0aC9yZWFsbXMvZ2FsYWN0aWNhIiwiYXN0LWJhc2UtdXJsIjoiaHR0cHM6Ly9kZXUuYXN0LmNoZWNrbWFyeC5uZXQifQ.j0MMhLKBkmvJ_vz5xjvvut5UfN7OJVPqV-RwJ3NdKD4"
2040+
wrappers.CachedAccessTime = time.Now()
2041+
viper.Set(params.TokenExpirySecondsKey, 300)
2042+
scan, _, err := scanWrapper.GetByID(scanID)
2043+
asserts.Nil(t, err)
2044+
assert.Assert(t, scan != nil, "Scan should not be nil")
2045+
assert.Equal(t, scan.ID, scanID, "Scan ID should be equal")
2046+
}
2047+
20242048
func TestScanCreate_WithContainerFilterFlags_CreatingScanSuccessfully(t *testing.T) {
20252049
bindKeysToEnvAndDefault(t)
20262050
var createdScan wrappers.ScanResponseModel

0 commit comments

Comments
 (0)