Skip to content

Instantly share code, notes, and snippets.

@carsongee
Created January 24, 2024 01:40
Show Gist options
  • Save carsongee/0bd36f183aa50e892492eb977f915639 to your computer and use it in GitHub Desktop.
Save carsongee/0bd36f183aa50e892492eb977f915639 to your computer and use it in GitHub Desktop.
Harness URL Parser snippet
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}"
@carsongee
Copy link
Author

Just so I never have to count slashes again and can pull out info from the URLs in Harness.io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment