Merge pull request #45375 from dipesh-rawat/migrate-getJSON
Replace 'getJSON' with 'transform.Unmarshal' for remote data retrieval
This commit is contained in:
		
						commit
						1372d79bb9
					
				|  | @ -1 +1,20 @@ | |||
| {{ getJSON .Site.Params.cveFeedBucket | jsonify }} | ||||
| {{- $url := .Site.Params.cveFeedBucket -}} | ||||
| {{- with resources.GetRemote $url -}} | ||||
|   {{- if .Err -}} | ||||
|     {{- $message := printf "Failed to retrieve CVE data: %s" .Err -}} | ||||
|     {{- if eq hugo.Environment "production" -}} | ||||
|       {{- errorf $message -}} | ||||
|     {{- else -}} | ||||
|       {{- warnf $message -}} | ||||
|     {{- end -}} | ||||
|   {{- else -}} | ||||
|     {{- .Content | transform.Unmarshal | jsonify -}} | ||||
|   {{- end -}} | ||||
| {{- else -}} | ||||
|   {{- $message := printf "Unable to fetch CVE data from the specified URL: %q" $url -}} | ||||
|   {{- if eq hugo.Environment "production" -}} | ||||
|     {{- errorf $message -}} | ||||
|   {{- else -}} | ||||
|     {{- warnf $message -}} | ||||
|   {{- end -}} | ||||
| {{- end -}} | ||||
|  | @ -1,4 +1,25 @@ | |||
| {{ $feed := getJSON .Site.Params.cveFeedBucket -}} | ||||
| {{- $url := .Site.Params.cveFeedBucket -}} | ||||
| {{- $feed := "" -}} | ||||
| 
 | ||||
| {{- with resources.GetRemote $url -}} | ||||
|   {{- if .Err -}} | ||||
|     {{- $message := printf "Failed to retrieve CVE data: %s" .Err -}} | ||||
|     {{- if eq hugo.Environment "production" -}} | ||||
|       {{- errorf $message -}} | ||||
|     {{- else -}} | ||||
|       {{- warnf $message -}} | ||||
|     {{- end -}} | ||||
|   {{- else -}} | ||||
|     {{- $feed = .Content | transform.Unmarshal -}} | ||||
|   {{- end -}} | ||||
| {{- else -}} | ||||
|   {{- $message := printf "Unable to fetch CVE data from the specified URL: %q" $url -}} | ||||
|   {{- if eq hugo.Environment "production" -}} | ||||
|     {{- errorf $message -}} | ||||
|   {{- else -}} | ||||
|     {{- warnf $message -}} | ||||
|   {{- end -}} | ||||
| {{- end -}} | ||||
| <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> | ||||
|   <channel> | ||||
|     <title>{{ $feed.title }}</title> | ||||
|  | @ -7,7 +28,10 @@ | |||
|     <generator>Hugo -- gohugo.io</generator> | ||||
|     <language>en-US</language> | ||||
| 	<copyright>{{ .Site.Params.Copyright_k8s }}</copyright> | ||||
|     <!-- Render last build date only if CVE feed is available, accommodating for offline builds. --> | ||||
|     {{- if ne $feed nil -}} | ||||
|     <lastBuildDate>{{ time.Format "Mon, 02 Jan 2006 15:04:05 -0700" $feed._kubernetes_io.updated_at | safeHTML }}</lastBuildDate> | ||||
|     {{- end -}} | ||||
|     {{ with .OutputFormats.Get "RSS" -}} | ||||
| 	{{ printf "<atom:link href=%q rel=\"self\" type=%q />" .Permalink .MediaType | safeHTML }} | ||||
|     {{ end -}} | ||||
|  |  | |||
|  | @ -1,7 +1,39 @@ | |||
| {{ $feed := getJSON .Site.Params.cveFeedBucket }} | ||||
| {{ if ne $feed.version "https://jsonfeed.org/version/1.1" }} | ||||
|   {{ warnf "CVE feed shortcode. KEP-3203: CVE feed does not comply with JSON feed v1.1." }} | ||||
| {{ end }} | ||||
| {{- $url := .Site.Params.cveFeedBucket }} | ||||
| {{- $feed := "" -}} | ||||
| <!-- Try to fetch remote resource from the specified URL --> | ||||
| {{- with resources.GetRemote $url -}} | ||||
|   {{- if .Err -}} | ||||
|     <!-- Error message if retrieval fails --> | ||||
|     {{- $message := printf "Failed to retrieve CVE data: %s" .Err -}} | ||||
|     {{- if eq hugo.Environment "production" -}} | ||||
|       {{- errorf $message -}} | ||||
|     {{- else -}} | ||||
|       {{- warnf $message -}} | ||||
|     {{- end -}} | ||||
|   {{- else -}} | ||||
|     <!-- Process the content if retrieval is successful --> | ||||
|     {{- $feed = .Content | transform.Unmarshal -}} | ||||
|     {{- if ne $feed.version "https://jsonfeed.org/version/1.1" -}} | ||||
|       {{- $warningMessage := "CVE feed shortcode. KEP-3203: CVE feed does not comply with JSON feed v1.1." -}} | ||||
|       {{- if eq hugo.Environment "production" -}} | ||||
|         {{- errorf $warningMessage -}} | ||||
|       {{- else -}} | ||||
|         {{- warnf $warningMessage -}} | ||||
|       {{- end -}} | ||||
|     {{- end -}} | ||||
|   {{- end -}} | ||||
| {{- else -}} | ||||
|   <!-- Error message if unable to fetch the remote resource --> | ||||
|   {{- $message := printf "Unable to fetch CVE data from the specified URL: %q" $url -}} | ||||
|   {{- if eq hugo.Environment "production" -}} | ||||
|     {{- errorf $message -}} | ||||
|   {{- else -}} | ||||
|     {{- warnf $message -}} | ||||
|   {{- end -}} | ||||
| {{- end -}} | ||||
| 
 | ||||
