22
33import java .util .List ;
44import java .util .Optional ;
5+ import java .util .stream .Stream ;
56
67import javax .ws .rs .core .Form ;
78import javax .ws .rs .core .GenericType ;
@@ -20,22 +21,21 @@ public DeployKeysApi(GitLabApi gitLabApi) {
2021
2122 /**
2223 * Get a list of all deploy keys across all projects of the GitLab instance. This method requires admin access.
23- * Only returns the first page.
2424 *
25- * GET /deploy_keys
25+ * <pre><code>GitLab Endpoint: GET /deploy_keys</code></pre>
2626 *
2727 * @return a list of DeployKey
2828 * @throws GitLabApiException if any exception occurs
2929 */
3030 public List <DeployKey > getDeployKeys () throws GitLabApiException {
31- return (getDeployKeys (1 , getDefaultPerPage ()));
31+ return (getDeployKeys (getDefaultPerPage ()). all ( ));
3232 }
3333
3434 /**
3535 * Get a list of all deploy keys across all projects of the GitLab instance using the specified page and per page settings.
3636 * This method requires admin access.
3737 *
38- * GET /deploy_keys
38+ * <pre><code>GitLab Endpoint: GET /deploy_keys</code></pre>
3939 *
4040 * @param page the page to get
4141 * @param perPage the number of deploy keys per page
@@ -50,7 +50,7 @@ public List<DeployKey> getDeployKeys(int page, int perPage) throws GitLabApiExce
5050 /**
5151 * Get a Pager of all deploy keys across all projects of the GitLab instance. This method requires admin access.
5252 *
53- * GET /deploy_keys
53+ * <pre><code>GitLab Endpoint: GET /deploy_keys</code></pre>
5454 *
5555 * @param itemsPerPage the number of DeployKey instances that will be fetched per page
5656 * @return a Pager of DeployKey
@@ -59,98 +59,111 @@ public List<DeployKey> getDeployKeys(int page, int perPage) throws GitLabApiExce
5959 public Pager <DeployKey > getDeployKeys (int itemsPerPage ) throws GitLabApiException {
6060 return (new Pager <DeployKey >(this , DeployKey .class , itemsPerPage , null , "deploy_keys" ));
6161 }
62-
62+
63+ /**
64+ * Get a Stream of all deploy keys across all projects of the GitLab instance. This method requires admin access.
65+ *
66+ * <pre><code>GitLab Endpoint: GET /deploy_keys</code></pre>
67+ *
68+ * @return a list of DeployKey
69+ * @throws GitLabApiException if any exception occurs
70+ */
71+ public Stream <DeployKey > getDeployKeysStream () throws GitLabApiException {
72+ return (getDeployKeys (getDefaultPerPage ()).stream ());
73+ }
74+
6375 /**
6476 * Get a list of the deploy keys for the specified project. This method requires admin access.
65- * Only returns the first page.
6677 *
67- * GET /projects/:id/deploy_keys
78+ * <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys</code></pre>
6879 *
69- * @param projectId the ID of the project
80+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
7081 * @return a list of DeployKey
7182 * @throws GitLabApiException if any exception occurs
7283 */
73- public List <DeployKey > getProjectDeployKeys (Integer projectId ) throws GitLabApiException {
74- return (getProjectDeployKeys (projectId , 1 , getDefaultPerPage ()));
84+ public List <DeployKey > getProjectDeployKeys (Object projectIdOrPath ) throws GitLabApiException {
85+ return (getProjectDeployKeys (projectIdOrPath , getDefaultPerPage ()). all ( ));
7586 }
7687
7788 /**
7889 * Get a list of the deploy keys for the specified project using the specified page and per page settings.
7990 * This method requires admin access.
8091 *
81- * GET /projects/:id/deploy_keys
92+ * <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys</code></pre>
8293 *
83- * @param projectId the ID of the project
94+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
8495 * @param page the page to get
8596 * @param perPage the number of deploy keys per page
8697 * @return the list of DeployKey in the specified range
8798 * @throws GitLabApiException if any exception occurs
8899 */
89- public List <DeployKey > getProjectDeployKeys (Integer projectId , int page , int perPage ) throws GitLabApiException {
90-
91- if (projectId == null ) {
92- throw new RuntimeException ("projectId cannot be null" );
93- }
94-
95- Response response = get (Response .Status .OK , getPageQueryParams (page , perPage ), "projects" , projectId , "deploy_keys" );
100+ public List <DeployKey > getProjectDeployKeys (Object projectIdOrPath , int page , int perPage ) throws GitLabApiException {
101+ Response response = get (Response .Status .OK , getPageQueryParams (page , perPage ),
102+ "projects" , getProjectIdOrPath (projectIdOrPath ), "deploy_keys" );
96103 return (response .readEntity (new GenericType <List <DeployKey >>() {}));
97104 }
98105
99106 /**
100107 * Get a Pager of the deploy keys for the specified project. This method requires admin access.
101108 *
102- * GET /projects/:id/deploy_keys
109+ * <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys</code></pre>
103110 *
104- * @param projectId the ID of the project
111+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance@param projectId the ID of the project
105112 * @param itemsPerPage the number of DeployKey instances that will be fetched per page
106113 * @return a Pager of DeployKey
107114 * @throws GitLabApiException if any exception occurs
108115 */
109- public Pager <DeployKey > getProjectDeployKeys (Integer projectId , Integer itemsPerPage ) throws GitLabApiException {
110-
111- if (projectId == null ) {
112- throw new RuntimeException ("projectId cannot be null" );
113- }
116+ public Pager <DeployKey > getProjectDeployKeys (Object projectIdOrPath , int itemsPerPage ) throws GitLabApiException {
117+ return (new Pager <DeployKey >(this , DeployKey .class , itemsPerPage , null ,
118+ "projects" , getProjectIdOrPath (projectIdOrPath ), "deploy_keys" ));
119+ }
114120
115- return (new Pager <DeployKey >(this , DeployKey .class , itemsPerPage , null , "projects" , projectId , "deploy_keys" ));
121+ /**
122+ * Get a list of the deploy keys for the specified project. This method requires admin access.
123+ *
124+ * <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys</code></pre>
125+ *
126+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
127+ * @return a list of DeployKey
128+ * @throws GitLabApiException if any exception occurs
129+ */
130+ public Stream <DeployKey > getProjectDeployKeysStream (Object projectIdOrPath ) throws GitLabApiException {
131+ return (getProjectDeployKeys (projectIdOrPath , getDefaultPerPage ()).stream ());
116132 }
117133
118134 /**
119135 * Get a single deploy key for the specified project.
120136 *
121- * GET /projects/:id/deploy_keys/:key_id
137+ * <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys/:key_id</code></pre>
122138 *
123- * @param projectId the ID of the project
139+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
124140 * @param keyId the ID of the deploy key to delete
125141 * @return the DeployKey instance for the specified project ID and key ID
126142 * @throws GitLabApiException if any exception occurs
127143 */
128- public DeployKey getDeployKey (Integer projectId , Integer keyId ) throws GitLabApiException {
129-
130- if (projectId == null ) {
131- throw new RuntimeException ("projectId cannot be null" );
132- }
144+ public DeployKey getDeployKey (Object projectIdOrPath , Integer keyId ) throws GitLabApiException {
133145
134146 if (keyId == null ) {
135147 throw new RuntimeException ("keyId cannot be null" );
136148 }
137149
138- Response response = get (Response .Status .OK , null , "projects" , projectId , "deploy_keys" , keyId );
150+ Response response = get (Response .Status .OK , null ,
151+ "projects" , getProjectIdOrPath (projectIdOrPath ), "deploy_keys" , keyId );
139152 return (response .readEntity (DeployKey .class ));
140153 }
141154
142155 /**
143156 * Get a single deploy key for the specified project as an Optional instance.
144157 *
145- * GET /projects/:id/deploy_keys/:key_id
158+ * <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys/:key_id</code></pre>
146159 *
147- * @param projectId the ID of the project
160+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
148161 * @param keyId the ID of the deploy key to delete
149162 * @return the DeployKey for the specified project ID and key ID as an Optional instance
150163 */
151- public Optional <DeployKey > getOptionalDeployKey (Integer projectId , Integer keyId ) {
164+ public Optional <DeployKey > getOptionalDeployKey (Object projectIdOrPath , Integer keyId ) {
152165 try {
153- return (Optional .ofNullable (getDeployKey (projectId , keyId )));
166+ return (Optional .ofNullable (getDeployKey (projectIdOrPath , keyId )));
154167 } catch (GitLabApiException glae ) {
155168 return (GitLabApi .createOptionalFromException (glae ));
156169 }
@@ -159,72 +172,62 @@ public Optional<DeployKey> getOptionalDeployKey(Integer projectId, Integer keyId
159172 /**
160173 * Creates a new deploy key for a project.
161174 *
162- * POST /projects/:id/deploy_keys
175+ * <pre><code>GitLab Endpoint: POST /projects/:id/deploy_keys</code></pre>
163176 *
164- * @param projectId the ID of the project owned by the authenticated user, required
177+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
165178 * @param title the new deploy key's title, required
166179 * @param key the new deploy key, required
167180 * @param canPush can deploy key push to the project's repository, optional
168181 * @return an DeployKey instance with info on the added deploy key
169182 * @throws GitLabApiException if any exception occurs
170183 */
171- public DeployKey addDeployKey (Integer projectId , String title , String key , Boolean canPush ) throws GitLabApiException {
172-
173- if (projectId == null ) {
174- throw new RuntimeException ("projectId cannot be null" );
175- }
184+ public DeployKey addDeployKey (Object projectIdOrPath , String title , String key , Boolean canPush ) throws GitLabApiException {
176185
177186 GitLabApiForm formData = new GitLabApiForm ()
178187 .withParam ("title" , title , true )
179188 .withParam ("key" , key , true )
180189 .withParam ("can_push" , canPush );
181- Response response = post (Response .Status .CREATED , formData , "projects" , projectId , "deploy_keys" );
190+ Response response = post (Response .Status .CREATED , formData ,
191+ "projects" , getProjectIdOrPath (projectIdOrPath ), "deploy_keys" );
182192 return (response .readEntity (DeployKey .class ));
183193 }
184194
185195 /**
186196 * Removes a deploy key from the project. If the deploy key is used only for this project,it will be deleted from the system.
187197 *
188- * DELETE /projects/:id/deploy_keys/:key_id
198+ * <pre><code>GitLab Endpoint: DELETE /projects/:id/deploy_keys/:key_id</code></pre>
189199 *
190- * @param projectId the ID of the project
200+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
191201 * @param keyId the ID of the deploy key to delete
192202 * @throws GitLabApiException if any exception occurs
193203 */
194- public void deleteDeployKey (Integer projectId , Integer keyId ) throws GitLabApiException {
195-
196- if (projectId == null ) {
197- throw new RuntimeException ("projectId cannot be null" );
198- }
204+ public void deleteDeployKey (Object projectIdOrPath , Integer keyId ) throws GitLabApiException {
199205
200206 if (keyId == null ) {
201207 throw new RuntimeException ("keyId cannot be null" );
202208 }
203209
204- delete (Response .Status .OK , null , "projects" , projectId , "deploy_keys" , keyId );
210+ delete (Response .Status .OK , null , "projects" , getProjectIdOrPath ( projectIdOrPath ) , "deploy_keys" , keyId );
205211 }
206212
207213 /**
208214 * Enables a deploy key for a project so this can be used. Returns the enabled key when successful.
209215 *
210- * POST /projects/:id/deploy_keys/:key_id/enable
216+ * <pre><code>GitLab Endpoint: POST /projects/:id/deploy_keys/:key_id/enable</code></pre>
211217 *
212- * @param projectId the ID of the project
218+ * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
213219 * @param keyId the ID of the deploy key to enable
214220 * @return an DeployKey instance with info on the enabled deploy key
215221 * @throws GitLabApiException if any exception occurs
216222 */
217- public DeployKey enableDeployKey (Integer projectId , Integer keyId ) throws GitLabApiException {
218-
219- if (projectId == null ) {
220- throw new RuntimeException ("projectId cannot be null" );
221- }
223+ public DeployKey enableDeployKey (Object projectIdOrPath , Integer keyId ) throws GitLabApiException {
222224
223225 if (keyId == null ) {
224226 throw new RuntimeException ("keyId cannot be null" );
225227 }
226228
227- Response response = post (Response .Status .CREATED , (Form )null , "projects" , projectId , "deploy_keys" , keyId , "enable" );
229+ Response response = post (Response .Status .CREATED , (Form )null ,
230+ "projects" , getProjectIdOrPath (projectIdOrPath ), "deploy_keys" , keyId , "enable" );
228231 return (response .readEntity (DeployKey .class ));
229232 }
230233}
0 commit comments