-
Notifications
You must be signed in to change notification settings - Fork 2
/
Program.cs
135 lines (116 loc) · 4.76 KB
/
Program.cs
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
using System;
using IO.Swagger.Api;
using IO.Swagger.Client;
using System.IO;
using System.Collections.Generic;
namespace SSCUploader
{
class Program
{
static void Main(string[] args)
{
const string PARAM_FPR = "-fpr";
const string PARAM_TOKEN = "-sscToken";
const string PARAM_APP_ID = "-appVersionID";
const string PARAM_SSC_URL = "-sscUrl";
Dictionary<string, string> parameters = new Dictionary<string, string>();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Fortify SSCUploader");
try
{
Console.ForegroundColor = ConsoleColor.Green;
// Display help
if (args.Length == 1 && HelpRequired(args[0]))
{
DisplayHelp();
}
// hopefully you have even number args count.
for (int i = 0; i < args.Length; i += 2)
{
{
parameters.Add(args[i], args[i + 1]);
}
}
// Validate params
if (!parameters.ContainsKey(PARAM_TOKEN))
{
ExitWithError("authToken parameter missing");
}
else if (!parameters.ContainsKey(PARAM_SSC_URL))
{
ExitWithError("sscUrl parameter missing");
}
else if (!parameters.ContainsKey(PARAM_APP_ID))
{
ExitWithError("applicationVersionID parameter missing");
}
else if (!parameters.ContainsKey(PARAM_FPR))
{
ExitWithError("fpr parameter missing");
}
}
catch(Exception paramException)
{
ExitWithError("Invalid parameters - " + paramException.Message );
}
// Does the FPR exist
if(!File.Exists(parameters[PARAM_FPR]))
{
ExitWithError("FPR not found");
}
// Is the SSC Url valid
if (!Uri.IsWellFormedUriString(parameters[PARAM_SSC_URL], UriKind.Absolute))
{
ExitWithError("Invalid SSC Url specified");
}
// Show the paramters passed
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("\r\nParameters");
foreach (var pair in parameters)
{
Console.WriteLine(pair.Key + ": " + pair.Value);
}
// Now start the import
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("\r\nStarting import....");
try
{
Configuration.ApiKey.Add("Authorization", "FortifyToken " + parameters[PARAM_TOKEN]); //Unified Token
var apiClient = new ApiClient("http://localhost:8180/ssc/api/v1");
Configuration.DefaultApiClient = apiClient;
var artifactApi = new ArtifactOfProjectVersionControllerApi(apiClient);
var stream = new System.IO.FileStream(parameters[PARAM_FPR], FileMode.Open);
artifactApi.UploadArtifactOfProjectVersion(Convert.ToInt32(parameters[PARAM_APP_ID]), stream, string.Empty);
Console.WriteLine("\r\nFPR uploaded succesfully");
}
catch(Exception sscException)
{
ExitWithError(sscException.Message);
}
Console.ResetColor();
}
private static void DisplayHelp()
{
Console.WriteLine("SSCUploader help");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("\r\n-fpr: Fully qualified path to the FPR file");
Console.WriteLine("-sscToken: SSC authorization token");
Console.WriteLine("-appVersionID: SSC application Id");
Console.WriteLine("-sscUrl: SSC url. Example: http://myhost/ssc");
Console.WriteLine("\r\nExample: SSCUploader.exe -sscToken MYAUTHTOKEN -fpr C:\\webinspect\\scans\\Scan.fpr -appVersionID 9 -sscUrl http://myhost:8180/ssc/ ");
Console.ResetColor();
Environment.Exit(0);
}
private static bool HelpRequired(string param)
{
return param == "-h" || param == "--help" || param == "/h" || param == "-help" || param == "/?" || param == "-?";
}
private static void ExitWithError(string message)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\r\nError: " + message);
Console.ResetColor();
Environment.Exit(1);
}
}
}