Skip to content

Commit a7f05fd

Browse files
Demo: update demo item generation
1 parent cdb4828 commit a7f05fd

File tree

4 files changed

+209
-32
lines changed

4 files changed

+209
-32
lines changed

src/Certify.Core/Management/CertifyManager/CertifyManager.Maintenance.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ private async Task UpgradeSettings()
8888
await UpdateHubManagedInstance(hubInstance.Id, hubInstance);
8989
}
9090
}
91+
92+
if (Environment.GetEnvironmentVariable("CERTIFY_GENERATE_DEMO_ITEMS") == "true")
93+
{
94+
var maxItems = Environment.GetEnvironmentVariable("CERTIFY_GENERATE_DEMO_ITEMS_MAX") ?? "500";
95+
await GenerateDemoItems(int.Parse(maxItems));
96+
}
9197
}
9298

9399
/// <summary>

src/Certify.Core/Management/CertifyManager/CertifyManager.ManagementHub.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -805,12 +805,17 @@ private void _managementServerClient_OnConnectionReconnecting()
805805
_serviceLog.Warning("Reconnecting to Management Hub.");
806806
}
807807

808-
private void GenerateDemoItems()
808+
private async Task GenerateDemoItems(int? numItems)
809809
{
810-
var items = DemoDataGenerator.GenerateDemoItems();
811-
foreach (var item in items)
810+
var currentItems = await GetManagedCertificateSummary(new ManagedCertificateFilter { });
811+
if (currentItems.Total == 0)
812812
{
813-
_ = UpdateManagedCertificate(item);
813+
var items = DemoDataGenerator.GenerateDemoItems(numItems ?? 100, numItems ?? 500);
814+
foreach (var item in items)
815+
{
816+
817+
_ = UpdateManagedCertificate(item);
818+
}
814819
}
815820
}
816821
}

src/Certify.Core/Management/CertifyManager/CertifyManager.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,6 @@ public async Task Init()
273273
await UpgradeSettings();
274274

275275
_serviceLog?.Information("Certify Manager Started");
276-
277-
#if DEBUG
278-
if (Environment.GetEnvironmentVariable("CERTIFY_GENERATE_DEMO_ITEMS") == "true")
279-
{
280-
GenerateDemoItems();
281-
}
282-
#endif
283276
}
284277

285278
/// <summary>

src/Certify.Shared/Utils/DemoDataGenerator.cs

