Merge "Experimental Compass Support"
[pharos-tools.git] / laas-fog / pharoslaas / actions / vpn_delete_user.py
1 ##############################################################################
2 # Copyright 2017 Parker Berberian and Others                                 #
3 #                                                                            #
4 # Licensed under the Apache License, Version 2.0 (the "License");            #
5 # you may not use this file except in compliance with the License.           #
6 # You may obtain a copy of the License at                                    #
7 #                                                                            #
8 #    http://www.apache.org/licenses/LICENSE-2.0                              #
9 #                                                                            #
10 # Unless required by applicable law or agreed to in writing, software        #
11 # distributed under the License is distributed on an "AS IS" BASIS,          #
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
13 # See the License for the specific language governing permissions and        #
14 # limitations under the License.                                             #
15 ##############################################################################
16
17 import json
18 from vpnAction import VPNAction
19
20
21 class Del_VPN_User(VPNAction):
22
23     def __init__(self, config=None):
24         super(Del_VPN_User, self).__init__(config=config)
25
26     def run(self, dn=None, key=None):
27         if not dn or dn == "None":
28             if not key or key == "None":
29                 return
30             vpn_info = json.loads(
31                     self.action_service.get_value(
32                         name=key,
33                         local=False,
34                         decrypt=True
35                         )
36                     )
37             dn = vpn_info['dn']
38             st2key = key
39         else:
40             st2key = 'vpn_'
41             # get username from dn
42             for attr in dn.split(','):
43                 if 'uid' in attr:
44                     st2key += attr.split('=')[-1]
45         # we have the dn and key now
46         self.action_service.delete_value(name=st2key, local=False)
47         self.deleteUser(dn)