~arsen/vengor

ab1ae7b275ab492d4806de88cfbf67e7b97c1ade — Arsen Arsenović 6 months ago 2f603ae master
vengor: extract common ensure_goproxy code
3 files changed, 15 insertions(+), 5 deletions(-)

M vengor/__init__.py
M vengor/tasks.py
M vengor/utils.py
M vengor/__init__.py => vengor/__init__.py +1 -4
@@ 40,10 40,7 @@ structlog.configure(

app = Flask(__name__)
logger = structlog.wrap_logger(app.logger)
proxy = os.getenv("GOPROXY", "proxy.golang.org")
if not proxy.startswith("https://"):
    proxy = f"https://{proxy}"
os.environ["GOPROXY"] = proxy
proxy = utils.ensure_goproxy()

if sys.version_info.major != 3 or sys.version_info.minor < 7:
    raise RuntimeError(

M vengor/tasks.py => vengor/tasks.py +1 -1
@@ 49,7 49,7 @@ if os.getenv("VENGOR_DEBUG", ""):
logger = structlog.wrap_logger(logger)


os.environ["GOPROXY"] = proxy = "https://" + os.getenv("GOPROXY", "proxy.golang.org")
proxy = utils.ensure_goproxy()
cachedir = os.getenv("VENGOR_DATASTORE", "cache")



M vengor/utils.py => vengor/utils.py +13 -0
@@ 51,3 51,16 @@ def atomic_write(directory, file, mode, *, wrapper=lambda x: x, nojoin=False):
            os.unlink(t.name)
        except FileNotFoundError:
            pass


def ensure_goproxy() -> str:
    """
    Ensures $GOPROXY is set and starts with https://

    Returns the new proxy value
    """
    proxy = os.getenv("GOPROXY", "proxy.golang.org")
    if not proxy.startswith("https://"):
        proxy = f"https://{proxy}"
    os.environ["GOPROXY"] = proxy
    return proxy