Skip to content

Commit 1ebcf49

Browse files
author
Glenn Snyder
committed
adding example showing how to set or update user session timeout value
1 parent 731cc06 commit 1ebcf49

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

examples/set_user_session_timeout.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import json
5+
import logging
6+
import sys
7+
8+
9+
from blackduck.HubRestApi import HubInstance
10+
11+
12+
def check_minimum(value):
13+
minimum = 1800
14+
ivalue = int(value)
15+
if ivalue < minimum:
16+
raise argparse.ArgumentTypeError("Timeout value must be greater than or equal to {} (seconds). You gave {}".format(
17+
minimum, ivalue))
18+
return ivalue
19+
20+
parser = argparse.ArgumentParser("Set the user session timeout - applies to both local and SSO authenticated sessions")
21+
parser.add_argument("timeout", type=check_minimum, help="The (integer) timeout value in seconds")
22+
args = parser.parse_args()
23+
24+
logging.basicConfig(format='%(asctime)s%(levelname)s:%(message)s', stream=sys.stderr, level=logging.DEBUG)
25+
logging.getLogger("requests").setLevel(logging.WARNING)
26+
logging.getLogger("urllib3").setLevel(logging.WARNING)
27+
28+
hub = HubInstance()
29+
30+
url = hub.get_apibase() + "/system-oauth-client"
31+
32+
new_timeout = {
33+
"accessTokenValiditySeconds": args.timeout
34+
}
35+
36+
response = hub.execute_put(url, data=new_timeout)
37+
print("Result code for attempting to set session timeout to {} seconds was: {}".format(
38+
args.timeout, response.status_code))

0 commit comments

Comments
 (0)