Skip to content

Commit

Permalink
Add runtime name validation (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaruni96 authored Nov 17, 2024
1 parent a031fb0 commit 9090a7b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project tries to adhere to [Semantic Versioning](https://semver.org/spe
### Added
- Include sysfs in the runtime as read-only
- Add option to upload runtime for publishing
- Add runtime name validation for commiting and uploading runtimes

### Changed
- Improved logic for uninstall
Expand Down
30 changes: 30 additions & 0 deletions src/maps
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,31 @@ def uninstall_runtime(repo, args):
sys.exit()


def validate_runtime_name(runtime_id: str):
"""
Function to validate that a given runtime ID conforms to naming rules
"""
if VERBOSE:
print("Validating runtime name...")
# name must be split into name/platform/version
# so, slash split string must have length 3
assert len(runtime_id.split('/')) == 3, "Must have 3 parts in runtime identifier"
if VERBOSE:
print("Name has 3 parts separated with '/'!")

# first part must be in rDNS. For now, it means that dot split string must have length
# greater than or equal to 3. most commonly, it will be 3
assert len(runtime_id.split('/')[0].split('.')) >= 3, "First part must be in reverse DNS format"
if VERBOSE:
print("First part is in rDNS!")

# validate platform. for now, only x86_64 is supported
assert runtime_id.split('/')[1] == 'x86_64'
if VERBOSE:
print(f"Platform is '{runtime_id.split('/')[1]}'!")
print("Name validated!")


# Update
def mode_update(repo, args, remote="Official"):
"""Function to update a runtime identifier to its recent version (if any)"""
Expand Down Expand Up @@ -585,6 +610,8 @@ def mode_package(repo, args):
signal.signal(signal.SIGINT, OG_SIGINT_HANLDER)
if args.COMMIT is not False:
# we are given TREE and BRANCH. All we have to do is commit TREE to BRANCH
# first validate that BRANCH follows a naming scheme we like
validate_runtime_name(args.COMMIT[1])
with concurrent.futures.ThreadPoolExecutor() as executor:
future = executor.submit(commit, [repo, args.COMMIT[0], args.COMMIT[1]])
print(f"Committing {args.COMMIT[0]} as {args.COMMIT[1]}. Please wait...")
Expand Down Expand Up @@ -798,6 +825,9 @@ def upload(repo, runtime):
"""
if AUTH is None:
raise AssertionError("MTDAUTH not set! Cannot upload without authentication!")
# just to be sure
# second name validation right before upload
validate_runtime_name(runtime)
runtimes = list(repo.list_refs()[1].keys())
if VERBOSE:
print("Available local runtimes are:")
Expand Down

0 comments on commit 9090a7b

Please sign in to comment.