Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more S3-compatible providers #721

Merged
merged 8 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ buildah rm "${container}"
images+=("${repobase}/${reponame}")

echo "Building the restic/rclone image..."
container=$(buildah from docker.io/library/alpine:3.18.4)
container=$(buildah from docker.io/library/alpine:3.20.3)
reponame="restic"
buildah add "${container}" restic/ /
buildah run ${container} sh <<'EOF'
Expand Down
24 changes: 23 additions & 1 deletion core/imageroot/usr/local/agent/bin/rclone-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import agent
import os
from urllib.parse import urlparse

def extract_region_code(hostname, position, default=""):
"""Obtain the region code for S3 backends by looking at the domain
parts of the endpoint FQDN."""
try:
return hostname.split('.')[position]
except ValueError:
return default

core_env = agent.read_envfile("/etc/nethserver/core.env")
rclone_image = core_env["RESTIC_IMAGE"]

Expand Down Expand Up @@ -60,8 +68,22 @@ elif uscheme == "s3":
if orepo['provider'] == 'aws':
rclone_env['RCLONE_S3_PROVIDER'] = 'AWS'
rclone_env['RCLONE_S3_REGION'] = orepo.get("aws_default_region", "")
elif orepo['provider'] == 'digitalocean':
elif orepo['provider'] == 'generic-s3' and 'digitalocean' in s3_endpoint:
rclone_env['RCLONE_S3_PROVIDER'] = 'DigitalOcean'
elif orepo['provider'] == 'generic-s3' and 'ovh.net' in s3_endpoint:
rclone_env['RCLONE_S3_PROVIDER'] = 'Other'
rclone_env['RCLONE_S3_REGION'] = orepo.get("aws_default_region", extract_region_code(s3_endpoint, 1))
rclone_env['RCLONE_S3_LOCATION_CONSTRAINT'] = rclone_env['RCLONE_S3_REGION']
elif orepo['provider'] == 'generic-s3' and 'wasabi' in s3_endpoint:
rclone_env['RCLONE_S3_PROVIDER'] = 'Wasabi'
rclone_env['RCLONE_S3_REGION'] = orepo.get("aws_default_region", extract_region_code(s3_endpoint, 1))
elif orepo['provider'] == 'generic-s3' and 'synology' in s3_endpoint:
rclone_env['RCLONE_S3_PROVIDER'] = 'Synology'
rclone_env['RCLONE_S3_REGION'] = orepo.get("aws_default_region", extract_region_code(s3_endpoint, 0))
rclone_env['RCLONE_S3_NO_CHECK_BUCKET'] = "1"
else:
rclone_env['RCLONE_S3_PROVIDER'] = 'Other'

elif uscheme == "azure":
rclone_path = ':azureblob:' + upath.rstrip(":")
rclone_env = {
Expand Down
2 changes: 0 additions & 2 deletions core/imageroot/usr/local/agent/pypkg/cluster/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ def get_default_backup_repository_name(provider, url, rid=""):
name = "AWS " + url.split('/', 1)[1]
elif provider == "backblaze":
name = "Backblaze " + url.split(':', 1)[1]
elif provider == "digitalocean":
name = "DigitalOcean " + url.split('/', 1)[1]
except:
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ renv['url'] = request['url'] # add url
renv['provider'] = request['provider'] # add provider
pvalidate = subprocess.run(['rclone-wrapper', '0', '--low-level-retries', '1', '--contimeout', '10s', 'size', '-q', '--json', 'REMOTE_PATH'], text=True, capture_output=True, env=renv)
if pvalidate.returncode != 0:
print(agent.SD_DEBUG, "The rclone-wrapper probe command has failed:", pvalidate.stderr, file=sys.stderr)
errors.append({'field':'parameters','parameter':'parameters','value':pvalidate.stderr,'error':'backup_repository_not_accessible'})

if errors:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@
"aws_secret_access_key": "edfjksof798r7fsdfiougvf7df"
}
},
{
"name": "repository 3",
"provider": "digitalocean",
"password": "",
"url": "s3:ams3.digitaloceanspaces.com/mybucket/mybackup",
"parameters": {
"aws_access_key_id": "XJEMERNGRIWGN",
"aws_secret_access_key": "897wergjkegher987geriugheruiger789"
}
},
{
"name": "repository 4",
"provider": "azure",
Expand Down Expand Up @@ -120,9 +110,12 @@
{
"title": "S3-based provider schema",
"properties": {
"url": {
"pattern": "/"
},
"provider": {
"title": "S3 providers",
"enum": ["aws", "digitalocean", "generic-s3"]
"enum": ["aws", "generic-s3"]
},
"parameters": {
"$ref": "#/$defs/s3_parameters"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
"title": "S3 providers",
"enum": [
"aws",
"digitalocean",
"generic-s3"
]
},
Expand Down
1 change: 1 addition & 0 deletions core/ui/public/i18n/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@
"cluster_placeholder": "Choose a node in the cluster",
"parameters_format": "Incorrect value",
"url": "URL",
"url_pattern": "The S3-compatible hostname and bucket name must be separated by a slash '/'",
"from_node_name_of_this_cluster": "From node {name} of this cluster",
"from_node_name_of_different_cluster": "From node {name} of a different cluster",
"from_this_cluster": "From this cluster",
Expand Down
16 changes: 8 additions & 8 deletions core/ui/src/components/backup/AddRepositoryModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,6 @@
ref="url"
>
</cv-text-input>
<cv-text-input
:label="$t('backup.aws_access_key_id')"
v-model.trim="aws.aws_access_key_id"
:invalid-message="error.aws.aws_access_key_id"
:disabled="loading.addBackupRepository"
ref="aws_access_key_id"
>
</cv-text-input>
<cv-text-input
:label="$t('backup.aws_default_region')"
v-model.trim="aws.aws_default_region"
Expand All @@ -256,6 +248,14 @@
ref="aws_default_region"
>
</cv-text-input>
<cv-text-input
:label="$t('backup.aws_access_key_id')"
v-model.trim="aws.aws_access_key_id"
:invalid-message="error.aws.aws_access_key_id"
:disabled="loading.addBackupRepository"
ref="aws_access_key_id"
>
</cv-text-input>
<cv-text-input
:label="$t('backup.aws_secret_access_key')"
type="password"
Expand Down
8 changes: 4 additions & 4 deletions core/ui/src/components/backup/RepoDetailsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@
<!-- amazon s3 -->
<template v-if="repository.provider == 'aws'">
<div class="key-value-setting">
<span class="label">{{ $t("backup.aws_access_key_id") }}</span>
<span class="label">{{ $t("backup.aws_default_region") }}</span>
<span class="value">{{
repository.parameters.aws_access_key_id
repository.parameters.aws_default_region
}}</span>
</div>
<div class="key-value-setting">
<span class="label">{{ $t("backup.aws_default_region") }}</span>
<span class="label">{{ $t("backup.aws_access_key_id") }}</span>
<span class="value">{{
repository.parameters.aws_default_region
repository.parameters.aws_access_key_id
}}</span>
</div>
<div class="key-value-setting">
Expand Down
Loading