Created
January 24, 2024 01:40
-
-
Save carsongee/0bd36f183aa50e892492eb977f915639 to your computer and use it in GitHub Desktop.
Harness URL Parser snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import NamedTuple | |
from urllib.parse import urlparse | |
class HarnessPipeline(NamedTuple): | |
account: str | |
org: str | |
project: str | |
pipeline: str | |
@classmethod | |
def from_string(cls, url: str): | |
path = urlparse(url).path.split('/') | |
account = path[3] | |
org = path[6] | |
project = path[8] | |
pipeline = path[10] | |
return cls(account=account, org=org, project=project, pipeline=pipeline) | |
@property | |
def allow_list_tuple(self) -> str: | |
return f"{self.org}/{self.project}/{self.pipeline}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just so I never have to count slashes again and can pull out info from the URLs in Harness.io