Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
java-gitlab-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
沈俊林
java-gitlab-api
Commits
2243612f
Commit
2243612f
authored
Sep 09, 2015
by
Tim Olshansky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #70 from ahaeber/support-oauth-access_token
Support OAuth access_token
parents
ad3ec370
ef0a0d41
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
4 deletions
+28
-4
GitlabAPI.java
src/main/java/org/gitlab/api/GitlabAPI.java
+10
-4
TokenType.java
src/main/java/org/gitlab/api/TokenType.java
+17
-0
GitlabHTTPRequestorTest.java
...est/java/org/gitlab/api/http/GitlabHTTPRequestorTest.java
+1
-0
No files found.
src/main/java/org/gitlab/api/GitlabAPI.java
View file @
2243612f
...
@@ -30,22 +30,28 @@ public class GitlabAPI {
...
@@ -30,22 +30,28 @@ public class GitlabAPI {
private
final
String
hostUrl
;
private
final
String
hostUrl
;
private
final
String
apiToken
;
private
final
String
apiToken
;
private
final
TokenType
tokenType
;
private
boolean
ignoreCertificateErrors
=
false
;
private
boolean
ignoreCertificateErrors
=
false
;
private
GitlabAPI
(
String
hostUrl
,
String
apiToken
)
{
private
GitlabAPI
(
String
hostUrl
,
String
apiToken
,
TokenType
tokenType
)
{
this
.
hostUrl
=
hostUrl
.
endsWith
(
"/"
)
?
hostUrl
.
replaceAll
(
"/$"
,
""
)
:
hostUrl
;
this
.
hostUrl
=
hostUrl
.
endsWith
(
"/"
)
?
hostUrl
.
replaceAll
(
"/$"
,
""
)
:
hostUrl
;
this
.
apiToken
=
apiToken
;
this
.
apiToken
=
apiToken
;
this
.
tokenType
=
tokenType
;
}
}
public
static
GitlabSession
connect
(
String
hostUrl
,
String
username
,
String
password
)
throws
IOException
{
public
static
GitlabSession
connect
(
String
hostUrl
,
String
username
,
String
password
)
throws
IOException
{
String
tailUrl
=
GitlabSession
.
URL
;
String
tailUrl
=
GitlabSession
.
URL
;
GitlabAPI
api
=
connect
(
hostUrl
,
null
);
GitlabAPI
api
=
connect
(
hostUrl
,
null
,
(
TokenType
)
null
);
return
api
.
dispatch
().
with
(
"login"
,
username
).
with
(
"password"
,
password
)
return
api
.
dispatch
().
with
(
"login"
,
username
).
with
(
"password"
,
password
)
.
to
(
tailUrl
,
GitlabSession
.
class
);
.
to
(
tailUrl
,
GitlabSession
.
class
);
}
}
public
static
GitlabAPI
connect
(
String
hostUrl
,
String
apiToken
)
{
public
static
GitlabAPI
connect
(
String
hostUrl
,
String
apiToken
)
{
return
new
GitlabAPI
(
hostUrl
,
apiToken
);
return
new
GitlabAPI
(
hostUrl
,
apiToken
,
TokenType
.
PRIVATE_TOKEN
);
}
public
static
GitlabAPI
connect
(
String
hostUrl
,
String
apiToken
,
TokenType
tokenType
)
{
return
new
GitlabAPI
(
hostUrl
,
apiToken
,
tokenType
);
}
}
public
GitlabAPI
ignoreCertificateErrors
(
boolean
ignoreCertificateErrors
)
{
public
GitlabAPI
ignoreCertificateErrors
(
boolean
ignoreCertificateErrors
)
{
...
@@ -67,7 +73,7 @@ public class GitlabAPI {
...
@@ -67,7 +73,7 @@ public class GitlabAPI {
public
URL
getAPIUrl
(
String
tailAPIUrl
)
throws
IOException
{
public
URL
getAPIUrl
(
String
tailAPIUrl
)
throws
IOException
{
if
(
apiToken
!=
null
)
{
if
(
apiToken
!=
null
)
{
tailAPIUrl
=
tailAPIUrl
+
(
tailAPIUrl
.
indexOf
(
'?'
)
>
0
?
'&'
:
'?'
)
+
"private_token
="
+
apiToken
;
tailAPIUrl
=
tailAPIUrl
+
(
tailAPIUrl
.
indexOf
(
'?'
)
>
0
?
'&'
:
'?'
)
+
tokenType
.
getTokenParamName
()
+
"
="
+
apiToken
;
}
}
if
(!
tailAPIUrl
.
startsWith
(
"/"
))
{
if
(!
tailAPIUrl
.
startsWith
(
"/"
))
{
...
...
src/main/java/org/gitlab/api/TokenType.java
0 → 100644
View file @
2243612f
package
org
.
gitlab
.
api
;
public
enum
TokenType
{
PRIVATE_TOKEN
(
"private_token"
)
,
ACCESS_TOKEN
(
"access_token"
),
;
private
final
String
tokenParamName
;
TokenType
(
String
tokenParamName
)
{
this
.
tokenParamName
=
tokenParamName
;
}
public
String
getTokenParamName
()
{
return
tokenParamName
;
}
}
src/test/java/org/gitlab/api/http/GitlabHTTPRequestorTest.java
View file @
2243612f
package
org
.
gitlab
.
api
.
http
;
package
org
.
gitlab
.
api
.
http
;
import
org.gitlab.api.GitlabAPI
;
import
org.gitlab.api.GitlabAPI
;
import
org.gitlab.api.TokenType
;
import
org.junit.Test
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment