-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Backup and ClusterRole constructors and to_dict function (#1349)
* Update Backup and ClusterRole constuctors and to_dict function * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update backup docs * Update docs * Update documentations * Remove if not self.yaml_file * Remove upper super.to_dict() * Remove and not self.yaml_file * Update documentaions * Use res.update with excluded resources * Update docs * Remove update() usage to add excluded_resources to spec. update() overrides spec content. * Verified --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
ab1d057
commit 7c64416
Showing
2 changed files
with
24 additions
and
63 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
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,51 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
from ocp_resources.constants import TIMEOUT_4MINUTES | ||
from ocp_resources.resource import Resource | ||
|
||
|
||
class ClusterRole(Resource): | ||
""" | ||
ClusterRole object | ||
ClusterRole in kubernetes 'authorization-resources' official API: | ||
https://kubernetes.io/docs/reference/kubernetes-api/authorization-resources/cluster-role-v1/ | ||
""" | ||
|
||
api_group = Resource.ApiGroup.RBAC_AUTHORIZATION_K8S_IO | ||
|
||
def __init__( | ||
self, | ||
name=None, | ||
client=None, | ||
rules=None, | ||
teardown=True, | ||
yaml_file=None, | ||
delete_timeout=TIMEOUT_4MINUTES, | ||
**kwargs, | ||
): | ||
def __init__(self, rules=None, **kwargs): | ||
""" | ||
Args: | ||
name (str): Role name. | ||
client (DynamicClient): DynamicClient to use. | ||
rules (list): list of dicts of rules. In the dict: | ||
permissions_to_resources (list): List of string with resource/s to which you want to add permissions to. | ||
Verbs (list): Determine the action/s (permissions) applicable on a specific resource. | ||
Available verbs per resource can be seen with the command 'oc api-resources --sort-by name -o wide' | ||
teardown (bool, default: True): Indicates if this resource would need to be deleted. | ||
yaml_file (yaml, default: None): yaml file for the resource. | ||
delete_timeout (int, default: 4 minutes): timeout associated with delete action. | ||
""" | ||
super().__init__( | ||
client=client, | ||
name=name, | ||
teardown=teardown, | ||
yaml_file=yaml_file, | ||
delete_timeout=delete_timeout, | ||
**kwargs, | ||
) | ||
super().__init__(**kwargs) | ||
self.rules = rules | ||
|
||
def to_dict(self): | ||
if not self.rules and not self.yaml_file: | ||
raise ValueError("must send rules or yaml_file") | ||
if not self.res: | ||
super().to_dict() | ||
super().to_dict() | ||
if not self.yaml_file: | ||
if not self.rules: | ||
raise ValueError("must send rules or yaml_file") | ||
self.res["rules"] = self.rules |