Skip to content
This repository was archived by the owner on Mar 24, 2023. It is now read-only.

Commit 1a5c303

Browse files
authored
Merge pull request #1065 from laverya/improve-ShipCustomerRelease-template-func
remove unneeded fields from ShipCustomerRelease template func
2 parents 484e744 + 9b16a9f commit 1a5c303

File tree

2 files changed

+186
-5
lines changed

2 files changed

+186
-5
lines changed

pkg/templates/installation_context.go

+27-5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@ func (ctx *InstallationContext) entitlementValue(name string) string {
3535
}
3636

3737
func (ctx *InstallationContext) shipCustomerRelease() string {
38+
restrictedMeta := ctx.Meta
39+
restrictedMeta.ConfigSpec = ""
40+
restrictedMeta.CollectSpec = ""
41+
restrictedMeta.AnalyzeSpec = ""
42+
restrictedMeta.GithubContents = nil
43+
restrictedMeta.Images = nil
44+
45+
data, err := util.MarshalIndent(2, restrictedMeta)
46+
if err != nil {
47+
level.Error(ctx.Logger).Log("msg", "unable to marshal release meta", "err", err)
48+
return ""
49+
}
50+
return string(data)
51+
}
52+
53+
func (ctx *InstallationContext) shipCustomerReleaseFull() string {
3854
data, err := util.MarshalIndent(2, ctx.Meta)
3955
if err != nil {
4056
level.Error(ctx.Logger).Log("msg", "unable to marshal release meta", "err", err)
@@ -43,6 +59,10 @@ func (ctx *InstallationContext) shipCustomerRelease() string {
4359
return string(data)
4460
}
4561

62+
func (ctx *InstallationContext) configSpec() string {
63+
return ctx.Meta.ConfigSpec
64+
}
65+
4666
func (ctx *InstallationContext) collectSpec() string {
4767
return ctx.Meta.CollectSpec
4868
}
@@ -53,11 +73,13 @@ func (ctx *InstallationContext) analyzeSpec() string {
5373

5474
func (ctx *InstallationContext) FuncMap() template.FuncMap {
5575
return template.FuncMap{
56-
"ShipCustomerRelease": ctx.shipCustomerRelease,
57-
"EntitlementValue": ctx.entitlementValue,
58-
"LicenseFieldValue": ctx.entitlementValue,
59-
"CollectSpec": ctx.collectSpec,
60-
"AnalyzeSpec": ctx.analyzeSpec,
76+
"ShipCustomerRelease": ctx.shipCustomerRelease,
77+
"ShipCustomerReleaseFull": ctx.shipCustomerReleaseFull,
78+
"EntitlementValue": ctx.entitlementValue,
79+
"LicenseFieldValue": ctx.entitlementValue,
80+
"ConfigSpec": ctx.configSpec,
81+
"CollectSpec": ctx.collectSpec,
82+
"AnalyzeSpec": ctx.analyzeSpec,
6183
"Installation": func(name string) string {
6284
switch name {
6385
case "state_file_path":

pkg/templates/installation_context_test.go

+159
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,165 @@ func testCases() []TestInstallation {
217217
v1:
218218
- {}`,
219219
},
220+
{
221+
Name: "ship customer release",
222+
Meta: api.ReleaseMetadata{
223+
AnalyzeSpec: `this is not an analyze spec`,
224+
ConfigSpec: ``,
225+
CollectSpec: ``,
226+
GithubContents: []api.GithubContent{{
227+
Repo: "abc",
228+
Path: "xyz",
229+
Ref: "test",
230+
Files: []api.GithubFile{{
231+
Name: "abc",
232+
Path: "xyz",
233+
Sha: "123",
234+
Size: 456,
235+
Data: "789",
236+
}},
237+
}},
238+
Images: []api.Image{{
239+
URL: "abc",
240+
Source: "xyz",
241+
AppSlug: "123",
242+
ImageKey: "456",
243+
}},
244+
LicenseID: "myLicenseID",
245+
},
246+
Tpl: `{{repl ShipCustomerRelease }}`,
247+
Expected: `releaseId: ""
248+
sequence: 0
249+
customerId: ""
250+
installation: ""
251+
channelId: ""
252+
appSlug: ""
253+
licenseId: myLicenseID
254+
channelName: ""
255+
channelIcon: ""
256+
semver: ""
257+
releaseNotes: ""
258+
created: ""
259+
installed: ""
260+
registrySecret: ""
261+
images: []
262+
githubContents: []
263+
shipAppMetadata:
264+
description: ""
265+
version: ""
266+
icon: ""
267+
name: ""
268+
readme: ""
269+
url: ""
270+
contentSHA: ""
271+
releaseNotes: ""
272+
entitlements:
273+
meta:
274+
lastupdated: 0001-01-01T00:00:00Z
275+
customerid: ""
276+
serialized: ""
277+
signature: ""
278+
values: []
279+
utilizations: []
280+
entitlementSpec: ""
281+
configSpec: ""
282+
collectSpec: ""
283+
analyzeSpec: ""
284+
type: ""
285+
license:
286+
id: ""
287+
assignee: ""
288+
createdAt: 0001-01-01T00:00:00Z
289+
expiresAt: 0001-01-01T00:00:00Z
290+
type: ""
291+
`,
292+
},
293+
{
294+
Name: "ship customer release full",
295+
Meta: api.ReleaseMetadata{
296+
AnalyzeSpec: `this is not an analyze spec`,
297+
ConfigSpec: `this is not a config spec`,
298+
CollectSpec: `this is not a collect spec`,
299+
GithubContents: []api.GithubContent{{
300+
Repo: "abc",
301+
Path: "xyz",
302+
Ref: "test",
303+
Files: []api.GithubFile{{
304+
Name: "abc",
305+
Path: "xyz",
306+
Sha: "123",
307+
Size: 456,
308+
Data: "789",
309+
}},
310+
}},
311+
Images: []api.Image{{
312+
URL: "abc",
313+
Source: "xyz",
314+
AppSlug: "123",
315+
ImageKey: "456",
316+
}},
317+
LicenseID: "myLicenseID",
318+
},
319+
Tpl: `{{repl ShipCustomerReleaseFull }}`,
320+
Expected: `releaseId: ""
321+
sequence: 0
322+
customerId: ""
323+
installation: ""
324+
channelId: ""
325+
appSlug: ""
326+
licenseId: myLicenseID
327+
channelName: ""
328+
channelIcon: ""
329+
semver: ""
330+
releaseNotes: ""
331+
created: ""
332+
installed: ""
333+
registrySecret: ""
334+
images:
335+
- url: abc
336+
source: xyz
337+
appSlug: "123"
338+
imageKey: "456"
339+
githubContents:
340+
- repo: abc
341+
path: xyz
342+
ref: test
343+
files:
344+
- name: abc
345+
path: xyz
346+
sha: "123"
347+
size: 456
348+
data: "789"
349+
shipAppMetadata:
350+
description: ""
351+
version: ""
352+
icon: ""
353+
name: ""
354+
readme: ""
355+
url: ""
356+
contentSHA: ""
357+
releaseNotes: ""
358+
entitlements:
359+
meta:
360+
lastupdated: 0001-01-01T00:00:00Z
361+
customerid: ""
362+
serialized: ""
363+
signature: ""
364+
values: []
365+
utilizations: []
366+
entitlementSpec: ""
367+
configSpec: this is not a config spec
368+
collectSpec: this is not a collect spec
369+
analyzeSpec: this is not an analyze spec
370+
type: ""
371+
license:
372+
id: ""
373+
assignee: ""
374+
createdAt: 0001-01-01T00:00:00Z
375+
expiresAt: 0001-01-01T00:00:00Z
376+
type: ""
377+
`,
378+
},
220379
}
221380
return tests
222381
}

0 commit comments

Comments
 (0)