8000 Merge pull request #45375 from dipesh-rawat/migrate-getJSON · kubernetes/website@1372d79 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1372d79

Browse files
authored
Merge pull request #45375 from dipesh-rawat/migrate-getJSON
Replace 'getJSON' with 'transform.Unmarshal' for remote data retrieval
2 parents 7fd03bd + 9e1c3c8 commit 1372d79

File tree

4 files changed

+108
-8
lines changed

4 files changed

+108
-8
lines changed

layouts/_default/cve-feed.json

+20-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,20 @@
1-
{{ getJSON .Site.Params.cveFeedBucket | jsonify }}
1+
{{- $url := .Site.Params.cveFeedBucket -}}
2+
{{- with resources.GetRemote $url -}}
3+
{{- if .Err -}}
4+
{{- $message := printf "Failed to retrieve CVE data: %s" .Err -}}
5+
{{- if eq hugo.Environment "production" -}}
6+
{{- errorf $message -}}
7+
{{- else -}}
8+
{{- warnf $message -}}
9+
{{- end -}}
10+
{{- else -}}
11+
{{- .Content | transform.Unmarshal | jsonify -}}
12+
{{- end -}}
13+
{{- else -}}
14+
{{- $message := printf "Unable to fetch CVE data from the specified URL: %q" $url -}}
15+
{{- if eq hugo.Environment "production" -}}
16+
{{- errorf $message -}}
17+
{{- else -}}
18+
{{- warnf $message -}}
19+
{{- end -}}
20+
{{- end -}}

layouts/_default/cve-feed.rss.xml

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
{{ $feed := getJSON .Site.Params.cveFeedBucket -}}
1+
{{- $url := .Site.Params.cveFeedBucket -}}
2+
{{- $feed := "" -}}
3+
4+
{{- with resources.GetRemote $url -}}
5+
{{- if .Err -}}
6+
{{- $message := printf "Failed to retrieve CVE data: %s" .Err -}}
7+
{{- if eq hugo.Environment "production" -}}
8+
{{- errorf $message -}}
9+
{{- else -}}
10+
{{- warnf $message -}}
11+
{{- end -}}
12+
{{- else -}}
13+
{{- $feed = .Content | transform.Unmarshal -}}
14+
{{- end -}}
15+
{{- else -}}
16+
{{- $message := printf "Unable to fetch CVE data from the specified URL: %q" $url -}}
17+
{{- if eq hugo.Environment "production" -}}
18+
{{- errorf $message -}}
19+
{{- else -}}
20+
{{- warnf $message -}}
21+
{{- end -}}
22+
{{- end -}}
223
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
324
<channel>
425
<title>{{ $feed.title }}</title>
@@ -7,7 +28,10 @@
728
<generator>Hugo -- gohugo.io</generator>
829
<language>en-US</language>
930
<copyright>{{ .Site.Params.Copyright_k8s }}</copyright>
31+
<!-- Render last build date only if CVE feed is available, accommodating for offline builds. -->
32+
{{- if ne $feed nil -}}
1033
<lastBuildDate>{{ time.Format "Mon, 02 Jan 2006 15:04:05 -0700" $feed._kubernetes_io.updated_at | safeHTML }}</lastBuildDate>
34+
{{- end -}}
1135
{{ with .OutputFormats.Get "RSS" -}}
1236
{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }}
1337
{{ end -}}

layouts/shortcodes/cve-feed.html

+37-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
1-
{{ $feed := getJSON .Site.Params.cveFeedBucket }}
2-
{{ if ne $feed.version "https://jsonfeed.org/version/1.1" }}
3-
{{ warnf "CVE feed shortcode. KEP-3203: CVE feed does not comply with JSON feed v1.1." }}
4-
{{ end }}
1+
{{- $url := .Site.Params.cveFeedBucket }}
2+
{{- $feed := "" -}}
3+
<!-- Try to fetch remote resource from the specified URL -->
4+
{{- with resources.GetRemote $url -}}
5+
{{- if .Err -}}
6+
<!-- Error message if retrieval fails -->
7+
{{- $message := printf "Failed to retrieve CVE data: %s" .Err -}}
8+
{{- if eq hugo.Environment "production" -}}
9+
{{- errorf $message -}}
10+
{{- else -}}
11+
{{- warnf $message -}}
12+
{{- end -}}
13+
{{- else -}}
14+
<!-- Process the content if retrieval is successful -->
15+
{{- $feed = .Content | transform.Unmarshal -}}
16+
{{- if ne $feed.version "https://jsonfeed.org/version/1.1" -}}
17+
{{- $warningMessage := "CVE feed shortcode. KEP-3203: CVE feed does not comply with JSON feed v1.1." -}}
18+
{{- if eq hugo.Environment "production" -}}
19+
{{- errorf $warningMessage -}}
20+
{{- else -}}
21+
{{- warnf $warningMessage -}}
22+
{{- end -}}
23+
{{- end -}}
24+
{{- end -}}
25+
{{- else -}}
26+
<!-- Error message if unable to fetch the remote resource -->
27+
{{- $message := printf "Unable to fetch CVE data from the specified URL: %q" $url -}}
28+
{{- if eq hugo.Environment "production" -}}
29+
{{- errorf $message -}}
30+
{{- else -}}
31+
{{- warnf $message -}}
32+
{{- end -}}
33+
{{- end -}}
34+
35+
<!-- Render table only if CVE feed is available, accommodating for offline builds. -->
36+
{{ if ne $feed nil }}
537
<table class="security-cves">
638
<caption style="caption-side: top;">{{ T "cve_table" }} {{ printf (T "cve_table_date_format_string") ($feed._kubernetes_io.updated_at | time.Format (T "cve_table_date_format")) }}</caption>
739
<thead>
@@ -21,3 +53,4 @@
2153
{{ end }}
2254
</tbody>
2355
</table>
56+
{{- end -}}

layouts/shortcodes/release-binaries.html

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
<!-- Fetch release_binaries.json from kubernetes-sigs/downloadkubernetes to render in table -->
2-
{{ $response := getJSON "https://raw.githubusercontent.com/kubernetes-sigs/downloadkubernetes/master/dist/release_binaries.json" }}
2+
{{- $url := "https://raw.githubusercontent.com/kubernetes-sigs/downloadkubernetes/master/dist/release_binaries.json" }}
3+
{{- $response := "" }}
34

5+
{{- with resources.GetRemote $url -}}
6+
{{- if .Err -}}
7+
{{- $message := printf "Failed to retrieve release binaries data: %s" .Err -}}
8+
{{- if eq hugo.Environment "production" -}}
9+
{{- errorf $message -}}
10+
{{- else -}}
11+
{{- warnf $message -}}
12+
{{- end -}}
13+
{{- else -}}
14+
{{- $response = .Content | transform.Unmarshal }}
15+
{{- end -}}
16+
{{- else -}}
17+
{{ $message := printf "Unable to fetch release binaries data from the specified URL: %q" $url -}}
18+
{{- if eq hugo.Environment "production" -}}
19+
{{- errorf $message -}}
20+
{{- else -}}
21+
{{- warnf $message -}}
22+
{{- end -}}
23+
{{- end -}}
24+
25+
<!-- Continue processing only if release binaries JSON is available, accommodating for offline builds. -->
26+
{{ if ne $response nil }}
427
{{ $currentVersion := site.Params.version }}
528

629
{{ $Binaries := slice }}
@@ -127,4 +150,5 @@
127150
</tbody>
128151
</table>
129152
</div>
130-
</div>
153+
</div>
154+
{{- end -}}

0 commit comments

Comments
 (0)
0