Merge pull request #1130 from dwertent/update-utm-link-v2

docs(links): Update URLs
This commit is contained in:
David Wertenteil
2023-03-06 14:08:25 +02:00
committed by GitHub
7 changed files with 104 additions and 56 deletions
+1 -1
View File
@@ -78,7 +78,7 @@ func getReporter(ctx context.Context, tenantConfig cautils.ITenantConfig, report
}
if tenantConfig.GetAccountID() == "" {
// Add link only when scanning a cluster using a framework
return reporterv2.NewReportMock("https://hub.armosec.io/docs/installing-kubescape", "run kubescape with the '--account' flag")
return reporterv2.NewReportMock("", "")
}
var message string
if !fwScan {
@@ -7,8 +7,11 @@ import (
"os"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/pkg/resultshandling/reporter"
)
var _ reporter.IReport = &ReportMock{}
type ReportMock struct {
query string
message string
@@ -36,17 +39,19 @@ func (reportMock *ReportMock) GetURL() string {
return ""
}
q := u.Query()
q.Add("utm_source", "GitHub")
q.Add("utm_medium", "CLI")
q.Add("utm_campaign", "Submit")
u.RawQuery = q.Encode()
return u.String()
}
func (reportMock *ReportMock) DisplayReportURL() {
if m := reportMock.strToDisplay(); m != "" {
cautils.InfoTextDisplay(os.Stderr, m)
}
}
func (reportMock *ReportMock) strToDisplay() string {
if reportMock.message == "" {
return ""
}
sep := "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
message := sep + "\n"
@@ -55,5 +60,5 @@ func (reportMock *ReportMock) DisplayReportURL() {
message += "For more details: " + link + "\n"
}
message += sep + "\n"
cautils.InfoTextDisplay(os.Stderr, fmt.Sprintf("\n%s\n", message))
return fmt.Sprintf("\n%s\n", message)
}
@@ -1,10 +1,13 @@
package reporter
import "testing"
import (
"testing"
)
func TestReportMock_GetURL(t *testing.T) {
type fields struct {
query string
query string
message string
}
tests := []struct {
name string
@@ -13,19 +16,17 @@ func TestReportMock_GetURL(t *testing.T) {
}{
{
name: "TestReportMock_GetURL",
fields: struct {
query string
}{
query: "https://kubescape.io",
fields: fields{
query: "https://kubescape.io",
message: "some message",
},
want: "https://kubescape.io?utm_campaign=Submit&utm_medium=CLI&utm_source=GitHub",
want: "https://kubescape.io",
},
{
name: "TestReportMock_GetURL_empty",
fields: struct {
query string
}{
query: "",
fields: fields{
query: "",
message: "",
},
want: "",
},
@@ -33,7 +34,8 @@ func TestReportMock_GetURL(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
reportMock := &ReportMock{
query: tt.fields.query,
query: tt.fields.query,
message: tt.fields.message,
}
if got := reportMock.GetURL(); got != tt.want {
t.Errorf("ReportMock.GetURL() = %v, want %v", got, tt.want)
@@ -41,3 +43,43 @@ func TestReportMock_GetURL(t *testing.T) {
})
}
}
func TestReportMock_strToDisplay(t *testing.T) {
type fields struct {
query string
message string
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "TestReportMock_strToDisplay",
fields: fields{
query: "https://kubescape.io",
message: "some message",
},
want: "\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nScan results have not been submitted: some message\nFor more details: https://kubescape.io\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n",
},
{
name: "TestReportMock_strToDisplay_empty",
fields: fields{
query: "https://kubescape.io",
message: "",
},
want: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
reportMock := &ReportMock{
query: tt.fields.query,
message: tt.fields.message,
}
if got := reportMock.strToDisplay(); got != tt.want {
t.Errorf("ReportMock.strToDisplay() = %v, want %v", got, tt.want)
}
})
}
}
@@ -14,6 +14,7 @@ import (
"github.com/kubescape/k8s-interface/workloadinterface"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/kubescape/v2/core/cautils/getter"
"github.com/kubescape/kubescape/v2/core/pkg/resultshandling/reporter"
"github.com/kubescape/opa-utils/reporthandling"
"github.com/kubescape/opa-utils/reporthandling/results/v1/prioritization"
"github.com/kubescape/opa-utils/reporthandling/results/v1/resourcesresults"
@@ -31,6 +32,8 @@ const (
SubmitContextRepository SubmitContext = "repository"
)
var _ reporter.IReport = &ReportEventReceiver{}
type ReportEventReceiver struct {
httpClient *http.Client
clusterName string
@@ -121,13 +124,6 @@ func (report *ReportEventReceiver) GetURL() string {
parseHost(&u)
report.addPathURL(&u)
q := u.Query()
q.Add("utm_source", "GitHub")
q.Add("utm_medium", "CLI")
q.Add("utm_campaign", "Submit")
u.RawQuery = q.Encode()
return u.String()
}
@@ -286,6 +282,10 @@ func (report *ReportEventReceiver) addPathURL(urlObj *url.URL) {
q := urlObj.Query()
q.Add("invitationToken", report.token)
q.Add("customerGUID", report.customerGUID)
// Adding utm parameters
q.Add("utm_source", "ARMOgithub")
q.Add("utm_medium", "createaccount")
urlObj.RawQuery = q.Encode()
}
@@ -11,13 +11,13 @@ import (
func TestReportEventReceiver_addPathURL(t *testing.T) {
tests := []struct {
name string
report *ReportEventReceiver
urlObj *url.URL
want *url.URL
name string
}{
{
name: "add scan path",
name: "URL for submitted data",
report: &ReportEventReceiver{
clusterName: "test",
customerGUID: "FFFF",
@@ -31,9 +31,30 @@ func TestReportEventReceiver_addPathURL(t *testing.T) {
Host: "localhost:8080",
},
want: &url.URL{
Scheme: "https",
Host: "localhost:8080",
Path: "compliance/test",
RawQuery: "",
},
},
{
name: "URL for first scan",
report: &ReportEventReceiver{
clusterName: "test",
customerGUID: "FFFF",
token: "XXXX",
reportID: "1234",
submitContext: SubmitContextScan,
},
urlObj: &url.URL{
Scheme: "https",
Host: "localhost:8080",
Path: "compliance/test",
},
want: &url.URL{
Scheme: "https",
Host: "localhost:8080",
Path: "account/sign-up",
RawQuery: "customerGUID=FFFF&invitationToken=XXXX&utm_medium=createaccount&utm_source=ARMOgithub",
},
},
}
@@ -59,7 +80,7 @@ func TestGetURL(t *testing.T) {
"",
SubmitContextScan,
)
assert.Equal(t, "https://cloud.armosec.io/compliance/test?utm_campaign=Submit&utm_medium=CLI&utm_source=GitHub", reporter.GetURL())
assert.Equal(t, "https://cloud.armosec.io/compliance/test", reporter.GetURL())
}
// Test rbac submit and registered url
@@ -74,7 +95,7 @@ func TestGetURL(t *testing.T) {
"",
SubmitContextRBAC,
)
assert.Equal(t, "https://cloud.armosec.io/rbac-visualizer?utm_campaign=Submit&utm_medium=CLI&utm_source=GitHub", reporter.GetURL())
assert.Equal(t, "https://cloud.armosec.io/rbac-visualizer", reporter.GetURL())
}
// Test repo submit and registered url
@@ -89,7 +110,7 @@ func TestGetURL(t *testing.T) {
"XXXX",
SubmitContextRepository,
)
assert.Equal(t, "https://cloud.armosec.io/repository-scanning/XXXX?utm_campaign=Submit&utm_medium=CLI&utm_source=GitHub", reporter.GetURL())
assert.Equal(t, "https://cloud.armosec.io/repository-scanning/XXXX", reporter.GetURL())
}
// Test submit and NOT registered url
@@ -104,7 +125,7 @@ func TestGetURL(t *testing.T) {
"",
SubmitContextScan,
)
assert.Equal(t, "https://cloud.armosec.io/account/sign-up?customerGUID=1234&invitationToken=token&utm_campaign=Submit&utm_medium=CLI&utm_source=GitHub", reporter.GetURL())
assert.Equal(t, "https://cloud.armosec.io/account/sign-up?customerGUID=1234&invitationToken=token&utm_medium=createaccount&utm_source=ARMOgithub", reporter.GetURL())
}
}
@@ -5,26 +5,6 @@ import (
"strings"
)
/* unused for now
func maskID(id string) string {
sep := "-"
splitted := strings.Split(id, sep)
if len(splitted) != 5 {
return ""
}
str := splitted[0][:4]
splitted[0] = splitted[0][4:]
for i := range splitted {
for j := 0; j < len(splitted[i]); j++ {
str += "X"
}
str += sep
}
return strings.TrimSuffix(str, sep)
}
*/
func parseHost(urlObj *url.URL) {
if strings.Contains(urlObj.Host, "http://") {
urlObj.Scheme = "http"
+1 -1
View File
@@ -1,6 +1,6 @@
<img src="armo-powered-by-kubescape-logo-grey.svg" width="25%" height="25%" align="right">
[ARMO Platform](https://cloud.armosec.io/account/sign-up) is an enterprise solution based on Kubescape. Its a multi-cloud Kubernetes and CI/CD security platform with a single pane of glass including risk analysis, security compliance, misconfiguration, image vulnerability, repository and registry scanning, RBAC visualization, and more.
[ARMO Platform](https://cloud.armosec.io/account/sign-up?utm_source=ARMOgithub&utm_medium=ARMOcli) is an enterprise solution based on Kubescape. Its a multi-cloud Kubernetes and CI/CD security platform with a single pane of glass including risk analysis, security compliance, misconfiguration, image vulnerability, repository and registry scanning, RBAC visualization, and more.
## Connect Kubescape to ARMO Platform
Step #1: Install Kubescape in your CLI