Skip to content

Commit

Permalink
The validate command no longer does head requests
Browse files Browse the repository at this point in the history
The validate command is used in a GHA and it is making too many head
requests. Thus we'll remote them from the validate command, followed by
adding them in another GHA that only does head requests if the URL of a
remote resource is changed.

Ticket: CFE-3904
Changelog: None
Signed-off-by: larsewi <[email protected]>
  • Loading branch information
larsewi committed Feb 4, 2022
1 parent d59ed18 commit 3a806a3
Showing 1 changed file with 1 addition and 38 deletions.
39 changes: 1 addition & 38 deletions cfbs/validate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import argparse
import json
import sys
import requests
import re

from cfbs.utils import is_a_commit_hash
Expand Down Expand Up @@ -54,13 +53,6 @@ def validate_repo(name, modules):
raise CFBSIndexException(name, "'repo' must be of type string")
if not modules[name]["repo"]:
raise CFBSIndexException(name, "'repo' must be non-empty")
response = requests.head(modules[name]["repo"])
if not response.ok:
raise CFBSIndexException(
name,
"HEAD request of repo responded with status code '%d'"
% response.status_code,
)

def validate_by(name, modules):
if not "by" in modules[name]:
Expand Down Expand Up @@ -126,38 +118,10 @@ def validate_steps(name, modules):
name, "'steps' must be a list of non-empty strings"
)

def validate_derived_url(name, modules):
url = modules[name]["repo"]
url += "/tree/" + modules[name]["commit"]
if "subdirectory" in modules[name]:
url += "/" + modules[name]["subdirectory"]
response = requests.head(url)
if not response.ok:
raise CFBSIndexException(
name,
"HEAD request of url '%s' responded with status code '%d'"
% (url, response.status_code),
)

def validate_url_field(name, modules, field):
url = modules[name].get(field)
if not url:
return

if not url.startswith("https://"):
if url and not url.startswith("https://"):
raise CFBSIndexException(name, "'%s' must be an HTTPS URL" % field)
try:
response = requests.head(url)
except requests.RequestException as e:
raise CFBSIndexException(
name, "HEAD request of %s url '%s' failed: %s" % (field, url, e)
) from e
if not response.ok:
raise CFBSIndexException(
name,
"HEAD request of %s url '%s' responded with status code '%d'"
% (field, url, response.status_code),
)

# Make sure index has a collection named modules
if not "index" in index:
Expand All @@ -180,7 +144,6 @@ def validate_url_field(name, modules, field):
if "subdirectory" in modules[name]: # optional attribute
validate_subdirectory(name, modules)
validate_steps(name, modules)
validate_derived_url(name, modules)
validate_url_field(name, modules, "website")
validate_url_field(name, modules, "documentation")

Expand Down

0 comments on commit 3a806a3

Please sign in to comment.