|
| 1 | +package com.auth0.client.mgmt; |
| 2 | + |
| 3 | +import com.auth0.client.mgmt.filter.NetworkAclsFilter; |
| 4 | +import com.auth0.json.mgmt.networkacls.NetworkAcls; |
| 5 | +import com.auth0.json.mgmt.networkacls.NetworkAclsPage; |
| 6 | +import com.auth0.net.BaseRequest; |
| 7 | +import com.auth0.net.Request; |
| 8 | +import com.auth0.net.VoidRequest; |
| 9 | +import com.auth0.net.client.Auth0HttpClient; |
| 10 | +import com.auth0.net.client.HttpMethod; |
| 11 | +import com.auth0.utils.Asserts; |
| 12 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 13 | +import okhttp3.HttpUrl; |
| 14 | + |
| 15 | +import java.util.Map; |
| 16 | + |
| 17 | +public class NetworkAclsEntity extends BaseManagementEntity { |
| 18 | + |
| 19 | + private final static String ORGS_PATH = "api/v2/network-acls"; |
| 20 | + |
| 21 | + NetworkAclsEntity(Auth0HttpClient client, HttpUrl baseUrl, TokenProvider tokenProvider) { |
| 22 | + super(client, baseUrl, tokenProvider); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * Lists all Network ACLs for the Auth0 tenant. |
| 27 | + * This method allows you to filter the results using the provided {@link NetworkAclsFilter}. |
| 28 | + * A token with scope read:network_acls is needed. |
| 29 | + * |
| 30 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/network-acls/get-network-acls">https://auth0.com/docs/api/management/v2#!/network-acls/get-network-acls</a> |
| 31 | + * @param filter the filter to apply to the request, can be null. |
| 32 | + * @return a Request that can be executed to retrieve a page of Network ACLs. |
| 33 | + */ |
| 34 | + public Request<NetworkAclsPage> list(NetworkAclsFilter filter) { |
| 35 | + HttpUrl.Builder builder = baseUrl.newBuilder() |
| 36 | + .addPathSegments(ORGS_PATH); |
| 37 | + |
| 38 | + if (filter != null) { |
| 39 | + for (Map.Entry<String, Object> e : filter.getAsMap().entrySet()) { |
| 40 | + builder.addQueryParameter(e.getKey(), String.valueOf(e.getValue())); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + String url = builder.build().toString(); |
| 45 | + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<NetworkAclsPage>(){ |
| 46 | + }); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Creates a new Network ACL for the Auth0 tenant. |
| 51 | + * A token with scope create:network_acls is needed. |
| 52 | + * |
| 53 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/network-acls/post-network-acls">https://auth0.com/docs/api/management/v2#!/network-acls/post-network-acls</a> |
| 54 | + * @param networkAcls the Network ACL to create. |
| 55 | + * @return a Request that can be executed to create the Network ACL. |
| 56 | + */ |
| 57 | + public Request<NetworkAcls> create(NetworkAcls networkAcls) { |
| 58 | + Asserts.assertNotNull(networkAcls, "network acls"); |
| 59 | + String url = baseUrl.newBuilder() |
| 60 | + .addPathSegments(ORGS_PATH) |
| 61 | + .build().toString(); |
| 62 | + BaseRequest<NetworkAcls> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.POST, new TypeReference<NetworkAcls>(){}); |
| 63 | + request.setBody(networkAcls); |
| 64 | + return request; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Get a Network ACL by its ID. |
| 69 | + * A token with scope read:network_acls is needed. |
| 70 | + * |
| 71 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/network-acls/get-network-acls-by-id">https://auth0.com/docs/api/management/v2#!/network-acls/get-network-acls-by-id</a> |
| 72 | + * @param id the ID of the Network ACL to delete. |
| 73 | + * @return a Request that can be executed to delete the Network ACL. |
| 74 | + */ |
| 75 | + public Request<NetworkAcls> get(String id) { |
| 76 | + Asserts.assertNotNull(id, "id"); |
| 77 | + |
| 78 | + String url = baseUrl.newBuilder() |
| 79 | + .addPathSegments(ORGS_PATH) |
| 80 | + .addPathSegment(id) |
| 81 | + .build().toString(); |
| 82 | + |
| 83 | + return new BaseRequest<>(client, tokenProvider, url, HttpMethod.GET, new TypeReference<NetworkAcls>(){}); |
| 84 | + } |
| 85 | + |
| 86 | + /** |
| 87 | + * Deletes a Network ACL by its ID. |
| 88 | + * A token with scope delete:network_acls is needed. |
| 89 | + * |
| 90 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/network-acls/delete-network-acls-by-id">https://auth0.com/docs/api/management/v2#!/network-acls/delete-network-acls-by-id</a> |
| 91 | + * @param id the ID of the Network ACL to delete. |
| 92 | + * @return a Request that can be executed to delete the Network ACL. |
| 93 | + */ |
| 94 | + public Request<Void> delete(String id) { |
| 95 | + Asserts.assertNotNull(id, "id"); |
| 96 | + |
| 97 | + String url = baseUrl.newBuilder() |
| 98 | + .addPathSegments(ORGS_PATH) |
| 99 | + .addPathSegment(id) |
| 100 | + .build().toString(); |
| 101 | + |
| 102 | + return new VoidRequest(client, tokenProvider, url, HttpMethod.DELETE); |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Updates a Network ACL by its ID. |
| 107 | + * A token with scope update:network_acls is needed. |
| 108 | + * |
| 109 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/network-acls/put-network-acls-by-id">https://auth0.com/docs/api/management/v2#!/network-acls/put-network-acls-by-id</a> |
| 110 | + * @param id the ID of the Network ACL to update. |
| 111 | + * @param networkAcls the Network ACL to update. |
| 112 | + * @return a Request that can be executed to update the Network ACL. |
| 113 | + */ |
| 114 | + public Request<NetworkAcls> update(String id, NetworkAcls networkAcls) { |
| 115 | + Asserts.assertNotNull(id, "id"); |
| 116 | + Asserts.assertNotNull(networkAcls, "network acls"); |
| 117 | + |
| 118 | + String url = baseUrl.newBuilder() |
| 119 | + .addPathSegments(ORGS_PATH) |
| 120 | + .addPathSegment(id) |
| 121 | + .build().toString(); |
| 122 | + |
| 123 | + BaseRequest<NetworkAcls> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.PUT, new TypeReference<NetworkAcls>() { |
| 124 | + }); |
| 125 | + request.setBody(networkAcls); |
| 126 | + return request; |
| 127 | + } |
| 128 | + |
| 129 | + /** |
| 130 | + * Partially updates a Network ACL by its ID. |
| 131 | + * A token with scope update:network_acls is needed. |
| 132 | + * |
| 133 | + * @see <a href="https://auth0.com/docs/api/management/v2#!/network-acls/patch-network-acls-by-id">https://auth0.com/docs/api/management/v2#!/network-acls/patch-network-acls-by-id</a> |
| 134 | + * @param id the ID of the Network ACL to update. |
| 135 | + * @param networkAcls the Network ACL to update. |
| 136 | + * @return a Request that can be executed to partially update the Network ACL. |
| 137 | + */ |
| 138 | + Request<NetworkAcls> patch(String id, NetworkAcls networkAcls) { |
| 139 | + Asserts.assertNotNull(id, "id"); |
| 140 | + |
| 141 | + String url = baseUrl.newBuilder() |
| 142 | + .addPathSegments(ORGS_PATH) |
| 143 | + .addPathSegment(id) |
| 144 | + .build().toString(); |
| 145 | + |
| 146 | + BaseRequest<NetworkAcls> request = new BaseRequest<>(client, tokenProvider, url, HttpMethod.PATCH, new TypeReference<NetworkAcls>() { |
| 147 | + }); |
| 148 | + request.setBody(networkAcls); |
| 149 | + return request; |
| 150 | + } |
| 151 | + |
| 152 | +} |
0 commit comments