use of com.ibm.cloud.cloudant.v1.model.PutCloudantSecurityConfigurationOptions in project cloudant-java-sdk by IBM.
the class PutCloudantSecurityConfigurationOptionsTest method testPutCloudantSecurityConfigurationOptions.
@Test
public void testPutCloudantSecurityConfigurationOptions() throws Throwable {
SecurityObject securityObjectModel = new SecurityObject.Builder().names(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).roles(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
assertEquals(securityObjectModel.names(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
assertEquals(securityObjectModel.roles(), new java.util.ArrayList<String>(java.util.Arrays.asList("testString")));
PutCloudantSecurityConfigurationOptions putCloudantSecurityConfigurationOptionsModel = new PutCloudantSecurityConfigurationOptions.Builder().db("testString").cloudant(new java.util.HashMap<String, List<String>>() {
{
put("foo", new java.util.ArrayList<String>(java.util.Arrays.asList("_reader")));
}
}).admins(securityObjectModel).members(securityObjectModel).couchdbAuthOnly(true).build();
assertEquals(putCloudantSecurityConfigurationOptionsModel.db(), "testString");
assertEquals(putCloudantSecurityConfigurationOptionsModel.cloudant(), new java.util.HashMap<String, List<String>>() {
{
put("foo", new java.util.ArrayList<String>(java.util.Arrays.asList("_reader")));
}
});
assertEquals(putCloudantSecurityConfigurationOptionsModel.admins(), securityObjectModel);
assertEquals(putCloudantSecurityConfigurationOptionsModel.members(), securityObjectModel);
assertEquals(putCloudantSecurityConfigurationOptionsModel.couchdbAuthOnly(), Boolean.valueOf(true));
}
use of com.ibm.cloud.cloudant.v1.model.PutCloudantSecurityConfigurationOptions in project cloudant-java-sdk by IBM.
the class CloudantTest method testPutCloudantSecurityConfigurationWOptions.
@Test
public void testPutCloudantSecurityConfigurationWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"ok\": true}";
String putCloudantSecurityConfigurationPath = "/_api/v2/db/testString/_security";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the SecurityObject model
SecurityObject securityObjectModel = new SecurityObject.Builder().names(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).roles(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
// Construct an instance of the PutCloudantSecurityConfigurationOptions model
PutCloudantSecurityConfigurationOptions putCloudantSecurityConfigurationOptionsModel = new PutCloudantSecurityConfigurationOptions.Builder().db("testString").cloudant(new java.util.HashMap<String, List<String>>() {
{
put("foo", new java.util.ArrayList<String>(java.util.Arrays.asList("_reader")));
}
}).admins(securityObjectModel).members(securityObjectModel).couchdbAuthOnly(true).build();
// Invoke operation with valid options model (positive test)
Response<Ok> response = cloudantService.putCloudantSecurityConfiguration(putCloudantSecurityConfigurationOptionsModel).execute();
assertNotNull(response);
Ok responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "PUT");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNull(query);
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, putCloudantSecurityConfigurationPath);
}
use of com.ibm.cloud.cloudant.v1.model.PutCloudantSecurityConfigurationOptions in project cloudant-java-sdk by IBM.
the class Cloudant method putCloudantSecurityConfiguration.
/**
* Modify only Cloudant related database permissions.
*
* Modify only Cloudant related permissions to database. Be careful: by removing an API key from the list, you remove
* the API key from the list of users that have access to the database.
*
* ### Note about nobody role
*
* The `nobody` username applies to all unauthenticated connection attempts. For example, if an application tries to
* read data from a database, but did not identify itself, the task can continue only if the `nobody` user has the
* role `_reader`.
*
* @param putCloudantSecurityConfigurationOptions the {@link PutCloudantSecurityConfigurationOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Ok}
*/
public ServiceCall<Ok> putCloudantSecurityConfiguration(PutCloudantSecurityConfigurationOptions putCloudantSecurityConfigurationOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(putCloudantSecurityConfigurationOptions, "putCloudantSecurityConfigurationOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("db", putCloudantSecurityConfigurationOptions.db());
RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/_api/v2/db/{db}/_security", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("cloudant", "v1", "putCloudantSecurityConfiguration");
for (Entry<String, String> header : sdkHeaders.entrySet()) {
builder.header(header.getKey(), header.getValue());
}
builder.header("Accept", "application/json");
final JsonObject contentJson = new JsonObject();
contentJson.add("cloudant", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(putCloudantSecurityConfigurationOptions.cloudant()));
if (putCloudantSecurityConfigurationOptions.admins() != null) {
contentJson.add("admins", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(putCloudantSecurityConfigurationOptions.admins()));
}
if (putCloudantSecurityConfigurationOptions.members() != null) {
contentJson.add("members", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(putCloudantSecurityConfigurationOptions.members()));
}
if (putCloudantSecurityConfigurationOptions.couchdbAuthOnly() != null) {
contentJson.addProperty("couchdb_auth_only", putCloudantSecurityConfigurationOptions.couchdbAuthOnly());
}
builder.bodyJson(contentJson);
ResponseConverter<Ok> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Ok>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations