-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_users
More file actions
executable file
·59 lines (49 loc) · 1.77 KB
/
Copy pathlist_users
File metadata and controls
executable file
·59 lines (49 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
# Copyright (C) 2021 Corexalys.
#
# This file is part of rs3f.
#
# rs3f is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# rs3f is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with rs3f. If not, see <https://www.gnu.org/licenses/>.
from argparse import ArgumentParser
import os
import re
from rs3f_common import get_authorized_keys_path, get_home_path
RE_PUBLIC_KEY = re.compile(
r"(?P<key>ssh-[^\s]+ [a-zA-Z0-9+/]+=*)(?: (?P<username>[^\s]+))?"
)
def main():
parser = ArgumentParser()
parser.add_argument(
"container_name",
help="A comma-separated list of container names",
)
args = parser.parse_args()
to_add = set()
for container in args.container_name.split(","):
container = container.strip()
if not container:
continue
if not os.path.exists(get_home_path(container)):
raise ValueError(f"Container '{container}' does not exist")
print(f"{container}:")
path = get_authorized_keys_path(container)
with open(path, "r") as authorized_file:
for line in authorized_file:
if not line.strip() or line.strip().startswith("#"):
continue
_, _, user = line.split(" ")
print(f"- {user}")
print("DONE")
if __name__ == "__main__":
main()