44creation, updates, deletion, and monitoring of containerized applications.
55"""
66
7+ import base64
8+ import os
79from dataclasses import dataclass , field
810from dataclasses_json import dataclass_json , Undefined # type: ignore
911from typing import List , Optional , Dict , Any
1820SERVERLESS_COMPUTE_RESOURCES_ENDPOINT = '/serverless-compute-resources'
1921CONTAINER_REGISTRY_CREDENTIALS_ENDPOINT = '/container-registry-credentials'
2022SECRETS_ENDPOINT = '/secrets'
23+ FILESET_SECRETS_ENDPOINT = '/file-secrets'
2124
2225
2326class EnvVarType (str , Enum ):
@@ -27,6 +30,13 @@ class EnvVarType(str, Enum):
2730 SECRET = "secret"
2831
2932
33+ class SecretType (str , Enum ):
34+ """Types of secrets that can be set in containers."""
35+
36+ GENERIC = "generic" # Regular secret, can be used in env vars
37+ FILESET = "file-secret" # A file secret that can be mounted into the container
38+
39+
3040class VolumeMountType (str , Enum ):
3141 """Types of volume mounts that can be configured for containers."""
3242
@@ -446,10 +456,12 @@ class Secret:
446456 Attributes:
447457 name: Name of the secret.
448458 created_at: Timestamp when the secret was created.
459+ secret_type: Type of the secret.
449460 """
450461
451462 name : str
452463 created_at : str
464+ secret_type : SecretType
453465
454466
455467@dataclass_json
@@ -909,6 +921,7 @@ def get_secrets(self) -> List[Secret]:
909921 List[Secret]: List of all secrets.
910922 """
911923 response = self .client .get (SECRETS_ENDPOINT )
924+ print (response .json ())
912925 return [Secret .from_dict (secret ) for secret in response .json ()]
913926
914927 def create_secret (self , name : str , value : str ) -> None :
@@ -956,3 +969,42 @@ def delete_registry_credentials(self, credentials_name: str) -> None:
956969 """
957970 self .client .delete (
958971 f"{ CONTAINER_REGISTRY_CREDENTIALS_ENDPOINT } /{ credentials_name } " )
972+
973+ def get_fileset_secrets (self ) -> List [Secret ]:
974+ """Retrieves all fileset secrets.
975+
976+ Returns:
977+ List of all fileset secrets.
978+ """
979+ response = self .client .get (FILESET_SECRETS_ENDPOINT )
980+ return [Secret .from_dict (secret ) for secret in response .json ()]
981+
982+ def delete_fileset_secret (self , secret_name : str ) -> None :
983+ """Deletes a fileset secret.
984+
985+ Args:
986+ secret_name: Name of the secret to delete.
987+ """
988+ self .client .delete (f"{ FILESET_SECRETS_ENDPOINT } /{ secret_name } " )
989+
990+ def create_fileset_secret_from_file_paths (self , secret_name : str , file_paths : List [str ]) -> None :
991+ """Creates a new fileset secret.
992+ A fileset secret is a secret that contains several files,
993+ and can be used to mount a directory with the files in a container.
994+
995+ Args:
996+ secret_name: Name of the secret.
997+ file_paths: List of file paths to include in the secret.
998+ """
999+ processed_files = []
1000+ for file_path in file_paths :
1001+ with open (file_path , "rb" ) as f :
1002+ base64_content = base64 .b64encode (f .read ()).decode ("utf-8" )
1003+ processed_files .append ({
1004+ "file_name" : os .path .basename (file_path ),
1005+ "base64_content" : base64_content
1006+ })
1007+ self .client .post (FILESET_SECRETS_ENDPOINT , {
1008+ "name" : secret_name ,
1009+ "files" : processed_files
1010+ })
0 commit comments