summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--accounts/gkleen@sif/default.nix2
-rw-r--r--accounts/gkleen@sif/ssh-hosts.nix5
-rwxr-xr-xoverlays/worktime/worktime/__main__.py26
3 files changed, 19 insertions, 14 deletions
diff --git a/accounts/gkleen@sif/default.nix b/accounts/gkleen@sif/default.nix
index 05cfc2c8..86a15c44 100644
--- a/accounts/gkleen@sif/default.nix
+++ b/accounts/gkleen@sif/default.nix
@@ -143,7 +143,7 @@ in {
143 # ProxyCommand ${pkgs.socat}/bin/socat - SOCKS4A:127.0.0.1:%h:%p,socksport=8118 143 # ProxyCommand ${pkgs.socat}/bin/socat - SOCKS4A:127.0.0.1:%h:%p,socksport=8118
144 ProxyJump ssh.math.lmu.de 144 ProxyJump ssh.math.lmu.de
145 145
146 Match host *.cipmath.loc !host cip04.cipmath.loc !exec "nc -z -w 1 %h %p &>/dev/null" 146 Match host *.cipmath.loc !host cip04.cipmath.loc,mgmt-cls01.cipmath.loc !exec "nc -z -w 1 %h %p &>/dev/null"
147 ProxyJump cip04 147 ProxyJump cip04
148 148
149 Match host *.ifi.lmu.de,*.math.lmu.de 149 Match host *.ifi.lmu.de,*.math.lmu.de
diff --git a/accounts/gkleen@sif/ssh-hosts.nix b/accounts/gkleen@sif/ssh-hosts.nix
index f141ca8e..ea714910 100644
--- a/accounts/gkleen@sif/ssh-hosts.nix
+++ b/accounts/gkleen@sif/ssh-hosts.nix
@@ -445,6 +445,11 @@
445 { hostname = "cip04.cipmath.loc"; 445 { hostname = "cip04.cipmath.loc";
446 proxyJump = "mathw0h"; 446 proxyJump = "mathw0h";
447 }; 447 };
448 "mgmt-cls01" =
449 { user = "root";
450 hostname = "mgmt-cls01.cipmath.loc";
451 proxyJump = "ssh.math.lmu.de";
452 };
448 "mgmt01" = 453 "mgmt01" =
449 { hostname = "mgmt01.mathinst.loc"; 454 { hostname = "mgmt01.mathinst.loc";
450 proxyJump = "mathw0h"; 455 proxyJump = "mathw0h";
diff --git a/overlays/worktime/worktime/__main__.py b/overlays/worktime/worktime/__main__.py
index 154c1966..dddbb250 100755
--- a/overlays/worktime/worktime/__main__.py
+++ b/overlays/worktime/worktime/__main__.py
@@ -38,7 +38,7 @@ import jsonpickle
38from hashlib import blake2s 38from hashlib import blake2s
39 39
40class TogglAPISection(Enum): 40class TogglAPISection(Enum):
41 TOGGL = '/api/v8' 41 TOGGL = '/api/v9'
42 REPORTS = '/reports/api/v2' 42 REPORTS = '/reports/api/v2'
43 43
44class TogglAPIError(Exception): 44class TogglAPIError(Exception):
@@ -58,7 +58,7 @@ class TogglAPI(object):
58 self._workspace_id = workspace_id 58 self._workspace_id = workspace_id
59 self._client_ids = set(map(int, client_ids.split(','))) if client_ids else None 59 self._client_ids = set(map(int, client_ids.split(','))) if client_ids else None
60 60
61 def _make_url(self, api=TogglAPISection.TOGGL, section=['time_entries', 'current'], params={}): 61 def _make_url(self, api=TogglAPISection.TOGGL, section=['me', 'time_entries', 'current'], params={}):
62 if api is TogglAPISection.REPORTS: 62 if api is TogglAPISection.REPORTS:
63 params.update({'user_agent': 'worktime', 'workspace_id': self._workspace_id}) 63 params.update({'user_agent': 'worktime', 'workspace_id': self._workspace_id})
64 64
@@ -80,7 +80,7 @@ class TogglAPI(object):
80 max_time=10, 80 max_time=10,
81 ) 81 )
82 def _raw_query(self, url, method): 82 def _raw_query(self, url, method):
83 headers = {'content-type': 'application/json'} 83 headers = {'content-type': 'application/json', 'accept': 'application/json'}
84 response = None 84 response = None
85 85
86 if method == 'GET': 86 if method == 'GET':
@@ -176,34 +176,34 @@ class TogglAPI(object):
176 return billable_acc 176 return billable_acc
177 177
178 def get_running_clock(self, now=datetime.now(timezone.utc)): 178 def get_running_clock(self, now=datetime.now(timezone.utc)):
179 url = self._make_url(api = TogglAPISection.TOGGL, section = ['time_entries', 'current']) 179 url = self._make_url(api = TogglAPISection.TOGGL, section = ['me', 'time_entries', 'current'])
180 r = self._query(url = url, method='GET') 180 r = self._query(url = url, method='GET')
181 181
182 if not r or not r.json(): 182 if not r:
183 raise TogglAPIError(r) 183 raise TogglAPIError(None, r)
184 184
185 if not r.json()['data'] or not r.json()['data']['billable']: 185 if not r.json() or not r.json()['billable']:
186 return None 186 return None
187 187
188 if self._client_ids is not None: 188 if self._client_ids is not None:
189 if 'pid' in r.json()['data'] and r.json()['data']['pid']: 189 if 'pid' in r.json() and r.json()['pid']:
190 url = self._make_url(api = TogglAPISection.TOGGL, section = ['projects', str(r.json()['data']['pid'])]) 190 url = self._make_url(api = TogglAPISection.TOGGL, section = ['workspaces', self._workspace_id, 'projects', str(r.json()['pid'])])
191 pr = self._query(url = url, method = 'GET') 191 pr = self._query(url = url, method = 'GET')
192 if not pr or not pr.json(): 192 if not pr or not pr.json():
193 raise TogglAPIError(pr) 193 raise TogglAPIError(pr)
194 194
195 if not pr.json()['data']: 195 if not pr.json():
196 return None 196 return None
197 197
198 if 'cid' in pr.json()['data'] and pr.json()['data']['cid']: 198 if 'cid' in pr.json() and pr.json()['cid']:
199 if pr.json()['data']['cid'] not in self._client_ids: 199 if pr.json()['cid'] not in self._client_ids:
200 return None 200 return None
201 elif 0 not in self._client_ids: 201 elif 0 not in self._client_ids:
202 return None 202 return None
203 elif 0 not in self._client_ids: 203 elif 0 not in self._client_ids:
204 return None 204 return None
205 205
206 start = isoparse(r.json()['data']['start']) 206 start = isoparse(r.json()['start'])
207 207
208 return now - start if start <= now else None 208 return now - start if start <= now else None
209 209