Skip to content

Commit 9e87773

Browse files
author
boonhapus
committed
Merge branch 'redesign'
2 parents fb3dada + 4cb6fed commit 9e87773

File tree

156 files changed

+6517
-2323
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+6517
-2323
lines changed

.gitignore

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ __pycache__/
1414
.Python
1515
build/
1616
develop-eggs/
17-
dist/
1817
downloads/
1918
eggs/
2019
.eggs/
@@ -135,6 +134,9 @@ dmypy.json
135134
# Sublime files
136135
*.sublime-project
137136
*.sublime-workspace
138-
139-
# ignore tsconfig!
140-
tsconfig.*
137+
poetry.lock
138+
pyproject.toml
139+
!.gitdontignore
140+
dist/pkgs/*.whl
141+
dist/pkgs/*.zip
142+
dist/pkgs/*.tar.gz

CONTRIBUTING.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ The process is straight-forward.
2020

2121
1. Fork the CS Tools [git repository][repo-master].
2222
2. Write the code for your feature.
23-
- if you're writing Python code, [set up a virtual environment][repo-hack-venv].
23+
- if you're writing Python code, set up a virtual environment
2424
3. Ensure basic tests work.
25-
4. Create a Pull Request against the [dev][repo-dev] branch of CS Tools.
25+
4. Create a Pull Request against the [dev][repo-dev] branch of CS Tools
2626

2727
## Pull requests are always welcome
2828
Not sure if that typo is worth a pull request? Found a bug and know how to fix it? Do
@@ -33,4 +33,3 @@ it! We will appreciate it. Any significant improvement should be documented as i
3333
[smart-sheet]: https://app.smartsheet.com/sheets/Hfvh6cCfVg8MQrFWmh3R4FgCqQfppXmV3mcW3v31
3434
[repo-master]: https://github.com/thoughtspot/cs_tools/tree/master
3535
[repo-dev]: https://github.com/thoughtspot/cs_tools/tree/dev
36-
[repo-hack-venv]: ./best-practices/virtual-environment.md

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include cs_tools/tools/**/static/*

README.md

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
customer delight.</em></p>
99

1010
CS Tools is an initiative by the CS/PS team to collect, organize, analyze, improve, and
11-
streamline various field engineering tools existing today. This repository is introduced
12-
to form consistency in how we design, build, test, document, and distribute our tools.
13-
In doing so, we are able to streamline our work as well as provide our customers with
14-
the highest level of consultancy that they've come to expect from the team.
11+
streamline various field engineering tools existing today. This repository was
12+
introduced to form consistency in how we design and distribute our tools.
1513

1614
---
1715

@@ -30,40 +28,32 @@ Not sure where to start? Come chat with us in #cstools on [Slack][slack-channel]
3028
## Getting Started
3129

3230
To clone and work this library, you'll want to have [Git][install-git] and
33-
[Python 3.6.1][install-python] or greater installed on your computer. Then, create a
34-
virtual environment and activate it. <sup>([Don't know how to do that][bp-venv]?)</sup>
31+
[Python 3.6.8][install-python] or greater installed on your computer. The shortlist of
32+
instructions are below!
3533

3634
From your command line:
3735
```console
38-
$ pip install git+https://github.com/thoughtspot/cs_tools.git
39-
40-
-or-
41-
42-
$ poetry add git+https://github.com/thoughtspot/cs_tools.git
43-
$ poetry install
36+
$ cd $HOME
37+
$ python3 -m venv .cs_tools-dev
38+
$ source .cs_tools-dev/bin/activate
39+
$ pip install -e git+https://github.com/thoughtspot/cs_tools.git
4440
```
4541

4642
That's it!
4743

48-
P.S. - for extra credit, don't forget to check out our [best practices][bp-main]!
49-
5044
## Our Tools
5145

52-
Note: All tools currently live alongside the ThoughtSpot library as an implementation
53-
detail. Our current structure will aid us in separating off these tools at a later date.
46+
All tools currently live within the ThoughtSpot library as a subpackage. This allows for
47+
ease of distribution and install at a customer site, or along with a customer.
5448

55-
All CS tools are installed as part of the Github CS Tools library. They do not live
56-
under the `/thoughtspot` directory so that they may be shared with clients directly.
57-
All tools do however, depend on the ThoughtSpot library in order to function properly,
58-
please see [Best Practices: Client Install][bp-client-install] for how to set up a
59-
client with the ThoughtSpot library.
49+
Nearly all tools depend on the ThoughtSpot API directly in order to function properly,
50+
please see our [Install Instructions][dist] for how to set up a client with the CT Tools
51+
library and toolset.
6052

6153
For further reading about tool structure, please see the [tools README][tools-readme].
6254

6355
[slack-channel]: https://slack.com/app_redirect?channel=cstools
6456
[install-git]: https://git-scm.com/downloads
6557
[install-python]: https://www.python.org/downloads
66-
[bp-main]: ./best-practices/
67-
[bp-venv]: ./best-practices/virtual-environment.md
68-
[bp-client-install]: ./best-practices/client-install.md
69-
[tools-readme]: ./tools/README.md
58+
[tools-readme]: ./cs_tools/tools/
59+
[dist]: ./dist/README.md

cs_tools/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from ._version import __version__

cs_tools/_version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = '1.0.3'

cs_tools/api.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import logging.config
2+
import datetime as dt
3+
import logging
4+
5+
import httpx
6+
7+
from cs_tools.models.ts_dataservice import TSDataService
8+
from cs_tools.models.dependency import _Dependency
9+
from cs_tools.models.periscope import _Periscope
10+
from cs_tools.models.metadata import Metadata, _Metadata
11+
from cs_tools.models.security import _Security
12+
from cs_tools.models.session import _Session
13+
from cs_tools.models.auth import Session
14+
from cs_tools.models.user import User
15+
from cs_tools.schema.user import User as UserSchema
16+
from cs_tools.errors import CertificateVerifyFailure
17+
from cs_tools.const import APP_DIR
18+
19+
20+
log = logging.getLogger(__name__)
21+
22+
23+
class ThoughtSpot:
24+
"""
25+
"""
26+
def __init__(self, ts_config):
27+
self.config = ts_config
28+
self._setup_logging()
29+
30+
# set up our session
31+
# NOTE: base_url is a valid parameter for httpx.Client
32+
self.http = httpx.Client(timeout=180.0, verify=not ts_config.thoughtspot.disable_ssl)
33+
self.http.headers.update({'X-Requested-By': 'ThoughtSpot'})
34+
35+
# set in __enter__()
36+
self.logged_in_user = None
37+
self.thoughtspot_version = None
38+
39+
# add remote TQL & tsload services
40+
self.ts_dataservice = TSDataService(self)
41+
42+
# add public API endpoints
43+
self.metadata = Metadata(self)
44+
self.auth = Session(self)
45+
self.user = User(self)
46+
47+
# add private API endpoints
48+
self._dependency = _Dependency(self)
49+
self._metadata = _Metadata(self)
50+
self._periscope = _Periscope(self)
51+
self._security = _Security(self)
52+
self._session = _Session(self)
53+
54+
def _clean_logs(self, now):
55+
logs_dir = APP_DIR / 'logs'
56+
logs_dir.mkdir(parents=True, exist_ok=True)
57+
58+
# keep only the last 25 logfiles
59+
lifo = sorted(logs_dir.iterdir(), reverse=True)
60+
61+
for idx, log in enumerate(lifo):
62+
if idx > 25:
63+
log.unlink()
64+
65+
def _setup_logging(self):
66+
logging.getLogger('urllib3').setLevel(logging.ERROR)
67+
68+
now = dt.datetime.now().strftime('%Y-%m-%dT%H_%M_%S')
69+
self._clean_logs(now)
70+
71+
logging.basicConfig(
72+
filename=f'{APP_DIR}/logs/{now}.log',
73+
format='[%(levelname)s - %(asctime)s] '
74+
'[%(name)s - %(module)s.%(funcName)s %(lineno)d] '
75+
'%(message)s',
76+
level=self.config.logging.level
77+
)
78+
79+
@property
80+
def host(self):
81+
"""
82+
URL of ThoughtSpot.
83+
"""
84+
return self.config.thoughtspot.host
85+
86+
def __enter__(self):
87+
try:
88+
r = self.auth.login()
89+
except httpx.ConnectError as e:
90+
if 'CERTIFICATE_VERIFY_FAILED' in str(e):
91+
raise CertificateVerifyFailure()
92+
93+
log.exception('something went wrong.. :(')
94+
raise SystemExit(1)
95+
96+
rj = r.json()
97+
98+
self.logged_in_user = UserSchema(
99+
guid=rj['userGUID'], name=rj['userName'], display_name=rj['userDisplayName'],
100+
email=rj['userEmail'], privileges=rj.get('privileges', ['AUTHORING'])
101+
)
102+
103+
self.thoughtspot_version = rj['releaseVersion']
104+
return self
105+
106+
def __exit__(self, exc_type, exc_value, exc_tb):
107+
self.auth.logout()

0 commit comments

Comments
 (0)