package awskit-s3

  1. Overview
  2. Docs
S3 client core — objects, buckets, multipart, and policies

Install

dune-project
 Dependency

Authors

Maintainers

Sources

awskit-v0.1.0.tbz
sha256=788e91d57b9eed047bdef011aec476e94588be20e2e2f1b8495cf48b1a90cf0f
sha512=0d441d599f3f3efb766270258bb4d8c9cd660943eb7f90ced0ec6f61a6790f5fb8977ca5cf87f466d84701ee34dbfdf81fe5043b568a2236411f577e698c6d1e

doc/src/awskit-s3/endpoint_resolver.ml.html

Source file endpoint_resolver.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
open Common

type addressing_style = [ `Auto | `Path | `Virtual_hosted ]

type endpoint_variant =
  [ `Regional
  | `Dualstack
  | `Fips
  | `Fips_dualstack
  | `Accelerate
  | `Accelerate_dualstack ]

type resolved_style = [ `Path | `Virtual_hosted ]

module Request = struct
  type t = {
    endpoint : Endpoint.t;
    path : string;
    signing_path : string;
    style : resolved_style;
  }
end

type t = {
  addressing_style : addressing_style;
  endpoint_variant : endpoint_variant;
  scheme : Endpoint.Scheme.t;
  endpoint_override : Endpoint.t option;
}

let create ?(addressing_style = `Auto) ?(endpoint_variant = `Regional)
    ?(scheme = `Https) ?endpoint () =
  { addressing_style; endpoint_variant; scheme; endpoint_override = endpoint }

let default = create ()
let addressing_style t = t.addressing_style
let endpoint_variant t = t.endpoint_variant

let scheme t =
  match t.endpoint_override with
  | Some endpoint -> Endpoint.scheme endpoint
  | None -> t.scheme

let endpoint_host t ~region =
  let region = Region.to_string region in
  match t.endpoint_variant with
  | `Regional -> Fmt.str "s3.%s.amazonaws.com" region
  | `Dualstack -> Fmt.str "s3.dualstack.%s.amazonaws.com" region
  | `Fips -> Fmt.str "s3-fips.%s.amazonaws.com" region
  | `Fips_dualstack -> Fmt.str "s3-fips.dualstack.%s.amazonaws.com" region
  | `Accelerate -> "s3-accelerate.amazonaws.com"
  | `Accelerate_dualstack -> "s3-accelerate.dualstack.amazonaws.com"

let endpoint t ~region =
  match t.endpoint_override with
  | Some endpoint -> Ok endpoint
  | None -> Endpoint.create ~scheme:t.scheme ~host:(endpoint_host t ~region) ()

let bucket_has_dot bucket = String.contains bucket '.'

let resolved_style t endpoint bucket =
  match t.addressing_style with
  | `Path -> Ok `Path
  | `Virtual_hosted -> Ok `Virtual_hosted
  | `Auto ->
      if Endpoint.scheme endpoint = `Https && bucket_has_dot bucket then
        Ok `Path
      else Ok `Virtual_hosted

let bucket_endpoint endpoint bucket =
  Endpoint.create ~scheme:(Endpoint.scheme endpoint)
    ~host:(bucket ^ "." ^ Endpoint.host endpoint)
    ?port:(Endpoint.port endpoint) ()

let path_style_path bucket suffix = "/" ^ bucket ^ suffix

let resolve_bucket_request t ~region ~bucket ~suffix ~signing_suffix =
  let* () = validate_bucket bucket in
  let* endpoint = endpoint t ~region in
  let* style = resolved_style t endpoint bucket in
  match style with
  | `Path ->
      Ok
        {
          Request.endpoint;
          path = path_style_path bucket suffix;
          signing_path = path_style_path bucket signing_suffix;
          style;
        }
  | `Virtual_hosted ->
      let* endpoint = bucket_endpoint endpoint bucket in
      Ok
        {
          Request.endpoint;
          path = suffix;
          signing_path = signing_suffix;
          style;
        }

let resolve_object_request t ~region ~bucket ~key =
  let* () = validate_bucket_key bucket key in
  let suffix = "/" ^ Awskit.Signing.uri_encode ~encode_slash:false key in
  let signing_suffix = "/" ^ key in
  resolve_bucket_request t ~region ~bucket ~suffix ~signing_suffix