Lines changed: 194 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ namespace Certify.Shared.Core.Utils
88
{
99
public class DemoDataGenerator
1010
{
11-
public static List<ManagedCertificate> GenerateDemoItems()
11+
public static List<ManagedCertificate> GenerateDemoItems(int min = 500, int max = 500)
1212
{
1313
var rnd = new Random();
1414

1515
var items = new List<ManagedCertificate>();
16-
var numItems = new Random().Next(10, 500);
16+
var numItems = rnd.Next(min, max);
1717
for (var i = 0; i < numItems; i++)
1818
{
1919

@@ -42,7 +42,7 @@ public static List<ManagedCertificate> GenerateDemoItems()
4242
if (demoState == 1)
4343
{
4444
// not yet requested
45-
item.Comments = "This is an example item note yet attempted.";
45+
item.Comments = "[DemoData-1]";
4646
}
4747
else if (demoState == 2)
4848
{
@@ -52,7 +52,7 @@ public static List<ManagedCertificate> GenerateDemoItems()
5252
item.DateLastRenewalAttempt = certStart;
5353
item.DateExpiry = certStart.AddDays(certLifetime);
5454
item.CertificateFriendlyName = $"{item.GetCertificateIdentifiers().First().Value} [CertifyDemo] - {item.DateStart} to {item.DateExpiry}";
55-
item.Comments = "This is an example item showing failure.";
55+
item.Comments = "[DemoData-2] This is an example item showing failure.";
5656
item.LastAttemptedCA = item.CertificateCurrentCA;
5757
item.LastRenewalStatus = RequestState.Error;
5858
item.RenewalFailureCount = new Random().Next(1, 3);
@@ -67,7 +67,7 @@ public static List<ManagedCertificate> GenerateDemoItems()
6767
item.DateLastRenewalAttempt = certStart;
6868
item.DateExpiry = certStart.AddDays(certLifetime);
6969
item.CertificateFriendlyName = $"{item.GetCertificateIdentifiers().First().Value} [CertifyDemo] - {item.DateStart} to {item.DateExpiry}";
70-
item.Comments = "This is an example item showing success";
70+
item.Comments = "[DemoData-3] This is an example item showing success";
7171
item.LastAttemptedCA = item.CertificateCurrentCA;
7272
item.LastRenewalStatus = RequestState.Success;
7373
}
@@ -88,31 +88,204 @@ public static string GenerateName(Random rnd)
8888
{
8989
// generate test item names using verb,animal
9090
var subjects = new string[] {
91-
"Lion",
92-
"Tiger",
93-
"Leopard",
94-
"Cheetah",
95-
"Elephant",
96-
"Giraffe",
97-
"Rhinoceros",
98-
"Gorilla"
99-
};
91+
"Lion",
92+
"Tiger",
93+
"Leopard",
94+
"Cheetah",
95+
"Elephant",
96+
"Giraffe",
97+
"Rhinoceros",
98+
"Gorilla",
99+
"Chimpanzee",
100+
"Quenda",
101+
"Koala",
102+
"Panda",
103+
"Kangaroo",
104+
"Wallaby",
105+
"Platypus",
106+
"Wombat",
107+
"Dingo",
108+
"Emu",
109+
"Cassowary",
110+
"Cockatoo",
111+
"Echidna",
112+
"TasmanianDevil",
113+
"Bilby",
114+
"Bandicoot",
115+
"Numbat",
116+
"SugarGlider",
117+
"Possum",
118+
"Lyrebird",
119+
"Brolga",
120+
"Magpie",
121+
"Kookaburra",
122+
"FrillNeckLizard",
123+
"Goanna",
124+
"ThornyDevil",
125+
"BlueTongueSkink",
126+
"SaltwaterCrocodile",
127+
"FreshwaterCrocodile",
128+
"Dugong",
129+
"SeaTurtle",
130+
"WhaleShark",
131+
"GreatWhiteShark",
132+
"HammerheadShark",
133+
"MantaRay",
134+
"Stingray",
135+
"Clownfish",
136+
"Seahorse",
137+
"Octopus",
138+
"Squid",
139+
"Jellyfish",
140+
"Starfish",
141+
"Coral",
142+
"Dolphin",
143+
"Orca",
144+
"HumpbackWhale",
145+
"BlueWhale",
146+
"Penguin",
147+
"Albatross",
148+
"Seal",
149+
"SeaLion",
150+
"Walrus",
151+
"PolarBear",
152+
"ArcticFox",
153+
"SnowLeopard",
154+
"Moose",
155+
"Caribou",
156+
"Bison",
157+
"Beaver",
158+
"Otter",
159+
"Lynx",
160+
"Bobcat",
161+
"Cougar",
162+
"Jaguar",
163+
"Ocelot",
164+
"Sloth",
165+
"Armadillo",
166+
"Anteater",
167+
"Capybara",
168+
"Tapir",
169+
"Peccary",
170+
"HowlerMonkey",
171+
"SpiderMonkey",
172+
"Tamarin",
173+
"Marmoset",
174+
"Macaw",
175+
"Toucan",
176+
"HarpyEagle",
177+
"Anaconda",
178+
"BoaConstrictor",
179+
"Caiman",
180+
"Piranha",
181+
"ElectricEel",
182+
"Axolotl",
183+
"Salamander",
184+
"Newt",
185+
"Frog",
186+
"Toad"
187+
};
188+
100189
var adjectives = new string[] {
101190
"active",
102191
"adaptable",
103192
"alert",
104-
"clever" ,
105-
"comfortable" ,
193+
"clever",
194+
"comfortable",
106195
"conscientious",
107196
"considerate",
108-
"courageous" ,
197+
"courageous",
109198
"decisive",
110-
"determined" ,
111-
"diligent" ,
199+
"determined",
200+
"diligent",
112201
"energetic",
113202
"entertaining",
114-
"enthusiastic" ,
115-
"fabulous"
203+
"enthusiastic",
204+
"fabulous",
205+
"friendly",
206+
"generous",
207+
"gentle",
208+
"graceful",
209+
"hardworking",
210+
"helpful",
211+
"honest",
212+
"imaginative",
213+
"independent",
214+
"intelligent",
215+
"kind",
216+
"lively",
217+
"loyal",
218+
"modest",
219+
"optimistic",
220+
"organized",
221+
"patient",
222+
"persistent",
223+
"polite",
224+
"practical",
225+
"punctual",
226+
"reliable",
227+
"resourceful",
228+
"respectful",
229+
"responsible",
230+
"sincere",
231+
"skillful",
232+
"sociable",
233+
"supportive",
234+
"thoughtful",
235+
"trustworthy",
236+
"understanding",
237+
"versatile",
238+
"vibrant",
239+
"witty",
240+
"zealous",
241+
"adventurous",
242+
"ambitious",
243+
"artistic",
244+
"athletic",
245+
"attentive",
246+
"bold",
247+
"brave",
248+
"calm",
249+
"charismatic",
250+
"cheerful",
251+
"compassionate",
252+
"confident",
253+
"creative",
254+
"curious",
255+
"dedicated",
256+
"dependable",
257+
"dynamic",
258+
"eager",
259+
"efficient",
260+
"empathetic",
261+
"enthusiastic",
262+
"flexible",
263+
"forgiving",
264+
"funny",
265+
"generous",
266+
"grateful",
267+
"humble",
268+
"inspiring",
269+
"inventive",
270+
"joyful",
271+
"motivated",
272+
"observant",
273+
"outgoing",
274+
"passionate",
275+
"perceptive",
276+
"playful",
277+
"proactive",
278+
"resilient",
279+
"selfless",
280+
"sensible",
281+
"spontaneous",
282+
"strategic",
283+
"tactful",
284+
"tenacious",
285+
"thoughtful",
286+
"tolerant",
287+
"visionary",
288+
"wise"
116289
};
117290

118291
return $"{adjectives[rnd.Next(0, adjectives.Length - 1)]}-{subjects[rnd.Next(0, subjects.Length - 1)]}".ToLower();

0 commit comments

Comments
 (0)