Ver código fonte

Remove cluster in favor of rolebindings.

Kenny Woodson 7 anos atrás
pai
commit
46c94de67f

+ 20 - 21
roles/lib_openshift/library/oc_adm_policy_group.py

@@ -1959,28 +1959,28 @@ class PolicyGroup(OpenShiftCLI):
         self.verbose = verbose
         self._rolebinding = None
         self._scc = None
-        self._cluster_policy_bindings = None
-        self._policy_bindings = None
+        self._cluster_role_bindings = None
+        self._role_bindings = None
 
     @property
-    def policybindings(self):
-        if self._policy_bindings is None:
-            results = self._get('clusterpolicybindings', None)
+    def rolebindings(self):
+        if self._role_bindings is None:
+            results = self._get('rolebindings', None)
             if results['returncode'] != 0:
-                raise OpenShiftCLIError('Could not retrieve policybindings')
-            self._policy_bindings = results['results'][0]['items'][0]
+                raise OpenShiftCLIError('Could not retrieve rolebindings')
+            self._role_bindings = results['results'][0]['items']
 
-        return self._policy_bindings
+        return self._role_bindings
 
     @property
-    def clusterpolicybindings(self):
-        if self._cluster_policy_bindings is None:
-            results = self._get('clusterpolicybindings', None)
+    def clusterrolebindings(self):
+        if self._cluster_role_bindings is None:
+            results = self._get('clusterrolebindings', None)
             if results['returncode'] != 0:
-                raise OpenShiftCLIError('Could not retrieve clusterpolicybindings')
-            self._cluster_policy_bindings = results['results'][0]['items'][0]
+                raise OpenShiftCLIError('Could not retrieve clusterrolebindings')
+            self._cluster_role_bindings = results['results'][0]['items']
 
-        return self._cluster_policy_bindings
+        return self._cluster_role_bindings
 
     @property
     def role_binding(self):
@@ -2023,18 +2023,17 @@ class PolicyGroup(OpenShiftCLI):
         ''' return whether role_binding exists '''
         bindings = None
         if self.config.config_options['resource_kind']['value'] == 'cluster-role':
-            bindings = self.clusterpolicybindings
+            bindings = self.clusterrolebindings
         else:
-            bindings = self.policybindings
+            bindings = self.rolebindings
 
         if bindings is None:
             return False
 
-        for binding in bindings['roleBindings']:
-            _rb = binding['roleBinding']
-            if _rb['roleRef']['name'] == self.config.config_options['name']['value'] and \
-                    _rb['groupNames'] is not None and \
-                    self.config.config_options['group']['value'] in _rb['groupNames']:
+        for binding in bindings:
+            if binding['roleRef']['name'] == self.config.config_options['name']['value'] and \
+                    binding['groupNames'] is not None and \
+                    self.config.config_options['group']['value'] in binding['groupNames']:
                 self.role_binding = binding
                 return True
 

+ 23 - 24
roles/lib_openshift/library/oc_adm_policy_user.py

@@ -1950,36 +1950,36 @@ class PolicyUser(OpenShiftCLI):
     ''' Class to handle attaching policies to users '''
 
     def __init__(self,
-                 policy_config,
+                 config,
                  verbose=False):
         ''' Constructor for PolicyUser '''
-        super(PolicyUser, self).__init__(policy_config.namespace, policy_config.kubeconfig, verbose)
-        self.config = policy_config
+        super(PolicyUser, self).__init__(config.namespace, config.kubeconfig, verbose)
+        self.config = config
         self.verbose = verbose
         self._rolebinding = None
         self._scc = None
-        self._cluster_policy_bindings = None
-        self._policy_bindings = None
+        self._cluster_role_bindings = None
+        self._role_bindings = None
 
     @property
-    def policybindings(self):
-        if self._policy_bindings is None:
-            results = self._get('policybindings', None)
+    def rolebindings(self):
+        if self._role_bindings is None:
+            results = self._get('rolebindings', None)
             if results['returncode'] != 0:
-                raise OpenShiftCLIError('Could not retrieve policybindings')
-            self._policy_bindings = results['results'][0]['items'][0]
+                raise OpenShiftCLIError('Could not retrieve rolebindings')
+            self._role_bindings = results['results'][0]['items']
 
-        return self._policy_bindings
+        return self._role_bindings
 
     @property
