FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-gitlab/tools/generate_token.py at master · SVLay/python-gitlab · GitHub
SVLay
python-gitlab
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-gitlab
/
tools
/
generate_token.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
51 lines (39 loc) · 1.52 KB
Breadcrumbs
python-gitlab
/
tools
/
generate_token.py
Copy path
File metadata and controls
executable file
·
51 lines (39 loc) · 1.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
from
six
.
moves
.
urllib
.
parse
import
urljoin
from
requests_html
import
HTMLSession
ENDPOINT
=
"http://localhost:8080"
LOGIN
=
"root"
PASSWORD
=
"5iveL!fe"
class
GitlabSession
(
HTMLSession
):
def
__init__
(
self
,
endpoint
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
endpoint
=
endpoint
self
.
csrf
=
None
def
find_csrf_token
(
self
,
html
):
param
=
html
.
find
(
"meta[name=csrf-param]"
)[
0
].
attrs
[
"content"
]
token
=
html
.
find
(
"meta[name=csrf-token]"
)[
0
].
attrs
[
"content"
]
self
.
csrf
=
{
param
:
token
}
def
obtain_csrf_token
(
self
):
r
=
self
.
get
(
urljoin
(
self
.
endpoint
,
"/"
))
self
.
find_csrf_token
(
r
.
html
)
def
sign_in
(
self
,
login
,
password
):
data
=
{
"user[login]"
:
login
,
"user[password]"
:
password
,
**
self
.
csrf
}
r
=
self
.
post
(
urljoin
(
self
.
endpoint
,
"/users/sign_in"
),
data
=
data
)
self
.
find_csrf_token
(
r
.
html
)
def
obtain_personal_access_token
(
self
,
name
):
data
=
{
"personal_access_token[name]"
:
name
,
"personal_access_token[scopes][]"
: [
"api"
,
"sudo"
],
**
self
.
csrf
,
}
r
=
self
.
post
(
urljoin
(
self
.
endpoint
,
"/profile/personal_access_tokens"
),
data
=
data
)
return
r
.
html
.
find
(
"#created-personal-access-token"
)[
0
].
attrs
[
"value"
]
def
main
():
with
GitlabSession
(
ENDPOINT
)
as
s
:
s
.
obtain_csrf_token
()
s
.
sign_in
(
LOGIN
,
PASSWORD
)
print
(
s
.
obtain_personal_access_token
(
"default"
))
if
__name__
==
"__main__"
:
main
()
Back
|
FazBrowse Home
|
New Git URL