admongo 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
admongo-0.1.0/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ BSD 2-Clause License
2
+
3
+ Copyright (c) 2020, Karlsruhe Institute of Technology (KIT)
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
admongo-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,61 @@
1
+ Metadata-Version: 2.1
2
+ Name: admongo
3
+ Version: 0.1.0
4
+ Summary: MongoDB Administration Tool
5
+ Author: The Virtmat Tools Team
6
+ Author-email: virtmat-tools@lists.kit.edu
7
+ License: BSD-2-Clause
8
+ Keywords: database,database management system
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: End Users/Desktop
12
+ Classifier: Intended Audience :: System Administrators
13
+ Classifier: License :: OSI Approved :: BSD License
14
+ Classifier: Natural Language :: English
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Topic :: Database
24
+ Classifier: Topic :: Software Development :: User Interfaces
25
+ Classifier: Topic :: Other/Nonlisted Topic
26
+ Requires-Python: >=3.8
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Requires-Dist: pymongo
30
+
31
+ ## About
32
+
33
+ This code automates MongoDB administrative tasks without knowledge of mongo shell language (JavaScript).
34
+
35
+ This repository contains scripts to automate adminstrative tasks on MongoDB.
36
+
37
+ * A Python module using PyMongo, the Python API for MongoDB. Detailed usage instructions can be found [here](docs/pymongo_admin.md).
38
+ * A bash script using the native JavaScript-based `mongo` client from the mongodb package.
39
+ This interface is not further maintained and is deprecated.
40
+
41
+ ## How to install
42
+
43
+ From the PyPI repository:
44
+ ```
45
+ pip install admongo
46
+ ```
47
+
48
+ From the Gitlab repository:
49
+ ```
50
+ pip install git+https://gitlab.kit.edu/ivan.kondov/mongo-admin.git
51
+ ```
52
+
53
+ ## How to use
54
+
55
+ A short help can be obtained with the command:
56
+
57
+ ```
58
+ mongo_admin --help
59
+ ```
60
+
61
+ See the [detailed usage instructions](docs/pymongo_admin.md).
@@ -0,0 +1,31 @@
1
+ ## About
2
+
3
+ This code automates MongoDB administrative tasks without knowledge of mongo shell language (JavaScript).
4
+
5
+ This repository contains scripts to automate adminstrative tasks on MongoDB.
6
+
7
+ * A Python module using PyMongo, the Python API for MongoDB. Detailed usage instructions can be found [here](docs/pymongo_admin.md).
8
+ * A bash script using the native JavaScript-based `mongo` client from the mongodb package.
9
+ This interface is not further maintained and is deprecated.
10
+
11
+ ## How to install
12
+
13
+ From the PyPI repository:
14
+ ```
15
+ pip install admongo
16
+ ```
17
+
18
+ From the Gitlab repository:
19
+ ```
20
+ pip install git+https://gitlab.kit.edu/ivan.kondov/mongo-admin.git
21
+ ```
22
+
23
+ ## How to use
24
+
25
+ A short help can be obtained with the command:
26
+
27
+ ```
28
+ mongo_admin --help
29
+ ```
30
+
31
+ See the [detailed usage instructions](docs/pymongo_admin.md).
@@ -0,0 +1,53 @@
1
+ [metadata]
2
+ name = admongo
3
+ version = 0.1.0
4
+ author = The Virtmat Tools Team
5
+ author_email = virtmat-tools@lists.kit.edu
6
+ description = MongoDB Administration Tool
7
+ long_description = file: README.md
8
+ long_description_content_type = text/markdown
9
+ keywords = database, database management system
10
+ license = BSD-2-Clause
11
+ classifiers =
12
+ Development Status :: 4 - Beta
13
+ Environment :: Console
14
+ Intended Audience :: End Users/Desktop
15
+ Intended Audience :: System Administrators
16
+ License :: OSI Approved :: BSD License
17
+ Natural Language :: English
18
+ Operating System :: OS Independent
19
+ Programming Language :: Python
20
+ Programming Language :: Python :: 3
21
+ Programming Language :: Python :: 3.8
22
+ Programming Language :: Python :: 3.9
23
+ Programming Language :: Python :: 3.10
24
+ Programming Language :: Python :: 3.11
25
+ Programming Language :: Python :: 3.12
26
+ Topic :: Database
27
+ Topic :: Software Development :: User Interfaces
28
+ Topic :: Other/Nonlisted Topic
29
+
30
+ [options]
31
+ zip_safe = false
32
+ package_dir =
33
+ = src
34
+ packages = find:
35
+ python_requires = >=3.8
36
+ install_requires =
37
+ pymongo
38
+
39
+ [options.packages.find]
40
+ where = src
41
+
42
+ [options.entry_points]
43
+ console_scripts =
44
+ mongo_admin = pymongo_admin.mongo_admin:main
45
+
46
+ [flake8]
47
+ max-line-length = 120
48
+ exclude = __init__.py
49
+
50
+ [egg_info]
51
+ tag_build =
52
+ tag_date = 0
53
+
admongo-0.1.0/setup.py ADDED
@@ -0,0 +1,4 @@
1
+ from setuptools import setup
2
+
3
+ if __name__ == '__main__':
4
+ setup()
@@ -0,0 +1,61 @@
1
+ Metadata-Version: 2.1
2
+ Name: admongo
3
+ Version: 0.1.0
4
+ Summary: MongoDB Administration Tool
5
+ Author: The Virtmat Tools Team
6
+ Author-email: virtmat-tools@lists.kit.edu
7
+ License: BSD-2-Clause
8
+ Keywords: database,database management system
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: End Users/Desktop
12
+ Classifier: Intended Audience :: System Administrators
13
+ Classifier: License :: OSI Approved :: BSD License
14
+ Classifier: Natural Language :: English
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Topic :: Database
24
+ Classifier: Topic :: Software Development :: User Interfaces
25
+ Classifier: Topic :: Other/Nonlisted Topic
26
+ Requires-Python: >=3.8
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Requires-Dist: pymongo
30
+
31
+ ## About
32
+
33
+ This code automates MongoDB administrative tasks without knowledge of mongo shell language (JavaScript).
34
+
35
+ This repository contains scripts to automate adminstrative tasks on MongoDB.
36
+
37
+ * A Python module using PyMongo, the Python API for MongoDB. Detailed usage instructions can be found [here](docs/pymongo_admin.md).
38
+ * A bash script using the native JavaScript-based `mongo` client from the mongodb package.
39
+ This interface is not further maintained and is deprecated.
40
+
41
+ ## How to install
42
+
43
+ From the PyPI repository:
44
+ ```
45
+ pip install admongo
46
+ ```
47
+
48
+ From the Gitlab repository:
49
+ ```
50
+ pip install git+https://gitlab.kit.edu/ivan.kondov/mongo-admin.git
51
+ ```
52
+
53
+ ## How to use
54
+
55
+ A short help can be obtained with the command:
56
+
57
+ ```
58
+ mongo_admin --help
59
+ ```
60
+
61
+ See the [detailed usage instructions](docs/pymongo_admin.md).
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ README.md
3
+ setup.cfg
4
+ setup.py
5
+ src/admongo.egg-info/PKG-INFO
6
+ src/admongo.egg-info/SOURCES.txt
7
+ src/admongo.egg-info/dependency_links.txt
8
+ src/admongo.egg-info/entry_points.txt
9
+ src/admongo.egg-info/not-zip-safe
10
+ src/admongo.egg-info/requires.txt
11
+ src/admongo.egg-info/top_level.txt
12
+ src/pymongo_admin/__init__.py
13
+ src/pymongo_admin/mongo_admin.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ mongo_admin = pymongo_admin.mongo_admin:main
@@ -0,0 +1 @@
1
+ pymongo
@@ -0,0 +1 @@
1
+ pymongo_admin
File without changes
@@ -0,0 +1,216 @@
1
+ """
2
+ Developed at Karlsruhe Institute of Technology (KIT), December 2019
3
+ This script uses pymongo commands to automate user management of mongodb instances.
4
+ """
5
+ import argparse
6
+ import getpass
7
+ from bson.json_util import dumps
8
+ from pymongo import MongoClient
9
+
10
+
11
+ def pass_set():
12
+ """Return a set password with password retype checking."""
13
+ pwd = -999
14
+ re_pwd = 111
15
+ while pwd != re_pwd:
16
+ pwd = getpass.getpass('New password for user: ')
17
+ re_pwd = getpass.getpass('Re-type password: ')
18
+ if pwd == re_pwd:
19
+ return pwd
20
+ print('Passwords do not match, try again: ')
21
+ return None
22
+
23
+
24
+ def main():
25
+ """the main function"""
26
+ parser = argparse.ArgumentParser()
27
+ parser.add_argument('--host', required=True,
28
+ help='Hostname of MongoDB instance')
29
+ parser.add_argument('--cacert', required=True,
30
+ help='Path to CA certificate')
31
+ parser.add_argument('--clcert', default=None, required=False,
32
+ help='Path to client certificate')
33
+ args = parser.parse_args()
34
+ opt = 0
35
+
36
+ while True:
37
+ try:
38
+ print('\nYour login credentials for '+args.host+':\n')
39
+ x509 = input('Do you use x509 authentication? [no/yes]\n' +
40
+ '(press "Enter" if you don\'t know or "0" to quit): ')
41
+ assert x509.lower() in ['yes', 'no', '', '0']
42
+ if x509.lower() == 'yes':
43
+ certkeyfile = input('Locate your certificate/key file: ')
44
+ client = MongoClient(host=args.host, authSource='$external',
45
+ tlsCertificateKeyFile=certkeyfile,
46
+ tlsCAFile=args.cacert, tls=True,
47
+ authMechanism='MONGODB-X509')
48
+ db = client['$external']
49
+ client.server_info()
50
+ elif x509.lower() in ['no', '']:
51
+ db_auth = input('Your authentication database: ')
52
+ user_auth = input('Your username to login: ')
53
+ pwd_auth = getpass.getpass(f'Your password for {user_auth}: ')
54
+ client = MongoClient(host=args.host, username=user_auth,
55
+ authSource=db_auth, password=pwd_auth,
56
+ tlsCertificateKeyFile=args.clcert,
57
+ tlsCAFile=args.cacert, tls=True)
58
+ db = client[db_auth]
59
+ client.server_info()
60
+ elif x509 == '0':
61
+ opt = 'quit'
62
+ break
63
+ except Exception as err:
64
+ print(err)
65
+
66
+ while opt != 'quit':
67
+ try:
68
+ choice = input("""
69
+ 1: Create user
70
+ 2: Change password
71
+ 3: Remove user
72
+ 4: Grant a role to user
73
+ 5: Revoke a role from user
74
+ 6: Show users
75
+ 7: List available databases
76
+ 8: Create a database
77
+ 9: Drop a database
78
+ 0: Quit/Log out
79
+
80
+ your choice (0 for Quit): """)
81
+
82
+ if choice == '1':
83
+ opt = 'createUser'
84
+ elif choice == '2':
85
+ opt = 'updatePass'
86
+ elif choice == '3':
87
+ opt = 'dropuser'
88
+ elif choice == '4':
89
+ opt = 'grant'
90
+ elif choice == '5':
91
+ opt = 'revoke'
92
+ elif choice == '6':
93
+ opt = 'showusers'
94
+ elif choice == '7':
95
+ opt = 'listdb'
96
+ elif choice == '8':
97
+ opt = 'createdb'
98
+ elif choice == '9':
99
+ opt = 'dropdb'
100
+ elif choice == '0':
101
+ opt = 'quit'
102
+ else:
103
+ raise Exception('WrongChoice')
104
+
105
+ if opt == 'createUser':
106
+ try:
107
+ x509_newuser = input('Do you use X509 authentication for new user [no/yes]: ')
108
+ if x509_newuser == 'yes':
109
+ subject_dn = input('Subject DN of new user: ')
110
+ role_newuser = input('Role of new user: ')
111
+ db = client['$external']
112
+ db.command({'createUser': subject_dn,
113
+ 'roles': [{'role': role_newuser, 'db': 'admin'}]})
114
+ print(f'\n {subject_dn} is created for admin database with {role_newuser} role.')
115
+ else:
116
+ new_user = input('New username: ')
117
+ db_sibling_in = input('Authentication database of new user: ')
118
+ db_sibling = client[db_sibling_in]
119
+ pass_newuser = pass_set()
120
+ role_newuser = input('Role of new user: ')
121
+ db_sibling.command(opt, new_user, pwd=pass_newuser,
122
+ roles=[{'role': role_newuser, 'db': db_sibling_in}])
123
+ print(f'\n {new_user} is created for {db_sibling} database with {role_newuser} role.')
124
+ except Exception as err:
125
+ print(err)
126
+
127
+ elif opt == 'updatePass':
128
+ try:
129
+ user_update = input('Username to update the password: ')
130
+ db_sibling_in = input('Authentication database of user: ')
131
+ db_sibling = client[db_sibling_in]
132
+ pass_newuser = pass_set()
133
+ db_sibling.command('updateUser', user_update, pwd=pass_newuser)
134
+ print(f'\n Password is changed successfully for {user_update}.')
135
+ except Exception as err:
136
+ print(err)
137
+
138
+ elif opt == 'dropuser':
139
+ try:
140
+ user_drop = input('Username to be removed: ')
141
+ db_sibling_in = input(f'Authentication database of {user_drop}: ')
142
+ db_sibling = client[db_sibling_in]
143
+ db_sibling.command('dropUser', user_drop)
144
+ print(f'The user {user_drop} is removed from {db_sibling_in} database.')
145
+ except Exception as err:
146
+ print(err)
147
+
148
+ elif opt == 'grant':
149
+ try:
150
+ user_grant = input('Username to be granted: ')
151
+ db_sibling_in = input('Authentication database of user: ')
152
+ db_sibling = client[db_sibling_in]
153
+ target_db = input('Database for which new role will be granted, target database: ')
154
+ new_role = input(f'New role for {user_grant}: ')
155
+ db_sibling.command('grantRolesToUser', user_grant,
156
+ roles=[{'role': new_role, 'db': target_db}])
157
+ print(f'\n The {new_role} role is granted to {user_grant} on {target_db} database.')
158
+ except Exception as err:
159
+ print(err)
160
+
161
+ elif opt == 'revoke':
162
+ try:
163
+ user_revoked = input('Username to revoke a role from: ')
164
+ db_sibling_in = input('Authentication database of user: ')
165
+ db_sibling = client[db_sibling_in]
166
+ target_db = input('Database for which role will be revoked, target database:')
167
+ role_drop = input('Role to be revoked from {user_revoked}: ')
168
+ db_sibling.command('revokeRolesFromUser', user_revoked,
169
+ roles=[{'role': role_drop, 'db': target_db}])
170
+ print(f'\n The {role_drop} role is revoked from {user_revoked} on {target_db} database.')
171
+ except Exception as err:
172
+ print(err)
173
+
174
+ elif opt == 'showusers':
175
+ try:
176
+ db_sibling_in = input('Database to print: ')
177
+ db_sibling = client[db_sibling_in]
178
+ command_exit = db_sibling.command('usersInfo')
179
+ print(dumps(command_exit, indent=4))
180
+ except Exception as err:
181
+ print(err)
182
+
183
+ elif opt == 'listdb':
184
+ try:
185
+ db_sibling = client['admin']
186
+ command_exit = db_sibling.command('listDatabases')
187
+ print(dumps(command_exit, indent=4))
188
+ except Exception as err:
189
+ print(err)
190
+
191
+ elif opt == 'createdb':
192
+ try:
193
+ db_name = input('Name of new database: ')
194
+ db_sibling = client[db_name]
195
+ privs = [{'resource': {'db': db_name, 'collection': ''},
196
+ 'actions': ['changeOwnPassword']}]
197
+ command_exit = db_sibling.command('createRole',
198
+ 'changeOwnPassword',
199
+ privileges=privs,
200
+ roles=[])
201
+ print(dumps(command_exit, indent=4))
202
+ except Exception as err:
203
+ print(err)
204
+
205
+ elif opt == 'dropdb':
206
+ try:
207
+ db_name = input('Database to drop: ')
208
+ db_sibling = client[db_name]
209
+ command_exit = db_sibling.command('dropAllUsersFromDatabase')
210
+ print(dumps(command_exit, indent=4))
211
+ client.drop_database(db_name)
212
+ except Exception as err:
213
+ print(err)
214
+
215
+ except Exception:
216
+ print('Wrong choice. Please try again.')