diff --git a/src/main/java/org/kohsuke/github/GHEnterpriseExt.java b/src/main/java/org/kohsuke/github/GHEnterpriseExt.java index 513a32d..ef5a355 100644 --- a/src/main/java/org/kohsuke/github/GHEnterpriseExt.java +++ b/src/main/java/org/kohsuke/github/GHEnterpriseExt.java @@ -20,12 +20,17 @@ GHEnterpriseExt wrapUp(GitHub root) { } public SCIMEMUUser createSCIMEMUUser(SCIMEMUUser newUser) throws IOException { + newUser.schemas = new String[]{SCIMConstants.SCIM_USER_SCHEMA}; + String json = mapper.writeValueAsString(newUser); byte[] jsonBytes = json.getBytes(); try (InputStream inputStream = new ByteArrayInputStream(jsonBytes)) { SCIMEMUUser u = root.createRequest() .method("POST") + .withHeader(SCIMConstants.HEADER_CONTENT_TYPE, SCIMConstants.SCIM_CONTENT_TYPE) + .withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT) + .withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION) .with(inputStream) .withUrlPath(String.format("/scim/v2/enterprises/%s/Users", login)) .fetch(SCIMEMUUser.class); @@ -40,6 +45,9 @@ public SCIMEMUUser updateSCIMEMUUser(String scimUserId, SCIMPatchOperations oper try (InputStream inputStream = new ByteArrayInputStream(jsonBytes)) { SCIMEMUUser u = root.createRequest() .method("PATCH") + .withHeader(SCIMConstants.HEADER_CONTENT_TYPE, SCIMConstants.SCIM_CONTENT_TYPE) + .withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT) + .withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION) .with(inputStream) .withUrlPath(String.format("/scim/v2/enterprises/%s/Users/%s", login, scimUserId)) .fetch(SCIMEMUUser.class); @@ -49,6 +57,8 @@ public SCIMEMUUser updateSCIMEMUUser(String scimUserId, SCIMPatchOperations oper public SCIMEMUUser getSCIMEMUUser(String scimUserId) throws IOException { SCIMEMUUser u = root.createRequest() + .withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT) + .withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION) .withUrlPath(String.format("/scim/v2/enterprises/%s/Users/%s", login, scimUserId)) .fetch(SCIMEMUUser.class); return u; @@ -56,6 +66,8 @@ public SCIMEMUUser getSCIMEMUUser(String scimUserId) throws IOException { public SCIMEMUUser getSCIMEMUUserByUserName(String scimUserName) throws IOException { SCIMEMUUser u = root.createRequest() + .withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT) + .withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION) .withUrlPath(String.format("/scim/v2/enterprises/%s/Users?filter=userName eq \"%s\"", login, scimUserName)) .fetch(SCIMEMUUser.class); return u; @@ -78,17 +90,24 @@ public SCIMPagedSearchIterable listSCIMUsers(int pageSize, int page public void deleteSCIMUser(String scimUserId) throws IOException { root.createRequest() .method("DELETE") + .withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT) + .withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION) .withUrlPath(String.format("/scim/v2/enterprises/%s/Users/%s", login, scimUserId)) .send(); } public SCIMEMUGroup createSCIMEMUGroup(SCIMEMUGroup newGroup) throws IOException { + newGroup.schemas = new String[]{SCIMConstants.SCIM_GROUP_SCHEMA}; + String json = mapper.writeValueAsString(newGroup); byte[] jsonBytes = json.getBytes(); try (InputStream inputStream = new ByteArrayInputStream(jsonBytes)) { SCIMEMUGroup g = root.createRequest() .method("POST") + .withHeader(SCIMConstants.HEADER_CONTENT_TYPE, SCIMConstants.SCIM_CONTENT_TYPE) + .withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT) + .withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION) .with(inputStream) .withUrlPath(String.format("/scim/v2/enterprises/%s/Groups", login)) .fetch(SCIMEMUGroup.class); @@ -103,6 +122,9 @@ public SCIMEMUGroup updateSCIMEMUGroup(String scimGroupId, SCIMPatchOperations o try (InputStream inputStream = new ByteArrayInputStream(jsonBytes)) { SCIMEMUGroup g = root.createRequest() .method("PATCH") + .withHeader(SCIMConstants.HEADER_CONTENT_TYPE, SCIMConstants.SCIM_CONTENT_TYPE) + .withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT) + .withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION) .with(inputStream) .withUrlPath(String.format("/scim/v2/enterprises/%s/Groups/%s", login, scimGroupId)) .fetch(SCIMEMUGroup.class); @@ -112,6 +134,8 @@ public SCIMEMUGroup updateSCIMEMUGroup(String scimGroupId, SCIMPatchOperations o public SCIMEMUGroup getSCIMEMUGroup(String scimGroupId) throws IOException { SCIMEMUGroup g = root.createRequest() + .withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT) + .withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION) .withUrlPath(String.format("/scim/v2/enterprises/%s/Groups/%s", login, scimGroupId)) .fetch(SCIMEMUGroup.class); return g; @@ -119,6 +143,8 @@ public SCIMEMUGroup getSCIMEMUGroup(String scimGroupId) throws IOException { public SCIMEMUGroup getSCIMEMUGroupByDisplayName(String scimGroupDisplayName) throws IOException { SCIMEMUGroup g = root.createRequest() + .withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT) + .withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION) .withUrlPath(String.format("/scim/v2/enterprises/%s/Groups?filter=displayName eq \"%s\"", login, scimGroupDisplayName)) .fetch(SCIMEMUGroup.class); return g; @@ -141,6 +167,8 @@ public SCIMPagedSearchIterable listSCIMGroups(int pageSize, int pa public void deleteSCIMGroup(String scimGroupId) throws IOException { root.createRequest() .method("DELETE") + .withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT) + .withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION) .withUrlPath(String.format("/scim/v2/enterprises/%s/Groups/%s", login, scimGroupId)) .send(); } diff --git a/src/main/java/org/kohsuke/github/GHOrganizationExt.java b/src/main/java/org/kohsuke/github/GHOrganizationExt.java index d385ddd..06ec05f 100644 --- a/src/main/java/org/kohsuke/github/GHOrganizationExt.java +++ b/src/main/java/org/kohsuke/github/GHOrganizationExt.java @@ -46,6 +46,8 @@ public SCIMUser createSCIMUser(SCIMUser newUser) throws IOException { SCIMUser u = root.createRequest() .method("POST") + .withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT) + .withHeader(SCIMConstants.GITHUB_API_VERSION, SCIMConstants.GITHUB_API_VERSION) .with(map) .withUrlPath(String.format("/scim/v2/organizations/%s/Users", login)) .fetch(SCIMUser.class); @@ -81,6 +83,8 @@ public SCIMUser updateSCIMUser(String scimUserId, String scimUserName, String sc SCIMUser u = root.createRequest() .method("PATCH") + .withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT) + .withHeader(SCIMConstants.GITHUB_API_VERSION, SCIMConstants.GITHUB_API_VERSION) .with(map) .withUrlPath(String.format("/scim/v2/organizations/%s/Users/%s", login, scimUserId)) .fetch(SCIMUser.class); @@ -89,6 +93,8 @@ public SCIMUser updateSCIMUser(String scimUserId, String scimUserName, String sc public SCIMUser getSCIMUser(String scimUserId) throws IOException { SCIMUser u = root.createRequest() + .withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT) + .withHeader(SCIMConstants.GITHUB_API_VERSION, SCIMConstants.GITHUB_API_VERSION) .withUrlPath(String.format("/scim/v2/organizations/%s/Users/%s", login, scimUserId)) .fetch(SCIMUser.class); return u; @@ -96,6 +102,8 @@ public SCIMUser getSCIMUser(String scimUserId) throws IOException { public SCIMUser getSCIMUserByUserName(String scimUserName) throws IOException { SCIMUser u = root.createRequest() + .withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT) + .withHeader(SCIMConstants.GITHUB_API_VERSION, SCIMConstants.GITHUB_API_VERSION) .withUrlPath(String.format("/scim/v2/organizations/%s/Users?filter=userName eq \"%s\"", login, scimUserName)) .fetch(SCIMUser.class); return u; @@ -132,6 +140,8 @@ public GraphQLPagedSearchIterable schemas = Collections.singletonList(PATCH_OP); @JsonProperty("Operations") diff --git a/src/main/java/org/kohsuke/github/SCIMSearchBuilder.java b/src/main/java/org/kohsuke/github/SCIMSearchBuilder.java index a0a5e0b..c70fda9 100644 --- a/src/main/java/org/kohsuke/github/SCIMSearchBuilder.java +++ b/src/main/java/org/kohsuke/github/SCIMSearchBuilder.java @@ -23,7 +23,8 @@ public abstract class SCIMSearchBuilder extends GHQueryBuilder { this.organization = org; this.receiverType = receiverType; req.withUrlPath(getApiUrl()); - req.rateLimit(RateLimitTarget.SEARCH); + req.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT); + req.withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION); } SCIMSearchBuilder(GitHub root, GHEnterpriseExt enterprise, Class> receiverType) { @@ -32,7 +33,8 @@ public abstract class SCIMSearchBuilder extends GHQueryBuilder { this.organization = null; this.receiverType = receiverType; req.withUrlPath(getApiUrl()); - req.rateLimit(RateLimitTarget.SEARCH); + req.withHeader(SCIMConstants.HEADER_ACCEPT, SCIMConstants.SCIM_ACCEPT); + req.withHeader(SCIMConstants.HEADER_API_VERSION, SCIMConstants.GITHUB_API_VERSION); } /**