-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Simon Heisterkamp
committed
Oct 29, 2024
1 parent
f3c7b81
commit 58f17b5
Showing
2 changed files
with
16 additions
and
18 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,26 @@ | ||
import json | ||
from typing import Dict | ||
|
||
from spetlr.spark import Spark | ||
|
||
|
||
class AzureTags: | ||
"""Represents easy access to the azure resource tags of the workspace.""" | ||
|
||
_tags = None | ||
def __init__(self): | ||
tags_json = Spark.get().conf.get( | ||
"spark.databricks.clusterUsageTags.clusterAllTags" | ||
) | ||
self._tags: Dict[str, str] = { | ||
i["key"]: i["value"] for i in json.loads(tags_json) | ||
} | ||
|
||
@classmethod | ||
def init(cls): | ||
if cls._tags is None: | ||
tags_json = Spark.get().conf.get( | ||
"spark.databricks.clusterUsageTags.clusterAllTags" | ||
) | ||
cls._tags = {i["key"]: i["value"] for i in json.loads(tags_json)} | ||
def keys(self): | ||
return self._tags.keys() | ||
|
||
@classmethod | ||
def keys(cls): | ||
cls.init() | ||
return cls._tags.keys() | ||
|
||
@classmethod | ||
def __getattr__(cls, attr): | ||
def __getattr__(self, attr) -> str: | ||
# only called when self.attr doesn't exist | ||
cls.init() | ||
return cls._tags[attr] | ||
return self._tags[attr] | ||
|
||
def asDict(self) -> Dict[str, str]: | ||
return self._tags.copy() |
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