This repository has been archived by the owner on Mar 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplatform_url.go
150 lines (111 loc) · 2.96 KB
/
platform_url.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package main
import (
"fmt"
"os"
"strconv"
"strings"
"github.com/fatih/color"
)
var supportedPages = []string{
"ReviewResultsStaticFlaws",
"ReviewResultsAllFlaws",
"AnalyzeAppModuleList",
"StaticOverview",
"AnalyzeAppSourceFiles",
"ViewReportsResultSummary",
"ViewReportsDetailedReport"}
func platformUrlInvalid(url string) {
color.HiRed(
fmt.Sprintf("%s is not a valid or supported Veracode Platform URL.\nThis tool requires a URL to one of the following Veracode Platform pages: %s",
url,
strings.Join(supportedPages, ", ")))
os.Exit(1)
}
func isPlatformURL(url string) bool {
return strings.HasPrefix(url, "https://analysiscenter.veracode.com/auth/index.jsp") ||
strings.HasPrefix(url, "https://analysiscenter.veracode.us/auth/index.jsp") ||
strings.HasPrefix(url, "https://analysiscenter.veracode.eu/auth/index.jsp")
}
func isParseableURL(urlFragment string) bool {
for _, page := range supportedPages {
if strings.HasPrefix(urlFragment, page) {
return true
}
}
return false
}
func parseRegionFromUrl(url string) string {
if strings.HasPrefix(url, "https://analysiscenter.veracode.us") {
return "us"
}
if strings.HasPrefix(url, "https://analysiscenter.veracode.eu") {
return "european"
}
return "commercial"
}
func parseBaseUrlFromRegion(region string) string {
if region == "us" {
return "https://analysiscenter.veracode.us"
}
if region == "european" {
return "https://analysiscenter.veracode.eu"
}
return "https://analysiscenter.veracode.com"
}
func parseAccountIdFromPlatformUrl(urlOrAccountId string) int {
accountId, err := strconv.Atoi(urlOrAccountId)
if err == nil {
return accountId
}
if !isPlatformURL(urlOrAccountId) {
platformUrlInvalid(urlOrAccountId)
}
var urlFragment = strings.Split(urlOrAccountId, "#")[1]
if isParseableURL(urlFragment) {
accountId, err := strconv.Atoi(strings.Split(urlFragment, ":")[1])
if err != nil {
platformUrlInvalid(urlOrAccountId)
}
return accountId
}
platformUrlInvalid(urlOrAccountId)
return -1
}
func parseAppIdFromPlatformUrl(urlOrAppId string) int {
appId, err := strconv.Atoi(urlOrAppId)
if err == nil {
return appId
}
if !isPlatformURL(urlOrAppId) {
platformUrlInvalid(urlOrAppId)
}
var urlFragment = strings.Split(urlOrAppId, "#")[1]
if isParseableURL(urlFragment) {
appId, err := strconv.Atoi(strings.Split(urlFragment, ":")[2])
if err != nil {
platformUrlInvalid(urlOrAppId)
}
return appId
}
platformUrlInvalid(urlOrAppId)
return -1
}
func parseBuildIdFromPlatformUrl(urlOrBuildId string) int {
buildId, err := strconv.Atoi(urlOrBuildId)
if err == nil {
return buildId
}
if !isPlatformURL(urlOrBuildId) {
platformUrlInvalid(urlOrBuildId)
}
var urlFragment = strings.Split(urlOrBuildId, "#")[1]
if isParseableURL(urlFragment) {
buildId, err := strconv.Atoi(strings.Split(urlFragment, ":")[3])
if err != nil {
platformUrlInvalid(urlOrBuildId)
}
return buildId
}
platformUrlInvalid(urlOrBuildId)
return -1
}