Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature-138: Construct HashStore Config Yaml with Library #144

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 75 additions & 1 deletion src/hashstore/filehashstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def _write_properties(self, properties: Dict[str, Union[str, int]]) -> None:
return

@staticmethod
def _build_hashstore_yaml_string(
def _build_hashstore_yaml_string_old(
store_depth: int,
store_width: int,
store_algorithm: str,
Expand Down Expand Up @@ -341,6 +341,80 @@ def _build_hashstore_yaml_string(
"""
return hashstore_configuration_yaml

@staticmethod
def _build_hashstore_yaml_string(
store_depth: int,
store_width: int,
store_algorithm: str,
store_metadata_namespace: str,
) -> str:
"""Build a YAML string representing the configuration for a HashStore.

:param int store_depth: Depth when sharding an object's hex digest.
:param int store_width: Width of directories when sharding an object's hex digest.
:param str store_algorithm: Hash algorithm used for calculating the object's hex digest.
:param str store_metadata_namespace: Namespace for the HashStore's system metadata.

:return: A YAML string representing the configuration for a HashStore.
"""
hashstore_configuration = {
"store_depth": store_depth,
"store_width": store_width,
"store_metadata_namespace": store_metadata_namespace,
"store_algorithm": store_algorithm,
"store_default_algo_list": [
"MD5",
"SHA-1",
"SHA-256",
"SHA-384",
"SHA-512",
],
}

# The tabbing here is intentional otherwise the created .yaml will have extra tabs
hashstore_configuration_comments = f"""
# Default configuration variables for HashStore

############### HashStore Config Notes ###############
############### Directory Structure ###############
# store_depth
# - Desired amount of directories when sharding an object to form the permanent address
# - **WARNING**: DO NOT CHANGE UNLESS SETTING UP NEW HASHSTORE
#
# store_width
# - Width of directories created when sharding an object to form the permanent address
# - **WARNING**: DO NOT CHANGE UNLESS SETTING UP NEW HASHSTORE
#
# Example:
# Below, objects are shown listed in directories that are 3 levels deep (DIR_DEPTH=3),
# with each directory consisting of 2 characters (DIR_WIDTH=2).
# /var/filehashstore/objects
# ├── 7f
# │ └── 5c
# │ └── c1
# │ └── 8f0b04e812a3b4c8f686ce34e6fec558804bf61e54b176742a7f6368d6

############### Format of the Metadata ###############
# store_metadata_namespace
# - The default metadata format (ex. system metadata)

############### Hash Algorithms ###############
# store_algorithm
# - Hash algorithm to use when calculating object's hex digest for the permanent address
#
# store_default_algo_list
# - Algorithm values supported by python hashlib 3.9.0+ for File Hash Store (FHS)
# - The default algorithm list includes the hash algorithms calculated when storing an
# - object to disk and returned to the caller after successful storage.

"""

hashstore_yaml_with_comments = hashstore_configuration_comments + yaml.dump(
hashstore_configuration, sort_keys=False
)

return hashstore_yaml_with_comments

def _verify_hashstore_properties(
self, properties: Dict[str, Union[str, int]], prop_store_path: str
) -> None:
Expand Down
Loading