-    def clusterpolicybindings(self):
-        if self._cluster_policy_bindings is None:
-            results = self._get('clusterpolicybindings', None)
+    def clusterrolebindings(self):
+        if self._cluster_role_bindings is None:
+            results = self._get('clusterrolebindings', None)
             if results['returncode'] != 0:
-                raise OpenShiftCLIError('Could not retrieve clusterpolicybindings')
-            self._cluster_policy_bindings = results['results'][0]['items'][0]
+                raise OpenShiftCLIError('Could not retrieve clusterrolebindings')
+            self._cluster_role_bindings = results['results'][0]['items']
 
-        return self._cluster_policy_bindings
+        return self._cluster_role_bindings
 
     @property
     def role_binding(self):
@@ -2017,18 +2017,17 @@ class PolicyUser(OpenShiftCLI):
         ''' return whether role_binding exists '''
         bindings = None
         if self.config.config_options['resource_kind']['value'] == 'cluster-role':
-            bindings = self.clusterpolicybindings
+            bindings = self.clusterrolebindings
         else:
-            bindings = self.policybindings
+            bindings = self.rolebindings
 
         if bindings is None:
             return False
 
-        for binding in bindings['roleBindings']:
-            _rb = binding['roleBinding']
-            if _rb['roleRef']['name'] == self.config.config_options['name']['value'] and \
-                    _rb['userNames'] is not None and \
-                    self.config.config_options['user']['value'] in _rb['userNames']:
+        for binding in bindings:
+            if binding['roleRef']['name'] == self.config.config_options['name']['value'] and \
+                    binding['userNames'] is not None and \
+                    self.config.config_options['user']['value'] in binding['userNames']:
                 self.role_binding = binding
                 return True
 

+ 1 - 1
roles/lib_openshift/library/oc_clusterrole.py

@@ -1671,7 +1671,7 @@ class OCClusterRole(OpenShiftCLI):
             self.clusterrole = ClusterRole(content=result['results'][0])
             result['results'] = self.clusterrole.yaml_dict
 
-        elif 'clusterrole "{}" not found'.format(self.name) in result['stderr']:
+        elif '"{}" not found'.format(self.name) in result['stderr']:
             result['returncode'] = 0
             self.clusterrole = None
 

+ 20 - 21
roles/lib_openshift/src/class/oc_adm_policy_group.py

@@ -41,28 +41,28 @@ class PolicyGroup(OpenShiftCLI):
         self.verbose = verbose
         self._rolebinding = None
         self._scc = None
-        self._cluster_policy_bindings = None
-        self._policy_bindings = None
+        self._cluster_role_bindings = None
+        self._role_bindings = None
 
     @property
-    def policybindings(self):
-        if self._policy_bindings is None:
-            results = self._get('clusterpolicybindings', None)
+    def rolebindings(self):
+        if self._role_bindings is None:
+            results = self._get('rolebindings', None)
             if results['returncode'] != 0:
-                raise OpenShiftCLIError('Could not retrieve policybindings')
-            self._policy_bindings = results['results'][0]['items'][0]
+                raise OpenShiftCLIError('Could not retrieve rolebindings')
+            self._role_bindings = results['results'][0]['items']
 
-        return self._policy_bindings
+        return self._role_bindings
 
     @property
-    def clusterpolicybindings(self):
-        if self._cluster_policy_bindings is None:
-            results = self._get('clusterpolicybindings', None)
+    def clusterrolebindings(self):
+        if self._cluster_role_bindings is None:
+            results = self._get('clusterrolebindings', None)
             if results['returncode'] != 0:
-                raise OpenShiftCLIError('Could not retrieve clusterpolicybindings')
-            self._cluster_policy_bindings = results['results'][0]['items'][0]
+                raise OpenShiftCLIError('Could not retrieve clusterrolebindings')
+            self._cluster_role_bindings = results['results'][0]['items']
 
-        return self._cluster_policy_bindings
+        return self._cluster_role_bindings
 
     @property
     def role_binding(self):
@@ -105,18 +105,17 @@ class PolicyGroup(OpenShiftCLI):
         ''' return whether role_binding exists '''
         bindings = None
         if self.config.config_options['resource_kind']['value'] == 'cluster-role':
-            bindings = self.clusterpolicybindings
+            bindings = self.clusterrolebindings
         else:
