Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 .github/actions/features_parse/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ outputs:
runs:
using: composite
steps:
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@0.7.3
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@0.8.0
- id: result
shell: bash
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/flavors_parse/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ outputs:
runs:
using: composite
steps:
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@0.7.3
- uses: gardenlinux/python-gardenlinux-lib/.github/actions/setup@0.8.0
- id: matrix
shell: bash
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Installs the given GardenLinux Python library
inputs:
version:
description: GardenLinux Python library version
default: "0.7.3"
default: "0.8.0"
runs:
using: composite
steps:
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "gardenlinux"
version = "0.7.3"
version = "0.8.0"
description = "Contains tools to work with the features directory of gardenlinux, for example deducting dependencies from feature sets or validating cnames"
authors = ["Garden Linux Maintainers <[email protected]>"]
license = "Apache-2.0"
Expand Down Expand Up @@ -34,6 +34,7 @@ gl-cname = "gardenlinux.features.cname_main:main"
gl-features-parse = "gardenlinux.features.__main__:main"
gl-flavors-parse = "gardenlinux.flavors.__main__:main"
gl-oci = "gardenlinux.oci.__main__:main"
gl-s3 = "gardenlinux.s3.__main__:main"

[tool.pytest.ini_options]
pythonpath = ["src"]
Expand Down
10 changes: 10 additions & 0 deletions src/gardenlinux/features/cname.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ def feature_set(self) -> str:

return Parser().filter_as_string(self.flavor)

@property
def platform(self) -> str:
"""
Returns the platform for the cname parsed.

:return: (str) Flavor
"""

return re.split("[_-]", self._flavor, 1)[0]

@property
def version(self) -> Optional[str]:
"""
Expand Down
10 changes: 10 additions & 0 deletions src/gardenlinux/s3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-

"""
S3 module
"""

from .bucket import Bucket
from .s3_artifacts import S3Artifacts

__all__ = ["Bucket", "S3Artifacts"]
45 changes: 45 additions & 0 deletions src/gardenlinux/s3/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
gl-s3 main entrypoint
"""

import argparse
import os
import re
import sys
from functools import reduce
from pathlib import Path
from typing import Any, List, Set

from .s3_artifacts import S3Artifacts


_ARGS_ACTION_ALLOWED = [
"download-artifacts-from-bucket",
"upload-artifacts-to-bucket",
]


def main() -> None:
"""
gl-s3 main()

:since: 0.8.0
"""

parser = argparse.ArgumentParser()

parser.add_argument("--bucket", dest="bucket")
parser.add_argument("--cname", required=False, dest="cname")
parser.add_argument("--path", required=False, dest="path")

parser.add_argument("action", nargs="?", choices=_ARGS_ACTION_ALLOWED)

args = parser.parse_args()

if args.action == "download-artifacts-from-bucket":
S3Artifacts(args.bucket).download_to_directory(args.cname, args.path)
elif args.action == "upload-artifacts-to-bucket":
S3Artifacts(args.bucket).upload_from_directory(args.cname, args.path)
82 changes: 82 additions & 0 deletions src/gardenlinux/s3/bucket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*-

"""
S3 bucket
"""

import boto3
import logging
from typing import Any, Optional

from ..logger import LoggerSetup


class Bucket(object):
"""
S3 bucket class

:author: Garden Linux Maintainers
:copyright: Copyright 2024 SAP SE
:package: gardenlinux
:subpackage: s3
:since: 0.8.0
:license: https://www.apache.org/licenses/LICENSE-2.0
Apache License, Version 2.0
"""

def __init__(
self,
bucket_name: str,
endpoint_url: Optional[str] = None,
s3_resource_config: Optional[dict[str, Any]] = None,
logger: Optional[logging.Logger] = None,
):
"""
Constructor __init__(Bucket)

:param bucket_name: S3 bucket name
:param endpoint_url: S3 endpoint URL
:param s3_resource_config: Additional boto3 S3 config values
:param logger: Logger instance

:since: 0.8.0
"""

if logger is None or not logger.hasHandlers():
logger = LoggerSetup.get_logger("gardenlinux.s3")

if s3_resource_config is None:
s3_resource_config = {}

if endpoint_url is not None:
s3_resource_config["endpoint_url"] = endpoint_url

self._s3_resource = boto3.resource("s3", **s3_resource_config)

self._bucket = self._s3_resource.Bucket(bucket_name)
self._logger = logger

@property
def objects(self):
"""
Returns a list of all objects in a bucket.

:return: (list) S3 bucket objects
:since: 0.8.0
"""

return self._bucket.objects.all()

def __getattr__(self, name):
"""
python.org: Called when an attribute lookup has not found the attribute in
the usual places (i.e. it is not an instance attribute nor is it found in the
class tree for self).

:param name: Attribute name

:return: (mixed) Attribute
:since: 0.8.0
"""

return getattr(self._bucket, name)
Loading