s3_http Module

Core S3 HTTP operations module providing direct access to S3-compatible object storage.

This module provides low-level HTTP-based operations for interacting with S3-compatible object storage services. It uses system curl commands to perform GET, PUT, DELETE, and HEAD HTTP operations.

Features

  • Direct S3 operations via curl HTTP requests
  • Support for both authenticated and public bucket access
  • URI-based operations with s3:// protocol support
  • HTTP and HTTPS protocol support
  • Configurable endpoints for S3-compatible services

Usage

use s3_http
type(s3_config) :: config
character(len=:), allocatable :: content
logical :: success

! Configure and initialize
config%bucket = 'my-bucket'
config%region = 'us-east-1'
config%use_https = .true.
call s3_init(config)

! Download object
success = s3_get_object('data/file.txt', content)

Note

This module requires the curl command to be available in the system PATH.

Warning

URL encoding of special characters in S3 keys is not currently supported.



Variables

Type Visibility Attributes Name Initial
type(s3_config), private, save :: current_config
logical, private, save :: initialized = .false.

Derived Types

type, public ::  s3_config

S3 configuration type containing connection parameters and credentials.

Read more…

Components

Type Visibility Attributes Name Initial
character(len=256), public :: bucket = ''
character(len=256), public :: region = 'us-east-1'
character(len=256), public :: endpoint = 's3.amazonaws.com'
character(len=256), public :: access_key = ''
character(len=256), public :: secret_key = ''
logical, public :: use_https = .true.

Functions

public function s3_get_object(key, content) result(success)

Download an object from S3 and return its content.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: key
character(len=:), intent(out), allocatable :: content

Return Value logical

private function s3_get_object_fallback(key, content) result(success)

Fallback implementation using temporary files.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: key
character(len=:), intent(out), allocatable :: content

Return Value logical

public function s3_put_object(key, content) result(success)

Upload an object to S3.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: key
character(len=*), intent(in) :: content

Return Value logical

public function s3_object_exists(key) result(exists)

Check if an object exists in S3.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: key

Return Value logical

public function s3_delete_object(key) result(success)

Delete an object from S3.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: key

Return Value logical

private function getpid() result(pid)

Arguments

None

Return Value integer

public function s3_get_uri(uri, content) result(success)

Download an object using an s3:// URI.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: uri
character(len=:), intent(out), allocatable :: content

Return Value logical

public function s3_exists_uri(uri) result(exists)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: uri

Return Value logical

public function s3_put_uri(uri, content) result(success)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: uri
character(len=*), intent(in) :: content

Return Value logical

public function s3_delete_uri(uri) result(success)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: uri

Return Value logical


Subroutines

private subroutine parse_s3_uri(uri, bucket, key, success)

Parse an s3:// URI into bucket name and object key components.

Read more…

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: uri
character(len=:), intent(out), allocatable :: bucket
character(len=:), intent(out), allocatable :: key
logical, intent(out) :: success

public subroutine s3_init(config)

Initialize the S3 HTTP module with configuration.

Read more…

Arguments

Type IntentOptional Attributes Name
type(s3_config), intent(in) :: config