-            bindings = self.policybindings
+            bindings = self.rolebindings
 
         if bindings is None:
             return False
 
-        for binding in bindings['roleBindings']:
-            _rb = binding['roleBinding']
-            if _rb['roleRef']['name'] == self.config.config_options['name']['value'] and \
-                    _rb['groupNames'] is not None and \
-                    self.config.config_options['group']['value'] in _rb['groupNames']:
+        for binding in bindings:
+            if binding['roleRef']['name'] == self.config.config_options['name']['value'] and \
+                    binding['groupNames'] is not None and \
+                    self.config.config_options['group']['value'] in binding['groupNames']:
                 self.role_binding = binding
                 return True
 

+ 23 - 24
roles/lib_openshift/src/class/oc_adm_policy_user.py

@@ -32,36 +32,36 @@ class PolicyUser(OpenShiftCLI):
     ''' Class to handle attaching policies to users '''
 
     def __init__(self,
-                 policy_config,
+                 config,
                  verbose=False):
         ''' Constructor for PolicyUser '''
-        super(PolicyUser, self).__init__(policy_config.namespace, policy_config.kubeconfig, verbose)
-        self.config = policy_config
+        super(PolicyUser, self).__init__(config.namespace, config.kubeconfig, verbose)
+        self.config = config
         self.verbose = verbose
         self._rolebinding = None
         self._scc = None
-        self._cluster_policy_bindings = None
-        self._policy_bindings = None
+        self._cluster_role_bindings = None
+        self._role_bindings = None
 
     @property
-    def policybindings(self):
-        if self._policy_bindings is None:
-            results = self._get('policybindings', None)
+    def rolebindings(self):
+        if self._role_bindings is None:
+            results = self._get('rolebindings', None)
             if results['returncode'] != 0:
-                raise OpenShiftCLIError('Could not retrieve policybindings')
-            self._policy_bindings = results['results'][0]['items'][0]
+                raise OpenShiftCLIError('Could not retrieve rolebindings')
+            self._role_bindings = results['results'][0]['items']
 
-        return self._policy_bindings
+        return self._role_bindings
 
     @property
-    def clusterpolicybindings(self):
-        if self._cluster_policy_bindings is None:
-            results = self._get('clusterpolicybindings', None)
+    def clusterrolebindings(self):
+        if self._cluster_role_bindings is None:
+            results = self._get('clusterrolebindings', None)
             if results['returncode'] != 0:
-                raise OpenShiftCLIError('Could not retrieve clusterpolicybindings')
-            self._cluster_policy_bindings = results['results'][0]['items'][0]
+                raise OpenShiftCLIError('Could not retrieve clusterrolebindings')
+            self._cluster_role_bindings = results['results'][0]['items']
 
-        return self._cluster_policy_bindings
+        return self._cluster_role_bindings
 
     @property
     def role_binding(self):
@@ -99,18 +99,17 @@ class PolicyUser(OpenShiftCLI):
         ''' return whether role_binding exists '''
         bindings = None
         if self.config.config_options['resource_kind']['value'] == 'cluster-role':
-            bindings = self.clusterpolicybindings
+            bindings = self.clusterrolebindings
         else:
-            bindings = self.policybindings
+            bindings = self.rolebindings
 
         if bindings is None:
             return False
 
-        for binding in bindings['roleBindings']:
-            _rb = binding['roleBinding']
-            if _rb['roleRef']['name'] == self.config.config_options['name']['value'] and \
-                    _rb['userNames'] is not None and \
-                    self.config.config_options['user']['value'] in _rb['userNames']:
+        for binding in bindings:
+            if binding['roleRef']['name'] == self.config.config_options['name']['value'] and \
+                    binding['userNames'] is not None and \
+                    self.config.config_options['user']['value'] in binding['userNames']:
                 self.role_binding = binding
                 return True
 

+ 1 - 1
roles/lib_openshift/src/class/oc_clusterrole.py

@@ -56,7 +56,7 @@ class OCClusterRole(OpenShiftCLI):
             self.clusterrole = ClusterRole(content=result['results'][0])
             result['results'] = self.clusterrole.yaml_dict
 
-        elif 'clusterrole "{}" not found'.format(self.name) in result['stderr']:
+        elif '"{}" not found'.format(self.name) in result['stderr']:
             result['returncode'] = 0
             self.clusterrole = None