Merge ~peter-sabaini/charm-sudo-pair:more-deconfiguration into ~sudo-pair-charmers/charm-sudo-pair:master

Proposed by Peter Sabaini
Status: Merged
Approved by: Jeremy Lounder
Approved revision: 227f5a0acb4a242240c9d8c331590030ee21496c
Merged at revision: 1b82414a662049168c53524a5e0dafe2091ffe0d
Proposed branch: ~peter-sabaini/charm-sudo-pair:more-deconfiguration
Merge into: ~sudo-pair-charmers/charm-sudo-pair:master
Diff against target: 99 lines (+68/-4)
4 files modified
actions.yaml (+3/-0)
actions/actions.py (+48/-0)
actions/remove-sudopair (+1/-0)
lib/libsudopair.py (+16/-4)
Reviewer Review Type Date Requested Status
Jeremy Lounder (community) Approve
Drew Freiberger (community) Approve
Canonical IS Reviewers Pending
Review via email: mp+377588@code.launchpad.net

Commit message

More deconfiguration
 - Be tidier when deconfiguring sudo-pair
 - Add action to remove sudo-pair binaries and config

To post a comment you must log in.
Revision history for this message
Drew Freiberger (afreiberger) wrote :

+1 lgtm

review: Approve
Revision history for this message
Jeremy Lounder (jldev) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/actions.yaml b/actions.yaml
0new file mode 1006440new file mode 100644
index 0000000..dad5090
--- /dev/null
+++ b/actions.yaml
@@ -0,0 +1,3 @@
1remove-sudopair:
2 description: Remove sudo-pair configuration and binaries
3
diff --git a/actions/actions.py b/actions/actions.py
0new file mode 1007554new file mode 100755
index 0000000..7dd03d8
--- /dev/null
+++ b/actions/actions.py
@@ -0,0 +1,48 @@
1#!/usr/local/sbin/charm-env python3
2#
3# Copyright 2016,2019,2020 Canonical Ltd
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16import os
17import sys
18
19from charmhelpers.core.hookenv import action_set, action_fail
20
21
22sys.path.append("lib")
23
24import libsudopair # NOQA
25
26
27def remove():
28 """Action to remove sudo-pair config and binaries"""
29 sph = libsudopair.SudoPairHelper()
30 sph.deconfigure()
31 action_set({"message": "Successfully removed sudo-pair config and binaries"})
32
33
34# A dictionary of all the defined actions to callables (which take
35# parsed arguments).
36ACTIONS = {"remove-sudopair": remove}
37
38
39def main(args):
40 action_name = os.path.basename(args[0])
41 try:
42 ACTIONS[action_name]()
43 except Exception as e:
44 action_fail(str(e))
45
46
47if __name__ == "__main__":
48 sys.exit(main(sys.argv))
diff --git a/actions/remove-sudopair b/actions/remove-sudopair
0new file mode 12000049new file mode 120000
index 0000000..ff9536b
--- /dev/null
+++ b/actions/remove-sudopair
@@ -0,0 +1 @@
1./actions.py
0\ No newline at end of file2\ No newline at end of file
diff --git a/lib/libsudopair.py b/lib/libsudopair.py
index d3b96a7..095e9a4 100644
--- a/lib/libsudopair.py
+++ b/lib/libsudopair.py
@@ -113,7 +113,19 @@ class SudoPairHelper(object):
113 return None113 return None
114114
115 def deconfigure(self):115 def deconfigure(self):
116 hookenv.log("Delete {}".format(self.sudo_conf_path))116 paths = [
117 os.unlink(self.sudo_conf_path)117 self.sudo_conf_path,
118 sudo_pair_lib = os.path.join(hookenv.charm_dir(), 'files', 'sudo_pair.so')118 self.sudo_lib_path,
119 hookenv.log("Delete lib {}".format(sudo_pair_lib))119 self.binary_path,
120 self.user_prompt_path,
121 self.pair_prompt_path,
122 self.sudoers_bypass_path,
123 self.tmpfiles_conf
124 ]
125 hookenv.log("Deleting: {}".format(paths))
126 for path in paths:
127 try:
128 os.unlink(path)
129 except Exception as e:
130 # We're trying hard to delete all files, even if some might fail
131 hookenv.log("Got exception unlinking {}: {}, continuing".format(path, e))

Subscribers

People subscribed via source and target branches