def _download_faas_supervisor_zip(self) -> None: supervisor_zip_url = GitHubUtils.get_source_code_url( GITHUB_USER, GITHUB_SUPERVISOR_PROJECT, self.supervisor_version) with open(self._supervisor_zip_path, "wb") as thezip: thezip.write(get_file(supervisor_zip_url))
def exists_release_in_repo(user: str, project: str, tag_name: str) -> bool: """Check if a tagged release exists in a repository.""" url = f'https://api.github.com/repos/{user}/{project}/releases/tags/{tag_name}' response = json.loads(request.get_file(url)) if 'message' in response and response['message'] == 'Not Found': return False return True
def download_supervisor_asset(cls, version: str, asset_name: str, supervisor_zip_path: str) -> str: """Downloads the FaaS Supervisor asset to the specified path.""" supervisor_zip_url = GitHubUtils.get_asset_url(cls._SUPERVISOR_GITHUB_USER, cls._SUPERVISOR_GITHUB_REPO, asset_name, version) with open(supervisor_zip_path, "wb") as thezip: thezip.write(request.get_file(supervisor_zip_url)) return supervisor_zip_path
def get_latest_release(user: str, project: str) -> str: """Get the tag of the latest release in a repository.""" url = f'https://api.github.com/repos/{user}/{project}/releases/latest' response = request.get_file(url) if response: response = json.loads(response) return response.get('tag_name', '') else: return None
def download_supervisor(cls, supervisor_version: str, path: str) -> str: """Downloads the FaaS Supervisor .zip package to the specified path.""" supervisor_zip_path = FileUtils.join_paths(path, 'faas-supervisor.zip') supervisor_zip_url = GitHubUtils.get_source_code_url( cls._SUPERVISOR_GITHUB_USER, cls._SUPERVISOR_GITHUB_REPO, supervisor_version) with open(supervisor_zip_path, "wb") as thezip: thezip.write(request.get_file(supervisor_zip_url)) return supervisor_zip_path
def _download_supervisor(supervisor_version: str, tmp_zip_path: str) -> str: supervisor_zip_url = GitHubUtils.get_source_code_url( GITHUB_USER, GITHUB_SUPERVISOR_PROJECT, supervisor_version) supervisor_zip = request.get_file(supervisor_zip_url) with zipfile.ZipFile(io.BytesIO(supervisor_zip)) as thezip: for file in thezip.namelist(): # Remove the parent folder path parent_folder, file_name = file.split("/", 1) if file_name.startswith("extra") or file_name.startswith( "faassupervisor"): thezip.extract(file, tmp_zip_path) return parent_folder
def get_source_code_url(user: str, project: str, tag_name: str='latest') -> str: """Get the source code's url from the specified github tagged project.""" source_url = "" repo_url = "" if tag_name == 'latest': repo_url = f'https://api.github.com/repos/{user}/{project}/releases/latest' else: if GitHubUtils.exists_release_in_repo(user, project, tag_name): repo_url = f'https://api.github.com/repos/{user}/{project}/releases/tags/{tag_name}' else: raise GitHubTagNotFoundError(tag=tag_name) if repo_url: response = json.loads(request.get_file(repo_url)) if isinstance(response, dict): source_url = response.get('zipball_url') return source_url
def get_asset_url(user: str, project: str, asset_name: str, tag_name: str='latest') -> Optional[str]: """Get the download asset url from the specified github tagged project.""" if tag_name == 'latest': url = f'https://api.github.com/repos/{user}/{project}/releases/latest' else: if GitHubUtils.exists_release_in_repo(user, project, tag_name): url = f'https://api.github.com/repos/{user}/{project}/releases/tags/{tag_name}' else: raise GitHubTagNotFoundError(tag=tag_name) response = json.loads(request.get_file(url)) if isinstance(response, dict) and 'assets' in response: for asset in response['assets']: if asset['name'] == asset_name: return asset['browser_download_url'] return None
def get_fdl_config(self, arn: str = None) -> Dict: function = arn if arn else self.function.get('name') function_info = self.client.get_function(function) # Get the FDL from the env variable fdl = function_info.get('Configuration', {}).get('Environment', {}).get('Variables', {}).get('FDL') if fdl: return yaml.safe_load(StrUtils.decode_base64(fdl)) # In the future this part can be removed if 'Location' in function_info.get('Code'): dep_pack_url = function_info.get('Code').get('Location') else: return {} dep_pack = get_file(dep_pack_url) # Extract function_config.yaml try: with ZipFile(io.BytesIO(dep_pack)) as thezip: with thezip.open('function_config.yaml') as cfg_yaml: return yaml.safe_load(cfg_yaml) except (KeyError, BadZipfile): return {}