Skip to content

Commit

Permalink
api. Validate OS in Subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidePrincipi committed Jan 23, 2024
1 parent 457d729 commit 462c077
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ def fetch_subscription_info_nscom(rdb, attributes):
}
return info

def _exit_validation_error(field, value, error, exit_code=2):
agent.set_status('validation-failed')
json.dump([{
'field': field,
'parameter': field,
'value': value,
'error': error
}],
fp=sys.stdout)
sys.exit(exit_code)

try:
os_release = agent.read_envfile("/etc/os-release")
if os_release["ID"] != '"rocky"' or \
os_release["PLATFORM_ID"] != '"platform:el9"':
raise Exception("Invalid OS")
except Exception as ex:
json.dump({"subscription": None, "error": "os_not_supported"}, fp=sys.stdout)
sys.exit(0)

rdb = agent.redis_connect(privileged=True)
hsubscription = rdb.hgetall("cluster/subscription") or {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,19 @@
"title": "get-subscription",
"description": "Get support subscription attributes",
"$id": "http://schema.nethserver.org/cluster/get-subscription.json",
"examples": []
}
"examples": [],
"type": [
"object"
],
"required": [
"subscription"
],
"properties": {
"subscription": {
"type": [
"object",
"null"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ else:
if rdb.exists("cluster/subscription"):
_exit_validation_error("", "", "system_already_subscribed")

try:
os_release = agent.read_envfile("/etc/os-release")
if os_release["ID"] != '"rocky"' or \
os_release["PLATFORM_ID"] != '"platform:el9"':
raise Exception("Invalid OS")
except Exception as ex:
print(agent.SD_WARNING, ex, file=sys.stderr)
_exit_validation_error("", "", "os_not_supported")

prev_exceptions = []
for subscribe_function in [subscribe_nsent, subscribe_nscom]:
try:
Expand Down

0 comments on commit 462c077

Please sign in to comment.