Skip to content

Commit

Permalink
handle aws_profile or aws_irsa on get_snapshot_interface_from_backup_…
Browse files Browse the repository at this point in the history
…info
  • Loading branch information
smcaine committed Dec 4, 2024
1 parent f7362ab commit 298e631
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions barman/cloud_providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
# You should have received a copy of the GNU General Public License
# along with Barman. If not, see <http://www.gnu.org/licenses/>

import logging

from barman.exceptions import BarmanException, ConfigurationException

_logger = logging.getLogger(__name__)


class CloudProviderUnsupported(BarmanException):
"""
Expand Down Expand Up @@ -333,19 +337,29 @@ def get_snapshot_interface_from_backup_info(backup_info, config=None):
# from the backup_info, unless a region is set in the config in which case the
# config region takes precedence.
region = None
profile = None
aws_irsa = False
if config is not None:
if hasattr(config, "aws_region"):
region = config.aws_region
try:
if getattr(config, "aws_profile"):
profile = config.aws_profile
if getattr(config, "aws_irsa"):
aws_irsa = config.aws_irsa
except AttributeError:
raise SystemExit(
"Unable to locate credentials. You should configure an AWS profile."
_logger.warning(
"Unable to locate iam role. Trying aws profile."
)
else:
try:
if getattr(config, "aws_profile"):
profile = config.aws_profile
except AttributeError:
raise SystemExit(
"Unable to locate credentials. You should configure an AWS IAM role or an AWS profile."
)
if region is None:
region = backup_info.snapshots_info.region
return AwsCloudSnapshotInterface(profile, region)
return AwsCloudSnapshotInterface(profile, aws_irsa, region)
else:
raise CloudProviderUnsupported(
"Unsupported snapshot provider in backup info: %s"
Expand Down

0 comments on commit 298e631

Please sign in to comment.