| <!-- Render table only if CVE feed is available, accommodating for offline builds. --> | ||||
| {{ if ne $feed nil }} | ||||
| <table class="security-cves"> | ||||
|   <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> | ||||
|   <thead> | ||||
|  | @ -21,3 +53,4 @@ | |||
|   {{ end }} | ||||
|   </tbody> | ||||
| </table> | ||||
| {{- end -}} | ||||
|  |  | |||
|  | @ -1,6 +1,29 @@ | |||
| <!-- Fetch release_binaries.json from kubernetes-sigs/downloadkubernetes to render in table --> | ||||
| {{ $response := getJSON "https://raw.githubusercontent.com/kubernetes-sigs/downloadkubernetes/master/dist/release_binaries.json" }} | ||||
| {{- $url := "https://raw.githubusercontent.com/kubernetes-sigs/downloadkubernetes/master/dist/release_binaries.json" }} | ||||
| {{- $response := "" }} | ||||
| 
 | ||||
| {{- with resources.GetRemote $url -}} | ||||
|   {{- if .Err -}} | ||||
|     {{- $message := printf "Failed to retrieve release binaries data: %s" .Err -}} | ||||
|     {{- if eq hugo.Environment "production" -}} | ||||
|       {{- errorf $message -}} | ||||
|     {{- else -}} | ||||
|       {{- warnf $message -}} | ||||
|     {{- end -}} | ||||
|   {{- else -}} | ||||
|     {{- $response = .Content | transform.Unmarshal }} | ||||
|   {{- end -}} | ||||
| {{- else -}} | ||||
|   {{ $message := printf "Unable to fetch release binaries data from the specified URL: %q" $url -}} | ||||
|   {{- if eq hugo.Environment "production" -}} | ||||
|     {{- errorf $message -}} | ||||
|   {{- else -}} | ||||
|     {{- warnf $message -}} | ||||
|   {{- end -}} | ||||
| {{- end -}} | ||||
| 
 | ||||
| <!-- Continue processing only if release binaries JSON is available, accommodating for offline builds. --> | ||||
| {{ if ne $response nil }} | ||||
| {{ $currentVersion := site.Params.version }} | ||||
| 
 | ||||
| {{ $Binaries := slice }} | ||||
|  | @ -127,4 +150,5 @@ | |||
|             </tbody> | ||||
|         </table> | ||||
|     </div> | ||||
| </div> | ||||
| </div> | ||||
| {{- end -}} | ||||
		Loading…
	
		Reference in New Issue