-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
237 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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,49 @@ | ||
{ | ||
"profile_name": "default-profile", | ||
"frogbot_config": { | ||
"email_author": "[email protected]", | ||
"aggregate_fixes": true, | ||
"avoid_previous_pr_comments_deletion": true, | ||
"branch_name_template": "frogbot-${IMPACTED_PACKAGE}-${BRANCH_NAME_HASH}", | ||
"pr_title_template": "[🐸 Frogbot] Upgrade {IMPACTED_PACKAGE} to {FIX_VERSION}", | ||
"pr_comment_title": "Frogbot notes:", | ||
"commit_message_template": "Upgrade {IMPACTED_PACKAGE} to {FIX_VERSION}", | ||
"show_secrets_as_pr_comment": false | ||
}, | ||
"modules": [ | ||
{ | ||
"module_name": "default-module", | ||
"path_from_root": ".", | ||
"releases_repo": "nuget-remote", | ||
"analyzer_manager_version": "1.8.1", | ||
"additional_paths_for_module": ["lib1", "utils/lib2"], | ||
"exclude_paths": ["**/.git/**", "**/*test*/**", "**/*venv*/**", "**/*node_modules*/**", "**/target/**"], | ||
"scan_config": { | ||
"scan_timeout": 600, | ||
"exclude_pattern": "*.md", | ||
"enable_sca_scan": true, | ||
"enable_contextual_analysis_scan": true, | ||
"sast_scanner_config": { | ||
"enable_sast_scan": true | ||
}, | ||
"secrets_scanner_config": { | ||
"enable_secrets_scan": true | ||
}, | ||
"iac_scanner_config": { | ||
"enable_iac_scan": true | ||
}, | ||
"applications_scanner_config": { | ||
"enable_applications_scan": true | ||
}, | ||
"services_scanner_config": { | ||
"enable_services_scan": true | ||
} | ||
}, | ||
"protected_branches": ["main", "master"], | ||
"include_exclude_mode": 0, | ||
"include_exclude_pattern": "*test*", | ||
"report_analytics": true | ||
} | ||
], | ||
"is_default": true | ||
} |
This file contains 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 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,54 @@ | ||
package tests | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/jfrog/jfrog-client-go/http/jfroghttpclient" | ||
"github.com/jfrog/jfrog-client-go/xsc/services" | ||
"github.com/stretchr/testify/assert" | ||
"net/http" | ||
"net/http/httptest" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestGetConfigurationProfile(t *testing.T) { | ||
initXscTest(t, services.ConfigProfileMinXscVersion) | ||
|
||
mockServer, configProfileService := createXscMockServerForConfigProfile(t) | ||
defer mockServer.Close() | ||
|
||
configProfile, err := configProfileService.GetConfigurationProfile("default-test-profile") | ||
assert.NoError(t, err) | ||
|
||
profileFileContent, err := os.ReadFile("testdata/configprofile/configProfileExample.json") | ||
assert.NoError(t, err) | ||
var configProfileForComparison services.ConfigProfile | ||
err = json.Unmarshal(profileFileContent, &configProfileForComparison) | ||
assert.NoError(t, err) | ||
assert.Equal(t, &configProfileForComparison, configProfile) | ||
} | ||
|
||
func createXscMockServerForConfigProfile(t *testing.T) (mockServer *httptest.Server, configProfileService *services.ConfigurationProfileService) { | ||
mockServer = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
if r.RequestURI == "/xsc/api/v1/profile/default-test-profile" && r.Method == http.MethodGet { | ||
w.WriteHeader(http.StatusOK) | ||
content, err := os.ReadFile("testdata/configprofile/configProfileExample.json") | ||
assert.NoError(t, err) | ||
_, err = w.Write(content) | ||
assert.NoError(t, err) | ||
} else { | ||
assert.Fail(t, "received an unexpected request") | ||
} | ||
})) | ||
|
||
xscDetails := GetXscDetails() | ||
xscDetails.SetUrl(mockServer.URL + "/xsc") | ||
xscDetails.SetAccessToken("") | ||
|
||
client, err := jfroghttpclient.JfrogClientBuilder().Build() | ||
assert.NoError(t, err) | ||
|
||
configProfileService = services.NewConfigurationProfileService(client) | ||
configProfileService.XscDetails = xscDetails | ||
return | ||
} |
This file contains 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 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 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 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,113 @@ | ||
package services | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/jfrog/jfrog-client-go/auth" | ||
"github.com/jfrog/jfrog-client-go/http/jfroghttpclient" | ||
"github.com/jfrog/jfrog-client-go/utils" | ||
"github.com/jfrog/jfrog-client-go/utils/errorutils" | ||
"net/http" | ||
) | ||
|
||
const ( | ||
ConfigProfileMinXscVersion = "1.11.0" | ||
xscConfigProfileApi = "api/v1/profile" | ||
) | ||
|
||
type ConfigurationProfileService struct { | ||
client *jfroghttpclient.JfrogHttpClient | ||
XscDetails auth.ServiceDetails | ||
} | ||
|
||
func NewConfigurationProfileService(client *jfroghttpclient.JfrogHttpClient) *ConfigurationProfileService { | ||
return &ConfigurationProfileService{client: client} | ||
} | ||
|
||
type ConfigProfile struct { | ||
ProfileName string `json:"profile_name"` | ||
FrogbotConfig FrogbotConfig `json:"frogbot_config,omitempty"` | ||
Modules []Module `json:"modules"` | ||
IsDefault bool `json:"is_default,omitempty"` | ||
} | ||
|
||
type FrogbotConfig struct { | ||
EmailAuthor string `json:"email_author,omitempty"` | ||
AggregateFixes bool `json:"aggregate_fixes,omitempty"` | ||
AvoidPreviousPrCommentsDeletion bool `json:"avoid_previous_pr_comments_deletion,omitempty"` | ||
BranchNameTemplate string `json:"branch_name_template,omitempty"` | ||
PrTitleTemplate string `json:"pr_title_template,omitempty"` | ||
PrCommentTitle string `json:"pr_comment_title,omitempty"` | ||
CommitMessageTemplate string `json:"commit_message_template,omitempty"` | ||
ShowSecretsAsPrComment bool `json:"show_secrets_as_pr_comment,omitempty"` | ||
} | ||
|
||
type Module struct { | ||
ModuleId int32 `json:"module_id,omitempty"` | ||
ModuleName string `json:"module_name"` | ||
PathFromRoot string `json:"path_from_root"` | ||
ReleasesRepo string `json:"releases_repo,omitempty"` | ||
AnalyzerManagerVersion string `json:"analyzer_manager_version,omitempty"` | ||
AdditionalPathsForModule []string `json:"additional_paths_for_module,omitempty"` | ||
ExcludePaths []string `json:"exclude_paths,omitempty"` | ||
ScanConfig ScanConfig `json:"scan_config"` | ||
ProtectedBranches []string `json:"protected_branches,omitempty"` | ||
IncludeExcludeMode int32 `json:"include_exclude_mode,omitempty"` | ||
IncludeExcludePattern string `json:"include_exclude_pattern,omitempty"` | ||
ReportAnalytics bool `json:"report_analytics,omitempty"` | ||
} | ||
|
||
type ScanConfig struct { | ||
ScanTimeout int32 `json:"scan_timeout,omitempty"` | ||
ExcludePattern string `json:"exclude_pattern,omitempty"` | ||
EnableScaScan bool `json:"enable_sca_scan,omitempty"` | ||
EnableContextualAnalysisScan bool `json:"enable_contextual_analysis_scan,omitempty"` | ||
SastScannerConfig SastScannerConfig `json:"sast_scanner_config,omitempty"` | ||
SecretsScannerConfig SecretsScannerConfig `json:"secrets_scanner_config,omitempty"` | ||
IacScannerConfig IacScannerConfig `json:"iac_scanner_config,omitempty"` | ||
ApplicationsScannerConfig ApplicationsScannerConfig `json:"applications_scanner_config,omitempty"` | ||
ServicesScannerConfig ServicesScannerConfig `json:"services_scanner_config,omitempty"` | ||
} | ||
|
||
type SastScannerConfig struct { | ||
EnableSastScan bool `json:"enable_sast_scan,omitempty"` | ||
Language string `json:"language,omitempty"` | ||
ExcludePatterns []string `json:"exclude_patterns,omitempty"` | ||
ExcludeRules []string `json:"exclude_rules,omitempty"` | ||
} | ||
|
||
type SecretsScannerConfig struct { | ||
EnableSecretsScan bool `json:"enable_secrets_scan,omitempty"` | ||
ExcludePatterns []string `json:"exclude_patterns,omitempty"` | ||
} | ||
|
||
type IacScannerConfig struct { | ||
EnableIacScan bool `json:"enable_iac_scan,omitempty"` | ||
ExcludePatterns []string `json:"exclude_patterns,omitempty"` | ||
} | ||
|
||
type ApplicationsScannerConfig struct { | ||
EnableApplicationsScan bool `json:"enable_applications_scan,omitempty"` | ||
ExcludePatterns []string `json:"exclude_patterns,omitempty"` | ||
} | ||
|
||
type ServicesScannerConfig struct { | ||
EnableServicesScan bool `json:"enable_services_scan,omitempty"` | ||
ExcludePatterns []string `json:"exclude_patterns,omitempty"` | ||
} | ||
|
||
func (cp *ConfigurationProfileService) GetConfigurationProfile(profileName string) (*ConfigProfile, error) { | ||
httpDetails := cp.XscDetails.CreateHttpClientDetails() | ||
url := fmt.Sprintf("%s%s/%s", utils.AddTrailingSlashIfNeeded(cp.XscDetails.GetUrl()), xscConfigProfileApi, profileName) | ||
res, body, _, err := cp.client.SendGet(url, true, &httpDetails) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to send GET query to '%s': %q", url, err) | ||
} | ||
if err = errorutils.CheckResponseStatusWithBody(res, body, http.StatusOK); err != nil { | ||
return nil, err | ||
} | ||
|
||
var profile ConfigProfile | ||
err = errorutils.CheckError(json.Unmarshal(body, &profile)) | ||
return &profile, err | ||
} |