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
1diff --git a/actions.yaml b/actions.yaml
2new file mode 100644
3index 0000000..dad5090
4--- /dev/null
5+++ b/actions.yaml
6@@ -0,0 +1,3 @@
7+remove-sudopair:
8+ description: Remove sudo-pair configuration and binaries
9+
10diff --git a/actions/actions.py b/actions/actions.py
11new file mode 100755
12index 0000000..7dd03d8
13--- /dev/null
14+++ b/actions/actions.py
15@@ -0,0 +1,48 @@
16+#!/usr/local/sbin/charm-env python3
17+#
18+# Copyright 2016,2019,2020 Canonical Ltd
19+#
20+# Licensed under the Apache License, Version 2.0 (the "License");
21+# you may not use this file except in compliance with the License.
22+# You may obtain a copy of the License at
23+#
24+# http://www.apache.org/licenses/LICENSE-2.0
25+#
26+# Unless required by applicable law or agreed to in writing, software
27+# distributed under the License is distributed on an "AS IS" BASIS,
28+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29+# See the License for the specific language governing permissions and
30+# limitations under the License.
31+import os
32+import sys
33+
34+from charmhelpers.core.hookenv import action_set, action_fail
35+
36+
37+sys.path.append("lib")
38+
39+import libsudopair # NOQA
40+
41+
42+def remove():
43+ """Action to remove sudo-pair config and binaries"""
44+ sph = libsudopair.SudoPairHelper()
45+ sph.deconfigure()
46+ action_set({"message": "Successfully removed sudo-pair config and binaries"})
47+
48+
49+# A dictionary of all the defined actions to callables (which take
50+# parsed arguments).
51+ACTIONS = {"remove-sudopair": remove}
52+
53+
54+def main(args):
55+ action_name = os.path.basename(args[0])
56+ try:
57+ ACTIONS[action_name]()
58+ except Exception as e:
59+ action_fail(str(e))
60+
61+
62+if __name__ == "__main__":
63+ sys.exit(main(sys.argv))
64diff --git a/actions/remove-sudopair b/actions/remove-sudopair
65new file mode 120000
66index 0000000..ff9536b
67--- /dev/null
68+++ b/actions/remove-sudopair
69@@ -0,0 +1 @@
70+./actions.py
71\ No newline at end of file
72diff --git a/lib/libsudopair.py b/lib/libsudopair.py
73index d3b96a7..095e9a4 100644
74--- a/lib/libsudopair.py
75+++ b/lib/libsudopair.py
76@@ -113,7 +113,19 @@ class SudoPairHelper(object):
77 return None
78
79 def deconfigure(self):
80- hookenv.log("Delete {}".format(self.sudo_conf_path))
81- os.unlink(self.sudo_conf_path)
82- sudo_pair_lib = os.path.join(hookenv.charm_dir(), 'files', 'sudo_pair.so')
83- hookenv.log("Delete lib {}".format(sudo_pair_lib))
84+ paths = [
85+ self.sudo_conf_path,
86+ self.sudo_lib_path,
87+ self.binary_path,
88+ self.user_prompt_path,
89+ self.pair_prompt_path,
90+ self.sudoers_bypass_path,
91+ self.tmpfiles_conf
92+ ]
93+ hookenv.log("Deleting: {}".format(paths))
94+ for path in paths:
95+ try:
96+ os.unlink(path)
97+ except Exception as e:
98+ # We're trying hard to delete all files, even if some might fail
99+ hookenv.log("Got exception unlinking {}: {}, continuing".format(path, e))

Subscribers

People subscribed via source and target branches