Obtaining Back-to-Source by Mirroring Rules (SDK for Java)
Function
This API is used to obtain the back-to-source by mirroring rules of a bucket.
Restrictions
- To obtain the back-to-source by mirroring rules of a bucket, you must be the bucket owner or have the required permission (obs:bucket:GetMirrorBackToSource granted using IAM or GetMirrorBackToSource granted using a bucket policy). For details, see Introduction to OBS Access Control, IAM Custom Policies, and Creating a Custom Bucket Policy.
- The mapping between OBS regions and endpoints must comply with what is listed in Regions and Endpoints.
Method
obsClient.getBucketMirrorBackToSource(GetBucketMirrorBackToSourceRequest request)
Request Parameters
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| request | Yes | Explanation: Request parameters for obtaining the back-to-source by mirroring rules. For details, see Table 2. |
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| bucketName | String | Yes | Explanation: Bucket name Restrictions:
Default value: None |
Responses
| Parameter | Type | Description |
|---|---|---|
| statusCode | int | Explanation: HTTP status code Value range: A status code is a group of digits indicating the status of a response. It ranges from 2xx (indicating successes) to 4xx or 5xx (indicating errors). For more information, see Status Code. Default value: None |
| responseHeaders | Map<String, Object> | Explanation: HTTP response header list, composed of tuples. In a tuple, the String key indicates the name of the header, and the Object value indicates the value of the header. Default value: None |
| mirrorBackToSourceConfiguration | Explanation: Back-to-source by mirroring configuration. For details, see Table 4. |
| Parameter | Type | Description |
|---|---|---|
| rules | List<Table 5> | Explanation: List of back-to-source by mirroring rules. For details, see Table 5. |
| Parameter | Type | Description |
|---|---|---|
| id | String | Explanation: Rule ID. It is the unique identifier of the back-to-source by mirroring rule configured for the current bucket. |
| condition | Explanation: Condition for triggering back to source. For details, see Table 6. | |
| redirect | Explanation: Parameters for implementing the back to source function. For details, see Table 7. |
| Parameter | Type | Description |
|---|---|---|
| httpErrorCodeReturnedEquals | String | Explanation: Error code that triggers the back to source function. When this error code is returned for a download request, the back to source function is triggered. Default value: 404 |
| objectKeyPrefixEquals | String | Explanation: Prefix of the object name that triggers the back to source function. Back to source is performed only when the specified object name prefix is contained in the request. Restrictions:
|
| Parameter | Type | Description |
|---|---|---|
| agency | String | Explanation: Agency name. With an agency, you can grant OBS the permissions to query whether a specified object exists in a bucket and to upload objects to a bucket. |
| publicSource | Explanation: Configuration of the source site that can be publicly accessed. This parameter is mandatory when the source site is a publicly accessible resource. publicSource is the parent node of sourceEndpoint. For details, see Table 8. | |
| vpcEndpointURN | String | Explanation: URN of the VPC endpoint service |
| retryConditions | List<String> | Explanation: Condition for switching the source site address |
| passQueryString | Boolean | Explanation: Whether to include the request character string Value range:
|
| mirrorFollowRedirect | Boolean | Explanation: Whether to obtain resources by redirecting the request based on the 3XX response from the source site Value range:
|
| mirrorHttpHeader | Explanation: HTTP header pass rule. mirrorHttpHeader is the parent node of passAll, pass, remove, and set. For details, see Table 10. | |
| replaceKeyWith | String | Explanation: Whether to add a prefix or suffix when downloading objects from the source site |
| replaceKeyPrefixWith | String | Explanation: Character string used to replace objectKeyPrefixEquals. If you need to replace the current object name prefix when downloading the object from the source site, specify this parameter. |
| redirectWithoutReferer | Boolean | Explanation: Whether to carry the original host as the referer header to the destination address for redirection Value range: false: The original host is carried as the referer header to the destination address for redirection. true: The original host is not carried as the referer header to the destination address for redirection. |
| mirrorAllowHttpMethod | List<String> | Explanation: Request method that supports transparent transmission Value range:
|
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| sourceEndpoint | No | Explanation: Address of the source site that can be publicly accessed. sourceEndpoint is the parent node of master and slave. For details, see Table 9. |
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| master | List<String> | No | Explanation: Primary source site address. If the source site is a bucket that can be accessed over HTTP, the address is the bucket domain name. If the source site is a private bucket provided by other cloud vendors, the address is the region domain name. |
| slave | List<String> | No | Explanation: Secondary source site address. If the source site is a bucket that can be accessed over HTTP, the address is the bucket domain name. If the source site is a private bucket provided by other cloud vendors, the address is the region domain name. |
| Parameter | Type | Mandatory (Yes/No) | Description |
|---|---|---|---|
| passAll | Boolean | No | Explanation: Whether to transparently transmit all HTTP headers to the source site Value range:
|
| pass | List<String> | No | Explanation: List of HTTP headers to be transparently transmitted |
| remove | List<String> | No | Explanation: List of HTTP headers that cannot be transparently transmitted |
| set | List<Table 11> | No | Explanation: List of HTTP header values to be transparently transmitted. For details, see Table 11. |
Sample Code
import com.obs.services.ObsClient;
import com.obs.services.exception.ObsException;
import com.obs.services.model.mirrorback.GetBucketMirrorBackToSourceRequest;
import com.obs.services.model.mirrorback.GetBucketMirrorBackToSourceResult;
import com.obs.services.model.mirrorback.MirrorBackRedirect;
import com.obs.services.model.mirrorback.MirrorBackSourceEndpoint;
import com.obs.services.model.mirrorback.MirrorBackToSourceConfiguration;
import com.obs.services.model.mirrorback.MirrorBackToSourceRule;
public class GetBucketMirrorBackToSource {
public static void main(String[] args) {
// Obtain an AK/SK pair using environment variables or import the AK/SK pair in other ways. Using hard coding may result in leakage.
// Obtain an AK/SK pair on the management console.
String ak = System.getenv("ACCESS_KEY_ID");
String sk = System.getenv("SECRET_ACCESS_KEY_ID");
// (Optional) If you are using a temporary AK/SK pair and a security token to access OBS, you are not advised to use hard coding, which may result in information leakage.
// Obtain an AK/SK pair and a security token using environment variables or import them in other ways.
String securityToken = System.getenv("SECURITY_TOKEN");
// Enter the endpoint corresponding to the bucket. CN North-Beijing4 is used here as an example. Replace it with the one currently in use.
// Obtain an endpoint using environment variables or import it in other ways.
String endPoint = System.getenv("ENDPOINT");
ObsConfiguration obsConfiguration = new ObsConfiguration();
obsConfiguration.setEndPoint(endPoint);
ObsClient obsClient = new ObsClient(ak, sk, securityToken, obsConfiguration);
try {
String exampleBucket = "examplebucket";
GetBucketMirrorBackToSourceRequest request = new GetBucketMirrorBackToSourceRequest(exampleBucket);
GetBucketMirrorBackToSourceResult result = obsClient.getBucketMirrorBackToSource(request);
System.out.println("GetBucketMirrorBackToSource successfully");
MirrorBackToSourceConfiguration config = result.getMirrorBackToSourceConfiguration();
if (config != null && config.getRules() != null) {
for (MirrorBackToSourceRule rule : config.getRules()) {
System.out.println("Rule ID: " + rule.getId());
if (rule.getCondition() != null) {
System.out.println("Condition HTTP Error Code: "
+ rule.getCondition().getHttpErrorCodeReturnedEquals());
System.out.println("Condition Object Key Prefix: "
+ rule.getCondition().getObjectKeyPrefixEquals());
}
if (rule.getRedirect() != null) {
MirrorBackRedirect redirect = rule.getRedirect();
System.out.println("Agency: " + redirect.getAgency());
System.out.println("Pass Query String: " + redirect.getPassQueryString());
System.out.println("Mirror Follow Redirect: " + redirect.getMirrorFollowRedirect());
if (redirect.getPublicSource() != null
&& redirect.getPublicSource().getSourceEndpoint() != null) {
MirrorBackSourceEndpoint ep =
redirect.getPublicSource().getSourceEndpoint();
System.out.println("Master Endpoints: " + ep.getMaster());
System.out.println("Slave Endpoints: " + ep.getSlave());
}
}
}
}
} catch (ObsException e) {
System.out.println("GetBucketMirrorBackToSource failed");
// Request failed. Print the HTTP status code.
System.out.println("HTTP Code:" + e.getResponseCode());
// Request failed. Print the server-side error code.
System.out.println("Error Code:" + e.getErrorCode());
// Request failed. Print the error details.
System.out.println("Error Message:" + e.getErrorMessage());
// Request failed. Print the request ID.
System.out.println("Request ID:" + e.getErrorRequestId());
System.out.println("Host ID:" + e.getErrorHostId());
e.printStackTrace();
} catch (Exception e) {
System.out.println("GetBucketMirrorBackToSource failed");
// Print other error information.
e.printStackTrace();
}
}
} Helpful Links
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot