### DNS Record Setup Example
Source: https://docs.arvancloud.ir/fa/cdn/domain/cname-setup
Illustrates how to configure DNS records for CNAME setup, including both NS records for initial setup and the final CNAME record.
```APIDOC
## DNS Record Setup Examples
### Initial NS Records (Example)
This shows the NS records that might be present before converting to CNAME setup.
```dns
$ORIGIN example.com.
example.com. 86400 IN NS a.ns.arvancdn.ir.
example.com. 86400 IN NS z.ns.arvancdn.ir.
```
### CNAME Record for Subdomain (Example)
This demonstrates how to set up a CNAME record for a subdomain after converting to CNAME setup.
```dns
blog.example.com. 0 IN CNAME 802d64fa68594323a174bdea336ae4e5.cname.arvancdn.ir.
```
### Description
These examples provide a clear illustration of how DNS records should be configured when using ArvanCloud's CDN service with CNAME setup. The first example shows typical NS records, while the second shows the final CNAME record pointing to the ArvanCloud CDN service. This helps users understand the transition and the final state of their DNS configuration.
```
--------------------------------
### Go: Run s3_list_multipart_upload.go Example
Source: https://docs.arvancloud.ir/fa/developer-tools/sdk/object-storage/list-multipart-upload
This example shows how to execute a Go program named 's3_list_multipart_upload.go' from the command line. It requires a 'BUCKET_NAME' argument to be provided.
```bash
go run s3_list_multipart_upload.go BUCKET_NAME
```
--------------------------------
### Get Bucket Policy Status (PHP)
Source: https://docs.arvancloud.ir/fa/developer-tools/sdk/object-storage/get-bucket-policy-status
Retrieve the status of a bucket policy using the AWS SDK for PHP. This example shows how to interact with the S3 client to get the policy status.
```APIDOC
## GET /bucket-policy-status
### Description
Retrieves the status of a bucket policy using the AWS SDK for PHP.
### Method
GET
### Endpoint
Not explicitly defined, as this is an SDK operation.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```php
';
try {
$result = $client->getBucketPolicyStatus([
'Bucket' => $bucket, // REQUIRED
]);
var_dump($result);
} catch (AwsException $e) {
// Display error message
echo $e->getMessage();
echo "\n";
}
?>
```
### Response
#### Success Response (200)
- **Status** (array) - Contains information about the bucket policy status.
#### Response Example
```json
{
"IsPublic": true/false
}
```
```
--------------------------------
### دسترسی به Options در اسکریپت برنامه
Source: https://docs.arvancloud.ir/fa/cdn/marketplace/develop
این نمونه کد نشان میدهد که چگونه میتوان به پارامترهای تعریف شده در بخش 'options' فایل install.json از داخل اسکریپت برنامه دسترسی پیدا کرد. پارامترها از طریق آبجکت INSTALL_OPTIONS قابل دسترس هستند.
```javascript
INSTAL_OPTIONS.token
```
--------------------------------
### Install Packages with .custom_env Script
Source: https://docs.arvancloud.ir/fa/developer-tools/cloud-shell/customize
The .custom_env script runs automatically when your Cloud Shell starts and executes with root privileges. This allows you to install any Debian packages needed for your sessions. The script runs once at boot, making installed packages available shortly after.
```shell
#!/bin/sh
apt-get update
apt-get -y install erlang
```
--------------------------------
### تعریف Options در install.json
Source: https://docs.arvancloud.ir/fa/cdn/marketplace/develop
این نمونه نحوه تعریف پارامترهای ورودی کاربر (options) را برای اپلیکیشنهای بازارچه آروان نشان میدهد. از استاندارد JSON-Schema برای تعریف و اعتبارسنجی مقادیر استفاده میشود.
```json
{
"options": {
"properties": {
"": {
"title": "shown to user during app installation",
"Description": "shown to user during app installation",
"default": "default value",
"type": "string"
}
},
"required": [
" "
]
}
}
```
--------------------------------
### Get Bucket Versioning (Go)
Source: https://docs.arvancloud.ir/fa/developer-tools/sdk/object-storage/get-bucket-versioning
Example of how to retrieve the versioning state of an S3 bucket using the AWS SDK for Go.
```APIDOC
## Get Bucket Versioning (Go)
### Description
This Go code snippet demonstrates how to use the AWS SDK for Go to retrieve the versioning configuration of an S3 bucket.
### Method
GET
### Endpoint
N/A (SDK Method)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```go
package main
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"fmt"
"os"
)
// Retrieve Versioning on bucket
//
// Usage:
// go run s3_get_bucket_versioning.go BUCKET
func main() {
if len(os.Args) != 2 {
exitErrorf("Bucket name required\nUsage: go run", os.Args[0], "BUCKET")
}
bucket := os.Args[1]
sess, err := session.NewSession(&aws.Config{
Credentials: credentials.NewStaticCredentials("", "", ""),
})
svc := s3.New(sess, &aws.Config{
Region: aws.String("default"),
Endpoint: aws.String(""),
})
result, err := svc.GetBucketVersioning(&s3.GetBucketVersioningInput{Bucket: &bucket})
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return
}
fmt.Println(result)
}
func exitErrorf(msg string, args ...interface{}) {
fmt.Fprintf(os.Stderr, msg+"\n", args...)
os.Exit(1)
}
```
For execution, save the code as `s3_get_bucket_versioning.go` and run using:
```bash
go run s3_get_bucket_versioning.go BUCKET
```
### Response
#### Success Response (200)
- **Pointer to s3.GetBucketVersioningOutput object**
#### Response Example
```go
&{VersioningConfiguration:{Status:Enabled}}
```
```
--------------------------------
### ArvanCloud Firewall Rule Examples
Source: https://docs.arvancloud.ir/fa/cdn/security/firewall
Demonstrates how to create custom firewall rules using various parameters and operators. It covers simple and compound expressions for matching specific traffic conditions.
```text
ip.src==1.2.3.4
```
```text
request.method=="POST" and ip.src=="192.168.1.1" and http.user_agent=="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36"
```
```text
any(http.x_forwarded_for[] in {1.1.1.0 1.2.3.4})
```
```text
any(http.x_forwarded_for[] == 1.1.1.0)
```
```text
any(http.x_forwarded_for[*] != 1.1.1.0)
```
```text
http.request.headers["x-custom-header"] == "special-value"
```
--------------------------------
### Example Application Configuration with Hooks
Source: https://docs.arvancloud.ir/fa/cdn/marketplace/develop
This JSON configuration demonstrates how to set up a sample application that utilizes ArvanCloud hooks. It includes resource definitions, user-configurable options, and hook configurations specifying the endpoint and events to listen for. The script within 'content' illustrates how to access installation options like 'color' and 'token'.
```json
{
"resources": {
"body": [
{
"type": "script",
"content": "!function(){console.log('Your favorite color is :' + INSTALL_OPTIONS.color + 'also you are registered on our website with help of hooks, your token is :' INSTALL_OPTIONS.token )}();"
}
]
},
"options": {
"properties": {
"color": {
"title": "desired color",
"description": "tell us what's your favorite color",
"type": "string"
},
"token": {
"title": "token by hook",
"description": "The token will be automatically generated for you, we register you as our customer with your arvan's email address",
"type": "string"
}
},
"required": [
"color",
"token"
]
},
"hooks": [
{
"endpoint": "https://example-vendor.com/hook",
"events": [
"before-new-install"
]
}
]
}
```
--------------------------------
### Get Bucket Versioning (Node.js)
Source: https://docs.arvancloud.ir/fa/developer-tools/sdk/object-storage/get-bucket-versioning
Example of how to retrieve the versioning state of an S3 bucket using the AWS SDK for JavaScript.
```APIDOC
## Get Bucket Versioning (Node.js)
### Description
This Node.js code snippet demonstrates how to use the AWS SDK for JavaScript to retrieve the versioning configuration of an S3 bucket.
### Method
GET
### Endpoint
N/A (SDK Method)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```javascript
// Import required AWS SDK clients and commands for Node.js
const { S3Client, GetBucketVersioningCommand } = require("@aws-sdk/client-s3");
// Create an S3 client service object
const s3 = new S3Client({
region: "default",
endpoint: "endpoint_url",
credentials: {
accessKeyId: "access_key",
secretAccessKey: "secret_key",
},
});
const BUCKET_NAME = "sample_bucket";
const run = async () => {
try {
const response = await s3.send(
new GetBucketVersioningCommand({
Bucket: BUCKET_NAME,
})
);
console.log("Success", response);
} catch (err) {
console.log("Error", err);
}
};
run();
```
### Response
#### Success Response (200)
- **Object containing versioning information**
#### Response Example
```json
{
"VersioningConfiguration": {
"Status": "Enabled"
}
}
```
```
--------------------------------
### Get Bucket Versioning (PHP)
Source: https://docs.arvancloud.ir/fa/developer-tools/sdk/object-storage/get-bucket-versioning
Example of how to retrieve the versioning state of an S3 bucket using the AWS SDK for PHP.
```APIDOC
## Get Bucket Versioning (PHP)
### Description
This PHP code snippet demonstrates how to use the AWS SDK for PHP to retrieve the versioning configuration of an S3 bucket.
### Method
GET
### Endpoint
N/A (SDK Method)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```php
';
try {
$result = $client->getBucketVersioning([
'Bucket' => $bucket, // REQUIRED
]);
var_dump($result);
} catch (AwsException $e) {
// Display error message
echo $e->getMessage();
echo "\n";
}
?>
```
### Response
#### Success Response (200)
- **Result array containing versioning information**
#### Response Example
```php
Array
(
[VersioningConfiguration] => Array
(
[Status] => Enabled
)
)
```
```
--------------------------------
### List and Abort Multipart Uploads with AWS SDK (Go)
Source: https://docs.arvancloud.ir/fa/developer-tools/sdk/object-storage/abort-multipart-upload
Demonstrates how to list and abort multipart uploads using the AWS SDK for Go. It shows initializing an S3 client with credentials and endpoint, then listing uploads and providing an example for aborting a specific upload. Ensure the AWS SDK for Go is installed and configured.
```go
package main
import (
"bytes"
"fmt"
"net/http"
"os"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
const (
awsAccessKeyID = ""
awsSecretAccessKey = ""
awsBucketRegion = "default"
awsBucketEndpoint = ""
awsBucketName = ""
)
func main() {
creds := credentials.NewStaticCredentials(awsAccessKeyID, awsSecretAccessKey, "")
_, err := creds.Get()
if err != nil {
fmt.Printf("bad credentials: %s \n", err)
}
cfg := aws.NewConfig().WithRegion(awsBucketRegion).WithCredentials(creds).WithEndpoint(awsBucketEndpoint)
svc := s3.New(session.New(), cfg)
// Example for listing multipart uploads
multipartOutput, err := svc.ListMultipartUploads(&s3.ListMultipartUploadsInput{
Bucket: &awsBucketName,
})
if err != nil {
fmt.Printf("error getting list of multipart uploads: %s \n", err)
}
if multipartOutput.Uploads != nil {
for _, upload := range multipartOutput.Uploads {
fmt.Printf("Key: %s, UploadId: %s", upload.Key, upload.UploadId)
}
}
// Example for aborting a multipart upload (uncomment and fill in details to use)
/*
_, err = svc.AbortMultipartUpload(&s3.AbortMultipartUploadInput{
Bucket: aws.String(awsBucketName),
Key: aws.String("Key_In_Previous_Code_Example"),
UploadId: aws.String("UploadId_In_previous_Code_Example"),
})
if err != nil {
fmt.Printf("error aborting multipart upload: %s\n", err)
} else {
fmt.Println("Successfully aborted multipart upload.")
}
*/
}
```
--------------------------------
### Mount File System and Backup Data
Source: https://docs.arvancloud.ir/fa/cloud-server/instance/rescue
This snippet demonstrates how to mount a file system and then use rsync or scp to back up files, such as a MySQL database. Ensure the file system is mounted before proceeding with data transfer.
```shell
mount /dev/vda2 /mnt
cd /mnt
```
```shell
# Example for MySQL database backup path
/mnt/var/lib/mysql
```
--------------------------------
### Get Bucket Versioning (C#)
Source: https://docs.arvancloud.ir/fa/developer-tools/sdk/object-storage/get-bucket-versioning
Example of how to retrieve the versioning state of an S3 bucket using the AWS SDK for .NET.
```APIDOC
## Get Bucket Versioning (C#)
### Description
This C# code snippet demonstrates how to use the AWS SDK for .NET to retrieve the versioning configuration of an S3 bucket.
### Method
GET
### Endpoint
N/A (SDK Method)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```csharp
using Amazon;
using Amazon.S3;
using Amazon.S3.Model;
using System;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace GetBucketVersioningExample
{
class GetBucketVersioning
{
private const string bucketName = "";
private static IAmazonS3 _s3Client;
public static void Main()
{
var awsCredentials = new Amazon.Runtime.BasicAWSCredentials("", "");
var config = new AmazonS3Config { ServiceURL = "" };
_s3Client = new AmazonS3Client(awsCredentials, config);
GetBucketVersioningAsync().Wait();
}
private static async Task GetBucketVersioningAsync()
{
try
{
GetBucketVersioningResponse response = await _s3Client.GetBucketVersioningAsync(new GetBucketVersioningRequest
{
BucketName = bucketName,
});
Console.WriteLine(JsonConvert.SerializeObject(response, Formatting.Indented));
}
catch (AmazonS3Exception amazonS3Exception)
{
Console.WriteLine("An AmazonS3Exception was thrown. Exception: " + amazonS3Exception.ToString());
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.ToString());
}
}
}
}
```
### Response
#### Success Response (200)
- **Json representation of GetBucketVersioningResponse object**
#### Response Example
```json
{
"VersioningConfiguration": {
"Status": "Enabled"
}
}
```
```
--------------------------------
### Redirect Domain Requests to Another Domain (JavaScript)
Source: https://docs.arvancloud.ir/fa/edge-computing/examples/redirect
This example shows how to redirect requests from the current domain to a different domain while preserving the original path and query parameters. It listens for fetch events, constructs the new destination URL based on the incoming request's URL, and then performs the redirect using `Response.redirect`. This is useful for domain migrations or consolidating domains.
```javascript
addEventListener("fetch", (event) => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const base = "https://example.com";
const statusCode = 301;
const url = new URL(request.url);
const { pathname, search } = url;
const destinationURL = `${base}${pathname}${search}`;
console.log(destinationURL);
return Response.redirect(destinationURL, statusCode);
}
```
--------------------------------
### GET /cdn/4.0/metric-exporters
Source: https://docs.arvancloud.ir/fa/cdn/analytics/metric-exporter
Retrieve a list of all configured domain metric exporters. This allows you to view and manage existing monitoring setups.
```APIDOC
## GET /cdn/4.0/metric-exporters
### Description
Retrieve a list of all configured domain metric exporters. This allows you to view and manage existing monitoring setups.
### Method
GET
### Endpoint
`/cdn/4.0/metric-exporters`
### Parameters
#### Headers
- **Authorization**: `apikey [apikey]` (Replace `[apikey]` with your actual API key. Format: `apikey xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx`)
### Response
#### Success Response (200)
- **data** (array) - A list of metric exporter objects.
- **id** (string) - The ID of the metric exporter.
- **domain** (string) - The domain associated with the metric exporter.
- **type** (string) - The type of metric exporter (`access`|`dns`|`error`|`event`).
- **name** (string) - The name of the metric exporter.
- **url** (string) - The URL to access the metrics.
- **interval** (string) - The collection interval.
- **status** (boolean) - The status of the metric exporter.
#### Response Example
```json
{
"data": [
{
"id": "[metricExporterId]",
"domain": "arvancloud.ir",
"type": "access",
"name": "hello",
"url": "https://napi.arvancloud.ir/cdn-metrics/v1/metrics/arvancloud.ir/id/[metricExporterId]",
"interval": "10s",
"status": true
}
]
}
```
```
--------------------------------
### Get Bucket Versioning (Python)
Source: https://docs.arvancloud.ir/fa/developer-tools/sdk/object-storage/get-bucket-versioning
Example of how to retrieve the versioning state of an S3 bucket using the AWS SDK for Python (Boto3).
```APIDOC
## Get Bucket Versioning (Python)
### Description
This Python code snippet demonstrates how to use the AWS SDK for Python (Boto3) to retrieve the versioning configuration of an S3 bucket.
### Method
GET
### Endpoint
N/A (SDK Method)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```python
import boto3
import logging
from botocore.exceptions import ClientError
logging.basicConfig(level=logging.INFO)
try:
s3_client = boto3.client(
's3',
endpoint_url='',
aws_access_key_id='',
aws_secret_access_key=''
)
except Exception as exc:
logging.error(exc)
else:
try:
bucket_name = ''
response = s3_client.get_bucket_versioning(Bucket=bucket_name)
logging.info(response)
except ClientError as exc:
logging.error(exc)
```
### Response
#### Success Response (200)
- **Dictionary containing versioning information**
#### Response Example
```json
{
'VersioningConfiguration': {
'Status': 'Enabled'
}
}
```
```
--------------------------------
### Go Command-Line Execution Example
Source: https://docs.arvancloud.ir/fa/developer-tools/sdk/object-storage/upload-object
This demonstrates how to execute the Go S3 upload program from the command line. It specifies the command to run and the required arguments: the bucket name and the filename to upload. This is a usage instruction for the preceding Go code snippet.
```bash
go run s3_upload_object.go BUCKET_NAME FILENAME
```
--------------------------------
### Cloud Storage API - Get Object
Source: https://docs.arvancloud.ir/fa/developer-tools/api/api-usage
Retrieves a specific object from a bucket. This example uses cURL with AWS signature authentication.
```APIDOC
## GET //
### Description
Retrieves a specific object from a bucket using AWS signature authentication.
### Method
GET
### Endpoint
`//`
### Parameters
#### Path Parameters
- **bucket** (string) - Required - The name of the bucket.
- **file** (string) - Required - The name of the file (object) to retrieve.
#### Headers
- **Host** (string) - Required - The host of the storage endpoint (e.g., `bucket.s3.ir-thr-at1.arvanstorage.ir`).
- **Date** (string) - Required - The current date and time in RFC 7231 format.
- **Authorization** (string) - Required - AWS signature authentication string.
### Request Example
```bash
S3KEY="Accesskey"
S3SECRET="Secretkey"
function getObject
{
bucket='Bucketname'
file="Filename"
date=$(date +"%a, %d %b %Y %T %z")
string="GET\n\n\n$date\n/$bucket/$file"
signature=$(echo -en "${string}" | openssl sha1 -hmac "${S3SECRET}" -binary | base64)
curl -X GET \
-H "Host: $bucket.s3.ir-thr-at1.arvanstorage.ir" \
-H "Date: $date" \
-H "Authorization: AWS ${S3KEY}:${signature}" \
"https://s3.ir-thr-at1.arvanstorage.ir/$file"
}
getObject
```
### Response
#### Success Response (200)
- **Object Data** (binary) - The content of the requested object.
#### Response Example
(Binary content of the file)
```
--------------------------------
### List Multipart Uploads using GO SDK
Source: https://docs.arvancloud.ir/fa/developer-tools/sdk/object-storage/list-multipart-upload
This Go program lists multipart uploads for a given bucket using the AWS SDK for Go. It requires the bucket name as a command-line argument and sets up the S3 service client with specific credentials and endpoint.
```go
package main
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"fmt"
"os"
)
// Lists multipart uploads
//
// Usage:
// go run s3_list_multipart_upload.go BUCKET
func main() {
if len(os.Args) != 2 {
exitErrorf("Bucket name required\nUsage: go run", os.Args[0], "BUCKET")
}
bucket := os.Args[1]
sess, err := session.NewSession(&aws.Config{
Credentials: credentials.NewStaticCredentials("", "", ""),
})
svc := s3.New(sess, &aws.Config{
Region: aws.String("default"),
Endpoint: aws.String(""),
})
result, err := svc.ListMultipartUploads(&s3.ListMultipartUploadsInput{Bucket: &bucket})
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
```