Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jmini committed Oct 20, 2023
2 parents 85904f5 + 1b3763e commit 4d23722
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 3 deletions.
75 changes: 72 additions & 3 deletions src/main/java/org/gitlab4j/api/GroupApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.gitlab4j.api.models.LdapGroupLink;
import org.gitlab4j.api.models.Member;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.SamlGroupLink;
import org.gitlab4j.api.models.Variable;
import org.gitlab4j.api.models.Visibility;
import org.gitlab4j.api.utils.ISO8601;
Expand Down Expand Up @@ -1183,9 +1184,9 @@ public void ldapSync(Object groupIdOrPath) throws GitLabApiException {

/**
* Get the list of LDAP group links.
*
*
* <pre><code>GitLab Endpoint: GET /groups/:id/ldap_group_links</code></pre>
*
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @return a list of LDAP group links
* @throws GitLabApiException if any exception occurs
Expand Down Expand Up @@ -1275,6 +1276,74 @@ public void deleteLdapGroupLink(Object groupIdOrPath, String cn, String provider
delete(Response.Status.OK, null, "groups", getGroupIdOrPath(groupIdOrPath), "ldap_group_links", provider, cn);
}

/**
* Get the list of SAML group links.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/saml_group_links</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @return a list of SAML group links
* @throws GitLabApiException if any exception occurs
*/
public List<SamlGroupLink> getSamlGroupLinks(Object groupIdOrPath) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "groups", getGroupIdOrPath(groupIdOrPath), "saml_group_links");
return (response.readEntity(new GenericType<List<SamlGroupLink>>() {}));
}

/**
* Adds an SAML group link.
*
* <pre><code>GitLab Endpoint: POST /groups/:id/saml_group_links</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param samlGroupName the name of the SAML group
* @param groupAccess the minimum access level for members of the SAML group
* @throws GitLabApiException if any exception occurs
*/
public void addSamlGroupLink(Object groupIdOrPath, String samlGroupName, AccessLevel groupAccess) throws GitLabApiException {

if (groupAccess == null) {
throw new RuntimeException("groupAccess cannot be null or empty");
}

addSamlGroupLink(groupIdOrPath, samlGroupName, groupAccess.toValue());
}

/**
* Adds an SAML group link.
*
* <pre><code>GitLab Endpoint: POST /groups/:id/saml_group_links</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param samlGroupName the name of the SAML group
* @param groupAccess the minimum access level for members of the SAML group
* @throws GitLabApiException if any exception occurs
*/
public void addSamlGroupLink(Object groupIdOrPath, String samlGroupName, Integer groupAccess) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("saml_group_name", samlGroupName, true)
.withParam("access_level", groupAccess, true);
post(Response.Status.CREATED, formData, "groups", getGroupIdOrPath(groupIdOrPath), "saml_group_links");
}

/**
* Deletes an SAML group link.
*
* <pre><code>GitLab Endpoint: DELETE /groups/:id/saml_group_links/:cn</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param samlGroupName the name of the SAML group to delete
* @throws GitLabApiException if any exception occurs
*/
public void deleteSamlGroupLink(Object groupIdOrPath, String samlGroupName) throws GitLabApiException {

if (samlGroupName == null || samlGroupName.trim().isEmpty()) {
throw new RuntimeException("samlGroupName cannot be null or empty");
}

delete(Response.Status.OK, null, "groups", getGroupIdOrPath(groupIdOrPath), "saml_group_links", samlGroupName);
}

/**
* Get list of a group’s variables.
*
Expand Down Expand Up @@ -1961,7 +2030,7 @@ public void deleteCustomAttribute(final Object groupIdOrPath, final String key)

delete(Response.Status.OK, null, "groups", getGroupIdOrPath(groupIdOrPath), "custom_attributes", key);
}

/**
* Lists group iterations.
*
Expand Down
32 changes: 32 additions & 0 deletions src/main/java/org/gitlab4j/api/models/SamlGroupLink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@

package org.gitlab4j.api.models;

import org.gitlab4j.api.utils.JacksonJson;

public class SamlGroupLink {

private String name;

private AccessLevel accessLevel;

public String getName() {
return name;
}

public void setName(String aName) {
this.name = aName;
}

public AccessLevel getAccessLevel() {
return accessLevel;
}

public void setAccessLevel(AccessLevel aAccessLevel) {
accessLevel = aAccessLevel;
}

@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}
}
7 changes: 7 additions & 0 deletions src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
import org.gitlab4j.api.models.RepositoryFileResponse;
import org.gitlab4j.api.models.Runner;
import org.gitlab4j.api.models.RunnerDetail;
import org.gitlab4j.api.models.SamlGroupLink;
import org.gitlab4j.api.models.SearchBlob;
import org.gitlab4j.api.models.Snippet;
import org.gitlab4j.api.models.SshKey;
Expand Down Expand Up @@ -816,6 +817,12 @@ public void testLdapGroupLink() throws Exception {
assertTrue(compareJson(link, "ldap-group-link.json"));
}

@Test
public void testSamlGroupLink() throws Exception {
SamlGroupLink link = unmarshalResource(SamlGroupLink.class, "saml-group-link.json");
assertTrue(compareJson(link, "saml-group-link.json"));
}

@Test
public void testSearchBlobs() throws Exception {
List<SearchBlob> searchResults = unmarshalResourceList(SearchBlob.class, "wiki-blobs.json");
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/org/gitlab4j/api/saml-group-link.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"access_level": 30,
"name": "A_GITLAB_DEVELOPER"
}

0 comments on commit 4d23722

Please sign in to comment.