Skip to content

Commit 6272d91

Browse files
authored
Merge pull request #4540 from bruntib/access_tokens
Personal access token
2 parents 0f9d99f + 45bcb7e commit 6272d91

File tree

23 files changed

+590
-95
lines changed

23 files changed

+590
-95
lines changed

docs/web/authentication.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -636,14 +636,24 @@ Personal tokens can be written instead of the user's password in the
636636
usage: CodeChecker cmd token new [-h] [--description DESCRIPTION]
637637
[--url SERVER_URL]
638638
[--verbose {info,debug,debug_analyzer}]
639+
NAME
639640
640641
Creating a new personal access token.
641642
642-
optional arguments:
643+
positional arguments:
644+
NAME A unique name that identifies the access token.
645+
646+
options:
643647
-h, --help show this help message and exit
644648
--description DESCRIPTION
645649
A custom textual description to be shown alongside the
646650
token.
651+
652+
common arguments:
653+
--url SERVER_URL The URL of the server to access, in the format of
654+
'[http[s]://]host:port'. (default: localhost:8001)
655+
--verbose {info,debug_analyzer,debug}
656+
Set verbosity level.
647657
```
648658
</details>
649659
@@ -656,13 +666,22 @@ optional arguments:
656666
```
657667
usage: CodeChecker cmd token list [-h] [--url SERVER_URL]
658668
[-o {plaintext,html,rows,table,csv,json}]
659-
[-e EXPORT_DIR] [-c]
660669
[--verbose {info,debug,debug_analyzer}]
661670
662671
List the available personal access tokens.
663672
664-
optional arguments:
673+
options:
665674
-h, --help show this help message and exit
675+
-o {plaintext,rows,table,csv,json}, --output {plaintext,rows,table,csv,json}
676+
The output format(s) to use in showing the data. Mind
677+
that some output formats are (like 'json') more verbose
678+
than others (like 'plaintext'). (default: plaintext)
679+
680+
common arguments:
681+
--url SERVER_URL The URL of the server to access, in the format of
682+
'[http[s]://]host:port'. (default: localhost:8001)
683+
--verbose {info,debug_analyzer,debug}
684+
Set verbosity level.
666685
```
667686
</details>
668687
@@ -675,11 +694,20 @@ optional arguments:
675694
```
676695
usage: CodeChecker cmd token del [-h] [--url SERVER_URL]
677696
[--verbose {info,debug,debug_analyzer}]
678-
TOKEN
697+
NAME
679698
680699
Removes the specified access token.
681700
682701
positional arguments:
683-
TOKEN Personal access token which will be deleted.
702+
NAME Name of the personal access token that will be deleted.
703+
704+
options:
705+
-h, --help show this help message and exit
706+
707+
common arguments:
708+
--url SERVER_URL The URL of the server to access, in the format of
709+
'[http[s]://]host:port'. (default: localhost:8001)
710+
--verbose {info,debug_analyzer,debug}
711+
Set verbosity level.
684712
```
685713
</details>

web/api/authentication.thrift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ struct SessionTokenData {
3333
}
3434
typedef list<SessionTokenData> SessionTokenDataList
3535

36+
struct PersonalAccessToken {
37+
1: string token,
38+
2: string name,
39+
3: string description,
40+
4: string lastAccess,
41+
5: string expiration,
42+
}
43+
typedef list<PersonalAccessToken> PersonalAccessTokenList
44+
3645
struct Permissions {
3746
1: map<string, list<string>> user,
3847
2: map<string, list<string>> group,
@@ -154,4 +163,14 @@ service codeCheckerAuthentication {
154163
bool removeToken(1: string token)
155164
throws (1: codechecker_api_shared.RequestFailed requestError)
156165

166+
PersonalAccessTokenList getPersonalAccessTokens()
167+
throws (1: codechecker_api_shared.RequestFailed requestError)
168+
169+
PersonalAccessToken newPersonalAccessToken(
170+
1: string name,
171+
2: optional string description)
172+
throws (1: codechecker_api_shared.RequestFailed requestError)
173+
174+
bool removePersonalAccessToken(1: string name)
175+
throws (1: codechecker_api_shared.RequestFailed requestError)
157176
}
Binary file not shown.
Binary file not shown.

web/api/js/codechecker-api-node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codechecker-api",
3-
"version": "6.62.0",
3+
"version": "6.63.0",
44
"description": "Generated node.js compatible API stubs for CodeChecker server.",
55
"main": "lib",
66
"homepage": "https://github.com/Ericsson/codechecker",
Binary file not shown.

web/api/py/codechecker_api/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
with open('README.md', encoding='utf-8', errors="ignore") as f:
99
long_description = f.read()
1010

11-
api_version = '6.62.0'
11+
api_version = '6.63.0'
1212

1313
setup(
1414
name='codechecker_api',
Binary file not shown.

web/api/py/codechecker_api_shared/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
with open('README.md', encoding='utf-8', errors="ignore") as f:
99
long_description = f.read()
1010

11-
api_version = '6.62.0'
11+
api_version = '6.63.0'
1212

1313
setup(
1414
name='codechecker_api_shared',

web/client/codechecker_client/cli/cmd.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,11 @@ def __register_token(parser):
12331233
"""
12341234

12351235
def __register_new(parser):
1236+
parser.add_argument("name",
1237+
type=str,
1238+
metavar='NAME',
1239+
help="A unique name that identifies the access "
1240+
"token.")
12361241
parser.add_argument("--description",
12371242
type=str,
12381243
metavar='DESCRIPTION',
@@ -1245,12 +1250,12 @@ def __register_del(parser):
12451250
"""
12461251
Add argparse subcommand parser for the "del token" action.
12471252
"""
1248-
parser.add_argument("token",
1253+
parser.add_argument("name",
12491254
type=str,
1250-
metavar='TOKEN',
1255+
metavar='NAME',
12511256
default=argparse.SUPPRESS,
1252-
help="Personal access token which will be "
1253-
"deleted.")
1257+
help="Name of the personal access token that will "
1258+
"be deleted.")
12541259

12551260
subcommands = parser.add_subparsers(title='available actions')
12561261

web/client/codechecker_client/client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,17 @@ def login_user(protocol, host, port, username, login=False):
7777
If login is False the user will be logged out.
7878
"""
7979
session = UserCredentials()
80-
auth_client = ThriftAuthHelper(protocol, host, port,
81-
'/v' + CLIENT_API + '/Authentication')
8280

8381
if not login:
82+
auth_client = init_auth_client(protocol, host, port)
8483
logout_done = auth_client.destroySession()
8584
if logout_done:
8685
session.save_token(host, port, None, True)
8786
LOG.info("Successfully logged out.")
8887
return
8988

89+
auth_client = setup_auth_client(protocol, host, port)
90+
9091
try:
9192
handshake = auth_client.getAuthParameters()
9293

web/client/codechecker_client/helpers/authentication.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,15 @@ def removeToken(self, token):
9595
@thrift_client_call
9696
def getTokens(self):
9797
pass
98+
99+
@thrift_client_call
100+
def newPersonalAccessToken(self, name, description):
101+
pass
102+
103+
@thrift_client_call
104+
def removePersonalAccessToken(self, name):
105+
pass
106+
107+
@thrift_client_call
108+
def getPersonalAccessTokens(self):
109+
pass

web/client/codechecker_client/token_client.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ def handle_add_token(args):
3838
client = init_auth_client(protocol, host, port)
3939

4040
description = args.description if 'description' in args else None
41-
session = client.newToken(description)
41+
personal_access_token = \
42+
client.newPersonalAccessToken(args.name, description)
4243

4344
print("The following access token has been generated for your account: " +
44-
session.token)
45+
personal_access_token.token)
4546

4647

4748
def handle_list_tokens(args):
@@ -58,15 +59,15 @@ def handle_list_tokens(args):
5859

5960
protocol, host, port = split_server_url(args.server_url)
6061
client = init_auth_client(protocol, host, port)
61-
tokens = client.getTokens()
62+
tokens = client.getPersonalAccessTokens()
6263

6364
if args.output_format == 'json':
6465
print(CmdLineOutputEncoder().encode(tokens))
6566
else: # plaintext, csv
66-
header = ['Token', 'Description', 'Last access']
67+
header = ['Name', 'Description', 'Last access']
6768
rows = []
6869
for res in tokens:
69-
rows.append((res.token,
70+
rows.append((res.name,
7071
res.description if res.description else '',
7172
res.lastAccess))
7273

@@ -82,14 +83,14 @@ def handle_del_token(args):
8283
protocol, host, port = split_server_url(args.server_url)
8384
client = init_auth_client(protocol, host, port)
8485

85-
token = args.token
86+
name = args.name
8687
try:
87-
success = client.removeToken(token)
88+
success = client.removePersonalAccessToken(name)
8889

8990
if success:
90-
print("'" + token + "' has been successfully removed.")
91+
print(f"'{name}' has been successfully removed.")
9192
else:
92-
print("Error: '" + token + "' can not be removed.")
93+
print(f"Error: '{name}' can not be removed.")
9394
except Exception as ex:
9495
LOG.error("Failed to remove the token!")
9596
LOG.error(ex)

web/codechecker_web/shared/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# The newest supported minor version (value) for each supported major version
2121
# (key) in this particular build.
2222
SUPPORTED_VERSIONS = {
23-
6: 62
23+
6: 63
2424
}
2525

2626
# Used by the client to automatically identify the latest major and minor

0 commit comments

Comments
 (0)