-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
394 lines (313 loc) · 18.5 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using YamlDotNet.Serialization;
using System.Text;
namespace ServiceBrokerDocGen
{
class Program
{
static void Main(string[] args)
{
LoadJsonTemplate();
}
static string path = "";
static void LoadJsonTemplate()
{
Console.WriteLine(" ");
Console.WriteLine("Welcome.");
Console.WriteLine("This program automatically creates the Service Broker doc Readme.md from the Cloudformation Template provided.");
Console.WriteLine("==========================================================================================================");
Console.WriteLine("IMPORTANT: Ensure the Template contains the 'AWS::ServiceBroker::Specification' section before proceeding");
Console.WriteLine(" ");
Console.WriteLine("Enter in path to '.json' cloudformation template:");
string input = Console.ReadLine();
path = input;
try
{
string json = "";
using (StreamReader r = new StreamReader(input))
{
json = r.ReadToEnd();
}
TraverseJson(json);
}
catch (Exception ex)
{
Console.WriteLine("ERROR: " + ex.Message);
Console.WriteLine(" ");
Console.WriteLine("Press Key to retry");
Console.ReadKey();
Console.Clear();
LoadJsonTemplate();
}
}
static void TraverseJson(string json)
{
JObject rss = JObject.Parse(json);
AWSServiceBrokerSpecification AWSSvBSpec = new AWSServiceBrokerSpecification();
try
{
AWSSvBSpec.Name = (string)rss["Metadata"]["AWS::ServiceBroker::Specification"]["Name"] ?? "Short Product Name Goes Here";
AWSSvBSpec.DisplayName = (string)rss["Metadata"]["AWS::ServiceBroker::Specification"]["DisplayName"] ?? "Display Product Name Goes Here";
AWSSvBSpec.LongDescription = (string)rss["Metadata"]["AWS::ServiceBroker::Specification"]["LongDescription"] ?? "Long Description Goes Here";
AWSSvBSpec.ImageUrl = (string)rss["Metadata"]["AWS::ServiceBroker::Specification"]["ImageUrl"] ?? "Image Url Goes Here";
AWSSvBSpec.DocumentationUrl = (string)rss["Metadata"]["AWS::ServiceBroker::Specification"]["DocumentationUrl"] ?? "Documentation Url Goes Here";
AWSSvBSpec.Cost = (string)rss["Metadata"]["AWS::ServiceBroker::Specification"]["ServicePlans"]["production"]["Cost"] ?? "Cost Url Goes Here";
}
catch (Exception ex)
{
Console.Write("Error: Ensure the file contains the AWS::ServiceBroker::Specification section before attempting to create the Readme.md");
throw ex;
}
var Params = new List<Parameter>();
foreach (JProperty item in rss["Parameters"])
{
Parameter param = new Parameter();
param.Name = item.Name;
param.Default = (string)item.Value["Default"];
param.Description = (string)item.Value["Description"];
param.Type = (string)item.Value["Type"];
param.AllowedValues = (JArray)item.Value["AllowedValues"];
Params.Add(param);
}
CreateMarkDown(AWSSvBSpec, Params);
}
static void CreateMarkDown(AWSServiceBrokerSpecification AWSSvBSpec, List<Parameter> Params)
{
//Symbols
var CarriageRtn = "\n\r";
var NewLine = "\r";
//Skeleton
var Content = "";
Content += "# AWS Service Broker - " + AWSSvBSpec.DisplayName + CarriageRtn;
Content += @"<img align=""left"" src=""https://s3.amazonaws.com/awsservicebroker/icons/aws-service-broker.png"" width=""120""><img align=""right"" src=" + AWSSvBSpec.ImageUrl + @" width=""108"">";
Content += @"<p align=""center"">" + AWSSvBSpec.LongDescription + "</p>" + " " + CarriageRtn;
Content += "Table of contents" + NewLine;
Content += "=================" + CarriageRtn;
Content += "* [Parameters](#parameters)" + NewLine;
Content += " * [production](#param-production)" + NewLine;
Content += " * [dev](#param-dev)" + NewLine;
Content += " * [custom](#param-custom)" + NewLine;
Content += "* [Bind Credentials](#bind-credentials)" + NewLine;
Content += "* [Examples](#kubernetes-openshift-examples)" + NewLine;
Content += " * [production](#example-production)" + NewLine;
Content += " * [dev](#example-dev)" + NewLine;
Content += " * [custom](#example-custom)" + CarriageRtn;
Content += @"<a id=""parameters""></a>" + CarriageRtn;
Content += "# Parameters" + CarriageRtn;
/******PRODUCTION*****/
Content += @"<a id = ""param-production""></a>" + CarriageRtn;
Content += "Creates an " + AWSSvBSpec.DisplayName + " optimised for production use. " + NewLine;
Content += "Pricing: " + AWSSvBSpec.Cost + CarriageRtn;
Content += @"### Required" + CarriageRtn;
Content += "At a minimum these parameters must be declared when provisioning an instance of this service" + CarriageRtn;
var TableRequired = @"Name | Description | Accepted Values" + NewLine;
TableRequired += "-------------- | --------------- | ---------------" + NewLine;
foreach (var item in Params)
{
TableRequired += item.Name + "|" + item.Description + "|" + item.Default + NewLine;
}
Content += TableRequired + CarriageRtn;
Content += "### Optional" + CarriageRtn;
Content += "These parameters can optionally be declared when provisioning" + CarriageRtn;
var TableOptional = @"Name | Description | Default | Accepted Values" + NewLine;
TableOptional += "--------------- | --------------- | --------------- | ---------------" + NewLine;
foreach (var item in Params)
{
if (item.AllowedValues != null)
{
string allowedValues = String.Join(", ", item.AllowedValues);
TableOptional += item.Name + "|" + item.Description + "|" + item.Default + "|" + allowedValues + NewLine;
}
}
Content += TableOptional + CarriageRtn;
Content += @"### Generic" + CarriageRtn;
Content += "These parameters are required, but generic or require privileged access to the underlying AWS account, we recommend they are configured with a broker secret, see [broker documentation](/docs/) for details." + CarriageRtn;
var TableGeneric = @"Name | Description | Default | Accepted Values" + NewLine;
TableGeneric += "--------------- | --------------- | --------------- | ---------------" + NewLine;
TableGeneric += "target_account_id | AWS Account ID to provision into(optional) ||" + NewLine;
TableGeneric += "target_role_name | IAM Role name to provision with(optional), must be used in combination with target_account_id ||" + NewLine;
TableGeneric += "region | AWS Region to create RDS instance in.| us-west-2 | ap-northeast-1, ap-northeast-2, ap-south-1, ap-southeast-1, ap-southeast-2, ca-central-1, eu-central-1, eu-west-1, eu-west-2, sa-east-1, us-east-1, us-east-2, us-west-1, us-west-2" + NewLine;
Content += TableGeneric + CarriageRtn;
Content += @"### Prescribed" + CarriageRtn;
Content += "These are parameters that are prescribed by the plan and are not configurable, should adjusting any of these be required please choose a plan that makes them available." + CarriageRtn;
Content += TableRequired + CarriageRtn;
/******DEVELOPMENT*****/
Content += @"<a id = ""param-dev""></a>" + CarriageRtn;
Content += "Creates an " + AWSSvBSpec.DisplayName + " optimised for dev/test use. " + NewLine;
Content += "Pricing: " + AWSSvBSpec.Cost + CarriageRtn;
Content += @"### Required" + CarriageRtn;
Content += "At a minimum these parameters must be declared when provisioning an instance of this service" + CarriageRtn;
Content += TableRequired + CarriageRtn;
Content += "### Optional" + CarriageRtn;
Content += "These parameters can optionally be declared when provisioning" + CarriageRtn;
Content += TableOptional + CarriageRtn;
Content += @"### Generic" + CarriageRtn;
Content += "These parameters are required, but generic or require privileged access to the underlying AWS account, we recommend they are configured with a broker secret, see [broker documentation](/docs/) for details." + CarriageRtn;
Content += TableGeneric + CarriageRtn;
Content += @"### Prescribed" + CarriageRtn;
Content += "These are parameters that are prescribed by the plan and are not configurable, should adjusting any of these be required please choose a plan that makes them available." + CarriageRtn;
Content += TableRequired + CarriageRtn;
/******CUSTOM*****/
Content += @"<a id = ""param-custom""></a>" + CarriageRtn;
Content += "Creates an " + AWSSvBSpec.DisplayName + " with custom configuration. " + NewLine;
Content += "Pricing: " + AWSSvBSpec.Cost + CarriageRtn;
Content += @"### Required" + CarriageRtn;
Content += "At a minimum these parameters must be declared when provisioning an instance of this service" + CarriageRtn;
Content += TableRequired + CarriageRtn;
Content += "### Optional" + CarriageRtn;
Content += "These parameters can optionally be declared when provisioning" + CarriageRtn;
var TableCustom = @"Name | Description | Default | Accepted Values" + NewLine;
TableCustom += "--------------- | --------------- | --------------- | ---------------" + NewLine;
foreach (var item in Params)
{
string allowedValues = "";
if (item.AllowedValues != null)
{
allowedValues = String.Join(", ", item.AllowedValues);
}
TableCustom += item.Name + "|" + item.Description + "|" + item.Default + "|" + allowedValues + NewLine;
}
Content += TableCustom + CarriageRtn;
Content += @"### Generic" + CarriageRtn;
Content += "These parameters are required, but generic or require privileged access to the underlying AWS account, we recommend they are configured with a broker secret, see [broker documentation](/docs/) for details." + CarriageRtn;
Content += TableGeneric + CarriageRtn;
/***BIND CREDNTIALS ***/
Content += @"<a id=""bind-credentials""></a>" + CarriageRtn;
Content += "# Bind Credentials" + CarriageRtn;
Content += "These are the environment variables that are available to an application on bind." + CarriageRtn;
var TableBindCr = @"Name | Description" + NewLine;
TableBindCr += "-------------- | ---------------" + NewLine;
Content += TableBindCr + CarriageRtn;
//==================================================
//End of Skeleton
//Start of K8 section Skeleton
//==================================================
//Get Parameters to add into K8 setion
string K8Params = "";
foreach (var item in Params)
{
string ParamValue = item.Default ?? "[VALUE]";
K8Params += "".PadRight(4) + item.Name + ": " + ParamValue + NewLine;
}
//==================================================
Content += @"# Kubernetes/Openshift Examples" + CarriageRtn;
Content += @"***Note:*** Examples do not include generic parameters, if you have not setup defaults for these you will need to add them as additional parameters" + CarriageRtn;
//Production
Content += @"<a id =""example-production""></a>" + CarriageRtn;
Content += "## production" + CarriageRtn;
Content += "### Minimal" + NewLine;
Content += "```yaml" + NewLine;
Content += "apiVersion: servicecatalog.k8s.io / v1beta1" + NewLine;
Content += "kind: ServiceInstance" + NewLine;
Content += "metadata: " + NewLine;
Content += " name: " + AWSSvBSpec.Name+"-production-complete-example" + NewLine;
Content += "spec: " + NewLine;
Content += " clusterServiceClassExternalName: " + AWSSvBSpec.Name + NewLine;
Content += " clusterServicePlanExternalName: production" + NewLine;
Content += " parameters: " + NewLine;
Content += K8Params;
Content += "```" + CarriageRtn + NewLine;
Content += "### Complete" + NewLine;
Content += "```yaml" + NewLine;
Content += "apiVersion: servicecatalog.k8s.io / v1beta1" + NewLine;
Content += "kind: ServiceInstance" + NewLine;
Content += "metadata: " + NewLine;
Content += " name: " + AWSSvBSpec.Name + "-production-complete-example" + NewLine;
Content += "spec: " + NewLine;
Content += " clusterServiceClassExternalName: " + AWSSvBSpec.Name + NewLine;
Content += " clusterServicePlanExternalName: production" + NewLine;
Content += " parameters: " + NewLine;
Content += K8Params;
Content += "```" + CarriageRtn + NewLine;
//Development
Content += @"<a id=""example-dev""></a>" + CarriageRtn;
Content += @"## dev" + CarriageRtn;
Content += "### Minimal" + NewLine;
Content += "```yaml" + NewLine;
Content += "apiVersion: servicecatalog.k8s.io / v1beta1" + NewLine;
Content += "kind: ServiceInstance" + NewLine;
Content += "metadata: " + NewLine;
Content += " name: " + AWSSvBSpec.Name + "-dev-complete-example" + NewLine;
Content += "spec: " + NewLine;
Content += " clusterServiceClassExternalName: " + AWSSvBSpec.Name + NewLine;
Content += " clusterServicePlanExternalName: dev" + NewLine;
Content += " parameters: " + NewLine;
Content += K8Params;
Content += "```" + CarriageRtn + NewLine;
Content += "### Complete" + NewLine;
Content += "```yaml" + NewLine;
Content += "apiVersion: servicecatalog.k8s.io / v1beta1" + NewLine;
Content += "kind: ServiceInstance" + NewLine;
Content += "metadata: " + NewLine;
Content += " name: " + AWSSvBSpec.Name + "-dev-complete-example" + NewLine;
Content += "spec: " + NewLine;
Content += " clusterServiceClassExternalName: " + AWSSvBSpec.Name + NewLine;
Content += " clusterServicePlanExternalName: dev" + NewLine;
Content += " parameters: " + NewLine;
Content += K8Params;
Content += "```" + CarriageRtn + NewLine;
//Custom
Content += @"<a id = ""example-custom""></a>" + CarriageRtn;
Content += @"## custom" + CarriageRtn;
Content += "### Minimal" + NewLine;
Content += "```yaml" + NewLine;
Content += "apiVersion: servicecatalog.k8s.io / v1beta1" + NewLine;
Content += "kind: ServiceInstance" + NewLine;
Content += "metadata: " + NewLine;
Content += " name: " + AWSSvBSpec.Name + "-custom-complete-example" + NewLine;
Content += "spec: " + NewLine;
Content += " clusterServiceClassExternalName: " + AWSSvBSpec.Name + NewLine;
Content += " clusterServicePlanExternalName: custom" + NewLine;
Content += " parameters: " + NewLine;
Content += K8Params;
Content += "```" + CarriageRtn + NewLine;
Content += "### Complete" + NewLine;
Content += "```yaml" + NewLine;
Content += "apiVersion: servicecatalog.k8s.io / v1beta1" + NewLine;
Content += "kind: ServiceInstance" + NewLine;
Content += "metadata: " + NewLine;
Content += " name: " + AWSSvBSpec.Name + "-custom-complete-example" + NewLine;
Content += "spec: " + NewLine;
Content += " clusterServiceClassExternalName: " + AWSSvBSpec.Name + NewLine;
Content += " clusterServicePlanExternalName: custom" + NewLine;
Content += " parameters: " + NewLine;
Content += K8Params;
Content += "```" + CarriageRtn + NewLine;
WriteMarkDownToFile(Content);
}
static void WriteMarkDownToFile(string output)
{
path = path.Substring(0, path.LastIndexOf("\\"));
StreamWriter sw = new StreamWriter(path+@"\README.md");
sw.Write(output);
sw.Close();
Console.WriteLine(" ");
Console.WriteLine("============================================================================================");
Console.WriteLine("Generation of Readme.md completed, and located in the same directory as the template path.");
Console.WriteLine("Press a Key to Exit");
Console.ReadKey();
}
class AWSServiceBrokerSpecification
{
public string Name = "";
public string DisplayName = "";
public string LongDescription = "";
public string ImageUrl = "";
public string DocumentationUrl = "";
public string ProviderDisplayName = "Amazon Web Services";
public string Cost = "";
}
class Parameter
{
public string Name = "";
public string Description = "";
public string Type = "";
public string Default = "";
public JArray AllowedValues;
}
}
}