@@ -60,6 +60,9 @@ public class ProjectAccessTokenScript implements Callable<Integer> {
60
60
@ Option (names = { "-c" , "--config" }, description = "configuration file location" )
61
61
String configFile ;
62
62
63
+ @ Option (names = { "-v" , "--verbose" }, description = "log http trafic" )
64
+ Boolean logHttp ;
65
+
63
66
private static enum Action {
64
67
LIST_PROJECT_ACCESS_TOKEN , GET_PROJECT_ACCESS_TOKEN , CREATE_PROJECT_ACCESS_TOKEN , ROTATE_PROJECT_ACCESS_TOKEN , REVOKE_PROJECT_ACCESS_TOKEN
65
68
}
@@ -79,7 +82,7 @@ public Integer call() throws Exception {
79
82
80
83
ensureExists (project , "project" );
81
84
82
- try (GitLabApi gitLabApi = new GitLabApi (gitLabUrl , gitLabAuthValue )) {
85
+ try (GitLabApi gitLabApi = createGitLabApi (gitLabUrl , gitLabAuthValue )) {
83
86
switch (action ) {
84
87
case LIST_PROJECT_ACCESS_TOKEN :
85
88
var tokens = gitLabApi .getProjectApi ()
@@ -93,6 +96,7 @@ public Integer call() throws Exception {
93
96
System .out .println (token );
94
97
break ;
95
98
case CREATE_PROJECT_ACCESS_TOKEN :
99
+ ensureExists (tokenName , "tokenName" );
96
100
var createdToken = gitLabApi .getProjectApi ()
97
101
.createProjectAccessToken (idOrPath (project ), tokenName , scopes , expiresAt , accessLevelValue (accessLevel ));
98
102
System .out .println (createdToken );
@@ -113,6 +117,14 @@ public Integer call() throws Exception {
113
117
return 0 ;
114
118
}
115
119
120
+ private GitLabApi createGitLabApi (String gitLabUrl , String gitLabAuthValue ) {
121
+ if (logHttp != null && logHttp ) {
122
+ return new GitLabApi (gitLabUrl , gitLabAuthValue )
123
+ .withRequestResponseLogging (java .util .logging .Level .INFO );
124
+ }
125
+ return new GitLabApi (gitLabUrl , gitLabAuthValue );
126
+ }
127
+
116
128
private static Long accessLevelValue (AccessLevel value ) {
117
129
if (value == null ) {
118
130
return null ;
0 commit comments