brain2-oc 2.1.5__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.
@@ -0,0 +1,8 @@
1
+ Ouroboros Coding Inc. License
2
+
3
+ Copyright (c) 2024 Ouroboros Coding Inc.
4
+
5
+ Permission is hereby granted, with limits, to any person using this software
6
+ within a project created by Ouroboros Coding Inc. Any attempt to modify this
7
+ code, or use it outside projects created by Ouroboros Coding Inc, will result
8
+ in legal action taken against the party using the code.
@@ -0,0 +1,24 @@
1
+ Metadata-Version: 2.1
2
+ Name: brain2_oc
3
+ Version: 2.1.5
4
+ Summary: Brain contains a service to manage users and permissions
5
+ Home-page: https://ouroboroscoding.com/body/brain2
6
+ Author: Chris Nasr - Ouroboros Coding Inc.
7
+ Author-email: chris@ouroboroscoding.com
8
+ License: Custom
9
+ Project-URL: Documentation, https://ouroboroscoding.com/body/brain2
10
+ Project-URL: Source, https://github.com/ouroboroscoding/brain2
11
+ Project-URL: Tracker, https://github.com/ouroboroscoding/brain2/issues
12
+ Keywords: rest,microservices
13
+ Platform: UNKNOWN
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+
18
+ # Brain2
19
+
20
+ Body 2.0 service that handles users and permissions.
21
+
22
+ This code comes without documentation as it's not meant to be used by anyone
23
+ outside of Ouroboros Coding Inc. Please see LICENSE for further information.
24
+
@@ -0,0 +1,6 @@
1
+ # Brain2
2
+
3
+ Body 2.0 service that handles users and permissions.
4
+
5
+ This code comes without documentation as it's not meant to be used by anyone
6
+ outside of Ouroboros Coding Inc. Please see LICENSE for further information.
@@ -0,0 +1,15 @@
1
+ # coding=utf8
2
+ """ Brain
3
+
4
+ Exposes internal modules
5
+ """
6
+
7
+ __author__ = "Chris Nasr"
8
+ __copyright__ = "Ouroboros Coding Inc."
9
+ __email__ = "chris@ouroboroscoding.com"
10
+ __created__ = "2023-07-16"
11
+
12
+ __all__ = [ 'errors', 'helpers', 'rights', 'service' ]
13
+
14
+ # Local
15
+ from brain import errors, helpers, rights, service
@@ -0,0 +1,90 @@
1
+ # coding=utf8
2
+ """ Brain
3
+
4
+ Handles authorization / user requests
5
+ """
6
+
7
+ __author__ = "Chris Nasr"
8
+ __version__ = "1.0.0"
9
+ __copyright__ = "Ouroboros Coding Inc."
10
+ __email__ = "chris@ouroboroscoding.com"
11
+ __created__ = "2022-08-25"
12
+
13
+ # Ouroboros imports
14
+ from config import config
15
+ from upgrade import upgrade
16
+
17
+ # Python imports
18
+ from os.path import abspath, expanduser
19
+ from pathlib import Path
20
+ from sys import argv, exit, stderr
21
+
22
+ # Pip imports
23
+ from rest_mysql import Record_MySQL
24
+
25
+ # Module imports
26
+ from brain import install, rest
27
+
28
+ def cli():
29
+ """CLI
30
+
31
+ Called from the command line to run from the current directory
32
+
33
+ Returns:
34
+ uint
35
+ """
36
+
37
+ # Get Brain config
38
+ conf = config.brain({
39
+ 'data': './.brain',
40
+ 'mysql': 'primary',
41
+ 'user_default_locale': 'en-US'
42
+ })
43
+ if '~' in conf['data']:
44
+ conf['data'] = expanduser(conf['data'])
45
+ conf['data'] = abspath(conf['data'])
46
+
47
+ # Add the global prepend
48
+ Record_MySQL.db_prepend(config.mysql.prepend(''))
49
+
50
+ # Add the primary mysql DB
51
+ Record_MySQL.add_host('brain', config.mysql.hosts[conf['mysql']]({
52
+ 'host': 'localhost',
53
+ 'port': 3306,
54
+ 'charset': 'utf8',
55
+ 'user': 'root',
56
+ 'passwd': ''
57
+ }))
58
+
59
+ # If we have no arguments
60
+ if len(argv) == 1:
61
+
62
+ # Run the REST server
63
+ return rest.run()
64
+
65
+ # Else, if we have one argument
66
+ elif len(argv) == 2:
67
+
68
+ # If we are installing
69
+ if argv[1] == 'install':
70
+ conf['module'] = Path(__file__).parent.resolve()
71
+ return install.install(conf)
72
+
73
+ # Else, if we are explicitly stating the rest service
74
+ elif argv[1] == 'rest':
75
+ return rest.run()
76
+
77
+ # Else, if we are upgrading
78
+ elif argv[1] == 'upgrade':
79
+ return upgrade(
80
+ conf['data'],
81
+ Path(__file__).parent.resolve()
82
+ )
83
+
84
+ # Else, arguments are wrong, print and return an error
85
+ print('Invalid arguments', file = stderr)
86
+ return 1
87
+
88
+ # Only run if called directly
89
+ if __name__ == '__main__':
90
+ exit(cli())
@@ -0,0 +1,64 @@
1
+ {
2
+ "__sql__": {
3
+ "auto_primary": "UUID()",
4
+ "changes": ["user"],
5
+ "create": [
6
+ "_created", "_updated", "name"
7
+ ],
8
+ "db": "brain",
9
+ "host": "brain",
10
+ "indexes": {
11
+ "name": {"unique": null}
12
+ },
13
+ "primary": "_id",
14
+ "table": "brain_db_host",
15
+ "charset": "utf8mb4",
16
+ "collate": "utf8mb4_unicode_ci"
17
+ },
18
+
19
+ "__name__": "Brain_DBHost",
20
+
21
+ "_id": {
22
+ "__type__":"uuid",
23
+ "__optional__": true
24
+ },
25
+
26
+ "_created": {
27
+ "__type__":"timestamp",
28
+ "__optional__": true,
29
+ "__sql__": {
30
+ "opts": "default CURRENT_TIMESTAMP"
31
+ }
32
+ },
33
+
34
+ "_updated": {
35
+ "__type__":"timestamp",
36
+ "__optional__": true,
37
+ "__sql__": {
38
+ "opts": "default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP"
39
+ }
40
+ },
41
+
42
+ "name": {
43
+ "__type__": "string",
44
+ "__maximum__": 64
45
+ },
46
+
47
+ "details": {
48
+ "host": {"__type__": "string"},
49
+ "port": {"__type__": "uint"},
50
+ "user": {"__type__": "string"},
51
+ "passwd": {"__type__": "string"},
52
+ "charset": {"__type__": "string", "__optional__": true},
53
+ "__sql__": {
54
+ "json": true
55
+ }
56
+ },
57
+
58
+ "full": {
59
+ "__type__": "bool",
60
+ "__sql__": {
61
+ "opt": "default 0"
62
+ }
63
+ }
64
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "__sql__": {
3
+ "auto_primary": "UUID()",
4
+ "changes": ["user"],
5
+ "create": [
6
+ "_created", "_updated", "name"
7
+ ],
8
+ "db": "brain",
9
+ "host": "brain",
10
+ "indexes": {
11
+ "name": {"unique": null}
12
+ },
13
+ "primary": "_id",
14
+ "table": "brain_group",
15
+ "charset": "utf8mb4",
16
+ "collate": "utf8mb4_unicode_ci"
17
+ },
18
+
19
+ "__name__": "Brain_Group",
20
+
21
+ "_id": {
22
+ "__type__":"uuid",
23
+ "__optional__": true,
24
+ "__ui__": {
25
+ "title": "Unique ID"
26
+ }
27
+ },
28
+
29
+ "_created": {
30
+ "__type__":"timestamp",
31
+ "__optional__": true,
32
+ "__sql__": {
33
+ "opts": "default CURRENT_TIMESTAMP"
34
+ }
35
+ },
36
+
37
+ "_updated": {
38
+ "__type__":"timestamp",
39
+ "__optional__": true,
40
+ "__sql__": {
41
+ "opts": "default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP"
42
+ }
43
+ },
44
+
45
+ "name": {
46
+ "__type__": "string",
47
+ "__maximum__": 64
48
+ }
49
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "__sql__": {
3
+ "auto_primary": false,
4
+ "create": ["_created", "_updated", "user", "type"],
5
+ "db": "brain",
6
+ "host": "brain",
7
+ "indexes": {
8
+ "user_type": {"unique": ["user", "type"]}
9
+ },
10
+ "table": "brain_key",
11
+ "charset": "utf8mb4",
12
+ "collate": "utf8mb4_bin"
13
+ },
14
+
15
+ "__name__": "Key",
16
+
17
+ "_id": {
18
+ "__type__": "string",
19
+ "__regex__": "^[0-9a-f]{32}$",
20
+ "__sql__": {
21
+ "type": "char(32)"
22
+ }
23
+ },
24
+
25
+ "_created": {
26
+ "__type__": "timestamp",
27
+ "__optional__": true,
28
+ "__sql__": {
29
+ "opts": "default CURRENT_TIMESTAMP"
30
+ }
31
+ },
32
+
33
+ "_updated": {
34
+ "__type__": "timestamp",
35
+ "__optional__": true,
36
+ "__sql__": {
37
+ "opts": "default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP"
38
+ }
39
+ },
40
+
41
+ "user": {
42
+ "__type__": "uuid"
43
+ },
44
+
45
+ "type": {
46
+ "__type__": "string",
47
+ "__options__": ["forgot", "setup", "verify"]
48
+ }
49
+ }
@@ -0,0 +1,67 @@
1
+ {
2
+ "__sql__": {
3
+ "auto_primary": "UUID()",
4
+ "changes": ["user"],
5
+ "create": ["_created", "_updated", "user", "portal", "rights"],
6
+ "db": "brain",
7
+ "host": "brain",
8
+ "indexes": {
9
+ "u_user_portal": ["user", "portal"]
10
+ },
11
+ "primary": "_id",
12
+ "table": "brain_permissions",
13
+ "charset": "utf8mb4",
14
+ "collate": "utf8mb4_bin"
15
+ },
16
+
17
+ "__name__": "Brain_Permissions",
18
+
19
+ "_id": {
20
+ "__type__": "uuid",
21
+ "__optional__": true
22
+ },
23
+
24
+ "_created": {
25
+ "__type__":"timestamp",
26
+ "__optional__": true,
27
+ "__sql__": {
28
+ "opts": "default CURRENT_TIMESTAMP"
29
+ }
30
+ },
31
+
32
+ "_updated": {
33
+ "__type__":"timestamp",
34
+ "__optional__": true,
35
+ "__sql__": {
36
+ "opts": "default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP"
37
+ }
38
+ },
39
+
40
+ "user": {
41
+ "__type__":"uuid"
42
+ },
43
+
44
+ "portal": {
45
+ "__type__": "string",
46
+ "__maximum__": 16,
47
+ "__sql__": {
48
+ "type": "char(16)"
49
+ }
50
+ },
51
+
52
+ "rights": {
53
+ "__hash__": {
54
+ "__type__": "string",
55
+ "__regex__": "[a-z_]+"
56
+ },
57
+ "__type__": {
58
+ "__hash__": "uuid",
59
+ "__type__": "uint",
60
+ "__minimum__": 1,
61
+ "__maximum__": 15
62
+ },
63
+ "__sql__": {
64
+ "json": true
65
+ }
66
+ }
67
+ }
@@ -0,0 +1,151 @@
1
+ {
2
+ "__sql__": {
3
+ "auto_primary": "UUID()",
4
+ "changes": ["user"],
5
+ "create": [
6
+ "_created", "_updated", "email", "passwd", "locale",
7
+ "first_name", "last_name", "title", "suffix",
8
+ "phone_number", "phone_ext", "verified"
9
+ ],
10
+ "db": "brain",
11
+ "host": "brain",
12
+ "indexes": {
13
+ "email": {"unique": null}
14
+ },
15
+ "primary": "_id",
16
+ "table": "brain_user",
17
+ "charset": "utf8mb4",
18
+ "collate": "utf8mb4_unicode_ci"
19
+ },
20
+
21
+ "__ui__": {
22
+ "create": ["email", "title", "first_name", "last_name",
23
+ "suffix", "phone_number", "phone_ext"],
24
+ "results": ["_id", "email", "title", "first_name", "last_name", "suffix"],
25
+ "search": ["_id", "email", "first_name", "last_name", "phone_number"],
26
+ "update": ["title", "first_name", "last_name", "suffix", "phone_number",
27
+ "phone_ext"]
28
+ },
29
+
30
+ "__name__": "Brain_User",
31
+
32
+ "_id": {
33
+ "__type__":"uuid",
34
+ "__optional__": true,
35
+ "__ui__": {
36
+ "title": "Unique ID"
37
+ }
38
+ },
39
+
40
+ "_created": {
41
+ "__type__":"timestamp",
42
+ "__optional__": true,
43
+ "__sql__": {
44
+ "opts": "default CURRENT_TIMESTAMP"
45
+ }
46
+ },
47
+
48
+ "_updated": {
49
+ "__type__":"timestamp",
50
+ "__optional__": true,
51
+ "__sql__": {
52
+ "opts": "default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP"
53
+ }
54
+ },
55
+
56
+ "email": {
57
+ "__type__":"string",
58
+ "__maximum__": 127,
59
+ "__ui__": {
60
+ "title": "E-Mail Address"
61
+ }
62
+ },
63
+
64
+ "passwd": {
65
+ "__type__":"string",
66
+ "__regex__":"^[0-9a-fA-F]{72}$",
67
+ "__sql__": "char(72)",
68
+ "__ui__": {
69
+ "regex": "^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{8,})",
70
+ "title": "Password",
71
+ "type": "password"
72
+ }
73
+ },
74
+
75
+ "locale": {
76
+ "__type__": "string",
77
+ "__regex__": "^[a-z]{2}-[A-Z]{2}$",
78
+ "__sql__": "char(5)",
79
+ "__ui__": {
80
+ "options": [["en-US", "U.S. English"]],
81
+ "title": "Language",
82
+ "type": "hidden"
83
+ }
84
+ },
85
+
86
+ "first_name": {
87
+ "__type__": "string",
88
+ "__minumum__": 1,
89
+ "__maximum__": 31,
90
+ "__ui__": {
91
+ "title": "Given Name"
92
+ }
93
+ },
94
+
95
+ "last_name": {
96
+ "__type__": "string",
97
+ "__minumum__": 2,
98
+ "__maximum__": 31,
99
+ "__ui__": {
100
+ "title": "Surname"
101
+ }
102
+ },
103
+
104
+ "title": {
105
+ "__type__": "string",
106
+ "__maximum__": 31,
107
+ "__optional__": true,
108
+ "__ui__": {
109
+ "title": "Title (e.g. Dr., Mrs., Miss, Lord, etc)"
110
+ }
111
+ },
112
+
113
+ "suffix": {
114
+ "__type__": "string",
115
+ "__maximum__": 31,
116
+ "__optional__": true,
117
+ "__ui__": {
118
+ "title": "Suffix (e.g. PhD, RN, Esq)"
119
+ }
120
+ },
121
+
122
+ "phone_number": {
123
+ "__type__": "string",
124
+ "__regex__": "^(\\+[\\d \\(\\)-]{10,30}|[\\d \\(\\)-]{10,31})$",
125
+ "__optional__": true,
126
+ "__ui__": {
127
+ "title": "Phone Number",
128
+ "type": "phone_number"
129
+ },
130
+ "__sql__": {
131
+ "type": "varchar(31)"
132
+ }
133
+ },
134
+
135
+ "phone_ext": {
136
+ "__type__": "string",
137
+ "__maximum__": 11,
138
+ "__optional__": true,
139
+ "__ui__": {
140
+ "title": "Extension"
141
+ }
142
+ },
143
+
144
+ "verified": {
145
+ "__type__": "bool",
146
+ "__optional__": true,
147
+ "__sql__": {
148
+ "opts": "default 0"
149
+ }
150
+ }
151
+ }
@@ -0,0 +1,34 @@
1
+ # coding=utf8
2
+ """ Errors
3
+
4
+ Brain error codes
5
+ """
6
+
7
+ __author__ = "Chris Nasr"
8
+ __copyright__ = "Ouroboros Coding Inc"
9
+ __version__ = "1.0.0"
10
+ __email__ = "chris@ouroboroscoding.com"
11
+ __created__ = "2023-01-16"
12
+
13
+ __all__ = ['body', 'SIGNIN_FAILED', 'PASSWORD_STRENGTH', 'BAD_PORTAL']
14
+
15
+ # Ouroboros imports
16
+ from body import errors as body
17
+
18
+ SIGNIN_FAILED = 1200
19
+ """Sign In Failed"""
20
+
21
+ PASSWORD_STRENGTH = 1201
22
+ """Password not strong enough"""
23
+
24
+ BAD_PORTAL = 1202
25
+ """Portal doesn't exist, or the user doesn't have permissions for it"""
26
+
27
+ INTERNAL_KEY = 1203
28
+ """Internal key failed to validate"""
29
+
30
+ BAD_OAUTH = 1204
31
+ """Something failed in the OAuth process"""
32
+
33
+ BAD_CONFIG = 1205
34
+ """Something is missing from the configuration"""
File without changes