Skip to content

Commit

Permalink
WIP Load revised MBS configuration properties
Browse files Browse the repository at this point in the history
  • Loading branch information
mmathesius committed Apr 19, 2021
1 parent c99dc69 commit e8b023d
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 4 deletions.
86 changes: 84 additions & 2 deletions lib/distrobaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,82 @@ def load_config(crepo):
logger.error("Configuration error: %s.profile missing.", k)
return None
if "mbs" in cnf[k]:
n[k]["mbs"] = str(cnf[k]["mbs"])
# MBS properties are only relevant for the destination
if k == "destination":
if not isinstance(cnf[k]["mbs"], dict):
logger.error(
"Configuration error: %s.mbs must be a mapping.",
k,
)
return None
if "auth_method" not in cnf[k]["mbs"]:
logger.error(
"Configuration error: %s.mbs.%s is missing.",
k,
"auth_method",
)
return None
mbs_auth_method = str(cnf[k]["mbs"]["auth_method"])
mbs_required_configs = ["auth_method", "api_url"]
if mbs_auth_method == "oidc":
# Try to import this now so the user gets immediate
# feedback if it isn't installed
try:
import openidc_client # noqa: F401
except ImportError:
logger.exception(
"python-openidc-client needs to be "
"installed for %s.mbs.%s %s",
k,
"auth_method",
mbs_auth_method,
)
return None
mbs_required_configs += [
"oidc_id_provider",
"oidc_client_id",
"oidc_client_secret",
"oidc_scopes",
]
elif mbs_auth_method == "kerberos":
# Try to import this now so the user gets immediate
# feedback if it isn't installed
try:
import requests_kerberos # noqa: F401
except ImportError:
logger.exception(
"python-requests-kerberos needs to be "
"installed for %s.mbs.%s %s",
k,
"auth_method",
mbs_auth_method,
)
return None
else:
logger.error(
"Configuration error: %s.mbs.%s %s is unsupported.",
k,
"auth_method",
mbs_auth_method,
)
return None
n[k]["mbs"] = dict()
for r in mbs_required_configs:
if r not in cnf[k]["mbs"]:
logger.error(
"Configuration error: %s.mbs.%s is required when %s is %s.",
k,
r,
"auth_method",
mbs_auth_method,
)
return None
n[k]["mbs"][r] = cnf[k]["mbs"][r]
else:
logger.warning(
"Configuration warning: %s.mbs is extraneous, ignoring.",
k,
)
else:
logger.error("Configuration error: %s.mbs missing.", k)
return None
Expand All @@ -277,7 +352,7 @@ def load_config(crepo):
return None
if "build" in cnf:
n["build"] = dict()
for k in ("prefix", "target"):
for k in ("prefix", "target", "platform"):
if k in cnf["build"]:
n["build"][k] = str(cnf["build"][k])
else:
Expand All @@ -290,6 +365,13 @@ def load_config(crepo):
"Configuration warning: build.scratch not defined, assuming false."
)
n["build"]["scratch"] = False
if ":" not in n["build"]["platform"]:
logger.error(
"Configuration error: build.%s.%s must be in name:stream format.",
k,
"platform",
)
return None
else:
logger.error("Configuration error: build missing.")
return None
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ fedora_messaging>=2.0.2
gitpython>=3.1.9
gunicorn>=20.0.4
koji>=1.22.1
openidc_client
pygobject
pyyaml>=5.3.1
regex>=2020.10.11
requests_kerberos
rpkg>=1.61
rpm-py-installer>=1.0.0
14 changes: 12 additions & 2 deletions tests/data/config/distrobaker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,32 @@ configuration:
cgi: https://src.fedoraproject.org/repo/pkgs/upload.cgi
path: "%(name)s/%(filename)s/%(hashtype)s/%(hash)s/%(filename)s"
profile: koji
mbs: https://mbs.fedoraproject.org
mbs: https://this.needs.to.be.ignored
destination:
scm: ssh://pkgs.example.com/
cache:
url: http://pkgs.example.com/repo
cgi: http://pkgs.example.com/lookaside/upload.cgi
path: "%(name)s/%(filename)s/%(hashtype)s/%(hash)s/%(filename)s"
profile: brew
mbs: https://mbs.example.com
mbs:
api_url: https://mbs.example.com/module-build-service/1/
auth_method: oidc
oidc_id_provider: https://id.example.com/openidc/
oidc_client_id: mbs-authorizer
oidc_client_secret: notsecret
oidc_scopes:
- openid
- https://id.example.com/scope/groups
- https://mbs.example.com/oidc/submit-build
trigger:
rpms: rawhide
modules: rawhide-modular
build:
prefix: git://pkgs.example.com/
target: fluff-42.0.0-alpha-candidate
scratch: false
platform: platform:fl42
git:
author: DistroBaker
email: [email protected]
Expand Down
22 changes: 22 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,28 @@ def test_load_config(self):
# make sure what was loaded matches get_config()
self.assertEqual(cfg, distrobaker.get_config())

# verify MBS build platform
self.assertEqual(cfg["main"]["build"]["platform"], "platform:fl42")

# verify MBS desination configuration
self.assertEqual(
cfg["main"]["destination"]["mbs"],
{
"api_url": "https://mbs.example.com/module-build-service/1/",
"auth_method": "oidc",
"oidc_client_id": "mbs-authorizer",
"oidc_client_secret": "notsecret",
"oidc_id_provider": "https://id.example.com/openidc/",
"oidc_scopes": [
"openid",
"https://id.example.com/scope/groups",
"https://mbs.example.com/oidc/submit-build",
],
},
)
# verify MBS source configuration is not present
self.assertTrue("mbs" not in cfg["main"]["source"])

# verify modular RPM component defaults were loaded
self.assertEqual(
cfg["main"]["defaults"]["modules"]["rpms"],
Expand Down

0 comments on commit e8b023d

Please sign in to comment.