scylla-cqlsh 6.0.29__cp310-cp310-win_amd64.whl
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.
- copyutil.cp310-win_amd64.pyd +0 -0
- cqlsh/__init__.py +1 -0
- cqlsh/__main__.py +11 -0
- cqlsh/cqlsh.py +2736 -0
- cqlshlib/__init__.py +90 -0
- cqlshlib/_version.py +34 -0
- cqlshlib/authproviderhandling.py +176 -0
- cqlshlib/copyutil.py +2762 -0
- cqlshlib/cql3handling.py +1670 -0
- cqlshlib/cqlhandling.py +333 -0
- cqlshlib/cqlshhandling.py +314 -0
- cqlshlib/displaying.py +128 -0
- cqlshlib/formatting.py +601 -0
- cqlshlib/helptopics.py +190 -0
- cqlshlib/pylexotron.py +562 -0
- cqlshlib/saferscanner.py +91 -0
- cqlshlib/sslhandling.py +109 -0
- cqlshlib/tracing.py +90 -0
- cqlshlib/util.py +183 -0
- cqlshlib/wcwidth.py +379 -0
- scylla_cqlsh-6.0.29.dist-info/METADATA +108 -0
- scylla_cqlsh-6.0.29.dist-info/RECORD +26 -0
- scylla_cqlsh-6.0.29.dist-info/WHEEL +5 -0
- scylla_cqlsh-6.0.29.dist-info/entry_points.txt +2 -0
- scylla_cqlsh-6.0.29.dist-info/licenses/LICENSE.txt +204 -0
- scylla_cqlsh-6.0.29.dist-info/top_level.txt +3 -0
cqlshlib/__init__.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
|
3
|
+
# distributed with this work for additional information
|
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
|
6
|
+
# "License"); you may not use this file except in compliance
|
|
7
|
+
# with the License. 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.
|
|
16
|
+
|
|
17
|
+
from cassandra.metadata import RegisteredTableExtension
|
|
18
|
+
import io
|
|
19
|
+
import struct
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# Add a handler for schema extensions to at least print
|
|
23
|
+
# the info when doing "desc <table>".
|
|
24
|
+
#
|
|
25
|
+
# The end result will not be cut-and-paste usable; we'd need to modify the
|
|
26
|
+
# driver for this. But it is something.
|
|
27
|
+
class MapExtensionReader:
|
|
28
|
+
def __init__(self, ext_blob):
|
|
29
|
+
self.bytes = io.BytesIO(ext_blob)
|
|
30
|
+
|
|
31
|
+
def read_string(self):
|
|
32
|
+
# strings are little endian 32-bit len bytes
|
|
33
|
+
utf_length = struct.unpack('<I', self.bytes.read(4))[0]
|
|
34
|
+
return self.bytes.read(utf_length).decode()
|
|
35
|
+
|
|
36
|
+
def read_pair(self):
|
|
37
|
+
# each map::value_type is written as <string><string>
|
|
38
|
+
key = self.read_string()
|
|
39
|
+
val = self.read_string()
|
|
40
|
+
return key, val
|
|
41
|
+
|
|
42
|
+
def read_map(self):
|
|
43
|
+
# num elements
|
|
44
|
+
len = struct.unpack('<I', self.bytes.read(4))[0]
|
|
45
|
+
res = {}
|
|
46
|
+
# x value_type pairs
|
|
47
|
+
for x in range(0, len):
|
|
48
|
+
p = self.read_pair()
|
|
49
|
+
res[p[0]] = p[1]
|
|
50
|
+
return res
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# Extension for CDC info
|
|
54
|
+
class CdcExt(RegisteredTableExtension):
|
|
55
|
+
name = 'cdc'
|
|
56
|
+
|
|
57
|
+
@classmethod
|
|
58
|
+
def after_table_cql(cls, table_meta, ext_key, ext_blob):
|
|
59
|
+
# For cdc options, the blob is actually
|
|
60
|
+
# a serialized unorderd_map<string, string>.
|
|
61
|
+
mer = MapExtensionReader(ext_blob)
|
|
62
|
+
return "%s = %s" % (ext_key, mer.read_map())
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
# Extension for alternator's `scylla_tags`
|
|
66
|
+
class ScyllaTagsExt(RegisteredTableExtension):
|
|
67
|
+
name = 'scylla_tags'
|
|
68
|
+
|
|
69
|
+
@classmethod
|
|
70
|
+
def after_table_cql(cls, table_meta, ext_key, ext_blob):
|
|
71
|
+
# For scylla_tags, the blob is actually
|
|
72
|
+
# a serialized unorderd_map<string, string>.
|
|
73
|
+
mer = MapExtensionReader(ext_blob)
|
|
74
|
+
return "%s = %s" % (ext_key, mer.read_map())
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# Add a handler for scylla_encryption_options extension to at least print
|
|
78
|
+
# the info when doing "desc <table>".
|
|
79
|
+
#
|
|
80
|
+
# The end result will not be cut-and-paste usable; we'd need to modify the
|
|
81
|
+
# driver for this. But it is something.
|
|
82
|
+
class Encr(RegisteredTableExtension):
|
|
83
|
+
name = 'scylla_encryption_options'
|
|
84
|
+
|
|
85
|
+
@classmethod
|
|
86
|
+
def after_table_cql(cls, table_meta, ext_key, ext_blob):
|
|
87
|
+
# For scylla_encryption_options, the blob is actually
|
|
88
|
+
# a serialized unorderd_map<string, string>.
|
|
89
|
+
mer = MapExtensionReader(ext_blob)
|
|
90
|
+
return "%s = %s" % (ext_key, mer.read_map())
|
cqlshlib/_version.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# file generated by setuptools-scm
|
|
2
|
+
# don't change, don't track in version control
|
|
3
|
+
|
|
4
|
+
__all__ = [
|
|
5
|
+
"__version__",
|
|
6
|
+
"__version_tuple__",
|
|
7
|
+
"version",
|
|
8
|
+
"version_tuple",
|
|
9
|
+
"__commit_id__",
|
|
10
|
+
"commit_id",
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
TYPE_CHECKING = False
|
|
14
|
+
if TYPE_CHECKING:
|
|
15
|
+
from typing import Tuple
|
|
16
|
+
from typing import Union
|
|
17
|
+
|
|
18
|
+
VERSION_TUPLE = Tuple[Union[int, str], ...]
|
|
19
|
+
COMMIT_ID = Union[str, None]
|
|
20
|
+
else:
|
|
21
|
+
VERSION_TUPLE = object
|
|
22
|
+
COMMIT_ID = object
|
|
23
|
+
|
|
24
|
+
version: str
|
|
25
|
+
__version__: str
|
|
26
|
+
__version_tuple__: VERSION_TUPLE
|
|
27
|
+
version_tuple: VERSION_TUPLE
|
|
28
|
+
commit_id: COMMIT_ID
|
|
29
|
+
__commit_id__: COMMIT_ID
|
|
30
|
+
|
|
31
|
+
__version__ = version = '6.0.29'
|
|
32
|
+
__version_tuple__ = version_tuple = (6, 0, 29)
|
|
33
|
+
|
|
34
|
+
__commit_id__ = commit_id = 'g22401228d'
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
|
3
|
+
# distributed with this work for additional information
|
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
|
6
|
+
# "License"); you may not use this file except in compliance
|
|
7
|
+
# with the License. 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.
|
|
16
|
+
"""
|
|
17
|
+
Handles loading of AuthProvider for CQLSH authentication.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import configparser
|
|
21
|
+
import sys
|
|
22
|
+
from importlib import import_module
|
|
23
|
+
from cqlshlib.util import is_file_secure
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _warn_for_plain_text_security(config_file, provider_settings):
|
|
27
|
+
"""
|
|
28
|
+
Call when using PlainTextAuthProvider
|
|
29
|
+
check to see if password appears in the basic provider settings
|
|
30
|
+
as this is a security risk
|
|
31
|
+
|
|
32
|
+
Will write errors to stderr
|
|
33
|
+
"""
|
|
34
|
+
if 'password' in provider_settings:
|
|
35
|
+
if not is_file_secure(config_file):
|
|
36
|
+
print("""\nWarning: Password is found in an insecure cqlshrc file.
|
|
37
|
+
The file is owned or readable by other users on the system.""",
|
|
38
|
+
end='',
|
|
39
|
+
file=sys.stderr)
|
|
40
|
+
print("""\nNotice: Credentials in the cqlshrc file is deprecated and
|
|
41
|
+
will be ignored in the future.\n
|
|
42
|
+
Please use a credentials file to
|
|
43
|
+
specify the username and password.\n""",
|
|
44
|
+
file=sys.stderr)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def load_auth_provider(config_file=None, cred_file=None, username=None, password=None):
|
|
48
|
+
"""
|
|
49
|
+
Function which loads an auth provider from available config.
|
|
50
|
+
|
|
51
|
+
Params:
|
|
52
|
+
* config_file ..: path to cqlsh config file (usually ~/.cassandra/cqlshrc).
|
|
53
|
+
* cred_file ....: path to cqlsh credentials file (default is ~/.cassandra/credentials).
|
|
54
|
+
* username .....: override used to return PlainTextAuthProvider according to legacy case
|
|
55
|
+
* password .....: override used to return PlainTextAuthProvider according to legacy case
|
|
56
|
+
|
|
57
|
+
Will attempt to load an auth provider from available config file, using what's found in
|
|
58
|
+
credentials file as an override.
|
|
59
|
+
|
|
60
|
+
Config file is expected to list module name /class in the *auth_provider*
|
|
61
|
+
section for dynamic loading (which is to be of type auth_provider)
|
|
62
|
+
|
|
63
|
+
Additional params passed to the constructor of class should be specified
|
|
64
|
+
in the *auth_provider* section and can be freely named to match
|
|
65
|
+
auth provider's expectation.
|
|
66
|
+
|
|
67
|
+
If passed username and password these will be overridden and passed to auth provider
|
|
68
|
+
|
|
69
|
+
None is returned if no possible auth provider is found, and no username/password can be
|
|
70
|
+
returned. If a username is found, system will assume that PlainTextAuthProvider was
|
|
71
|
+
specified
|
|
72
|
+
|
|
73
|
+
EXAMPLE CQLSHRC:
|
|
74
|
+
# .. inside cqlshrc file
|
|
75
|
+
|
|
76
|
+
[auth_provider]
|
|
77
|
+
module = cassandra.auth
|
|
78
|
+
classname = PlainTextAuthProvider
|
|
79
|
+
username = user1
|
|
80
|
+
password = password1
|
|
81
|
+
|
|
82
|
+
if credentials file is specified put relevant properties under the class name
|
|
83
|
+
EXAMPLE
|
|
84
|
+
# ... inside credentials file for above example
|
|
85
|
+
[PlainTextAuthProvider]
|
|
86
|
+
password = password2
|
|
87
|
+
|
|
88
|
+
Credential attributes will override found in the cqlshrc.
|
|
89
|
+
in the above example, PlainTextAuthProvider would be used with a password of 'password2',
|
|
90
|
+
and username of 'user1'
|
|
91
|
+
"""
|
|
92
|
+
|
|
93
|
+
def get_settings_from_config(section_name,
|
|
94
|
+
conf_file,
|
|
95
|
+
interpolation=configparser.BasicInterpolation()):
|
|
96
|
+
"""
|
|
97
|
+
Returns dict from section_name, and ini based conf_file
|
|
98
|
+
|
|
99
|
+
* section_name ..: Section to read map of properties from (ex: [auth_provider])
|
|
100
|
+
* conf_file .....: Ini based config file to read. Will return empty dict if None.
|
|
101
|
+
* interpolation .: Interpolation to use.
|
|
102
|
+
|
|
103
|
+
If section is not found, or conf_file is None, function will return an empty dictionary.
|
|
104
|
+
"""
|
|
105
|
+
conf = configparser.ConfigParser(interpolation=interpolation)
|
|
106
|
+
if conf_file is None:
|
|
107
|
+
return {}
|
|
108
|
+
|
|
109
|
+
conf.read(conf_file)
|
|
110
|
+
if section_name in conf.sections():
|
|
111
|
+
return dict(conf.items(section_name))
|
|
112
|
+
return {}
|
|
113
|
+
|
|
114
|
+
def get_cred_file_settings(classname, creds_file):
|
|
115
|
+
# Since this is the credentials file we may be encountering raw strings
|
|
116
|
+
# as these are what passwords, or security tokens may inadvertently fall into
|
|
117
|
+
# we don't want interpolation to mess with them.
|
|
118
|
+
return get_settings_from_config(
|
|
119
|
+
section_name=classname,
|
|
120
|
+
conf_file=creds_file,
|
|
121
|
+
interpolation=None)
|
|
122
|
+
|
|
123
|
+
def get_auth_provider_settings(conf_file):
|
|
124
|
+
return get_settings_from_config(
|
|
125
|
+
section_name='auth_provider',
|
|
126
|
+
conf_file=conf_file)
|
|
127
|
+
|
|
128
|
+
def get_legacy_settings(legacy_username, legacy_password):
|
|
129
|
+
result = {}
|
|
130
|
+
if legacy_username is not None:
|
|
131
|
+
result['username'] = legacy_username
|
|
132
|
+
if legacy_password is not None:
|
|
133
|
+
result['password'] = legacy_password
|
|
134
|
+
return result
|
|
135
|
+
|
|
136
|
+
provider_settings = get_auth_provider_settings(config_file)
|
|
137
|
+
|
|
138
|
+
module_name = provider_settings.pop('module', None)
|
|
139
|
+
class_name = provider_settings.pop('classname', None)
|
|
140
|
+
|
|
141
|
+
if module_name is None and class_name is None:
|
|
142
|
+
# not specified, default to plaintext auth provider
|
|
143
|
+
module_name = 'cassandra.auth'
|
|
144
|
+
class_name = 'PlainTextAuthProvider'
|
|
145
|
+
elif module_name is None or class_name is None:
|
|
146
|
+
# then this was PARTIALLY specified.
|
|
147
|
+
return None
|
|
148
|
+
|
|
149
|
+
credential_settings = get_cred_file_settings(class_name, cred_file)
|
|
150
|
+
|
|
151
|
+
if module_name == 'cassandra.auth' and class_name == 'PlainTextAuthProvider':
|
|
152
|
+
# merge credential settings as overrides on top of provider settings.
|
|
153
|
+
|
|
154
|
+
# we need to ensure that password property gets "set" in all cases.
|
|
155
|
+
# this is to support the ability to give the user a prompt in other parts
|
|
156
|
+
# of the code.
|
|
157
|
+
_warn_for_plain_text_security(config_file, provider_settings)
|
|
158
|
+
ctor_args = {'password': None,
|
|
159
|
+
**provider_settings,
|
|
160
|
+
**credential_settings,
|
|
161
|
+
**get_legacy_settings(username, password)}
|
|
162
|
+
# if no username, we can't create PlainTextAuthProvider
|
|
163
|
+
if 'username' not in ctor_args:
|
|
164
|
+
return None
|
|
165
|
+
else:
|
|
166
|
+
# merge credential settings as overrides on top of provider settings.
|
|
167
|
+
ctor_args = {**provider_settings,
|
|
168
|
+
**credential_settings,
|
|
169
|
+
**get_legacy_settings(username, password)}
|
|
170
|
+
|
|
171
|
+
# Load class definitions
|
|
172
|
+
module = import_module(module_name)
|
|
173
|
+
auth_provider_klass = getattr(module, class_name)
|
|
174
|
+
|
|
175
|
+
# instantiate the class
|
|
176
|
+
return auth_provider_klass(**ctor_args)
|