package awso-async

  1. Overview
  2. Docs

Source file cfg.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
open! Core
open! Async
open! Import

let get ?profile ?aws_access_key_id ?aws_secret_access_key ?region ?output () =
  let profile : string option =
    List.reduce_exn ~f:Option.first_some [ profile; Sys.getenv "AWS_DEFAULT_PROFILE" ]
  in
  let file path of_string =
    match path () with
    | None -> return (Ok None)
    | Some file -> (
      let%bind contents = Reader.file_contents file in
      match of_string contents with
      | Error e -> return (Error e)
      | Ok r -> return (Ok (Some (file, r))))
  in
  match%bind file Awso.Cfg.Config_file.path Awso.Cfg.Config_file.of_string with
  | Error e -> return (Error e)
  | Ok config_file -> (
    match%map
      file
        Awso.Cfg.Shared_credentials_file.path
        Awso.Cfg.Shared_credentials_file.of_string
    with
    | Error e -> Error e
    | Ok shared_credentials_file ->
      Awso.Cfg.make
        ?config_file
        ?shared_credentials_file
        ?profile
        ?aws_access_key_id
        ?aws_secret_access_key
        ?region
        ?output
        ())
;;

let get_exn ?profile ?aws_access_key_id ?aws_secret_access_key ?region ?output () =
  match%map get ?profile ?aws_access_key_id ?aws_secret_access_key ?region ?output () with
  | Ok r -> r
  | Error e -> failwithf "Cfg.get_exn: %s" e ()
;;