Skip to contents

Resolves the correct Google Cloud Storage options from a configuration object based on the target bucket. Handles both standalone (coasts) and downstream package contexts (e.g. peskas.mozambique.data.pipeline) transparently, so workflow functions do not need to hardcode config paths.

Usage

resolve_storage_opts(
  conf,
  type = c("coasts", "country", "pds", "public", "api"),
  error_if_missing = FALSE
)

Arguments

conf

A configuration list as returned by read_config().

type

Character. The target bucket. One of:

  • "coasts": the shared coasts bucket where device metadata lives. Uses conf$storage$google$options_coasts if present (downstream packages), falling back to conf$storage$google$options (coasts itself, where options already points to the coasts bucket).

  • "country": the country-specific pipeline bucket where processed outputs are written. Always uses conf$storage$google$options. In the coasts package this is the same bucket as "coasts".

  • "pds": the PDS-specific bucket where raw GPS tracks are stored. Always uses conf$pds_storage$google$options, which resolves to the correct bucket per package (pds-peskas-coasts in coasts, pds-mozambique-prod in the Mozambique pipeline, etc.).

  • "public": the publicly readable bucket serving portal JSON. Uses conf$public_storage$google$options, falling back to conf$storage$google$options_public. Optional — see error_if_missing.

  • "api": the cross-country API bucket holding the harmonized trips parquet every country publishes. Uses conf$storage$google$options_api. Optional — coasts itself does not configure one — see error_if_missing.

error_if_missing

Logical. Controls what happens when the requested type is not configured. FALSE (the default) returns NULL, which is how this function has always behaved for an unconfigured key and what makes "public" safe to ask for from a package that has no public bucket. Pass TRUE to fail fast with a message naming the expected configuration key.

Value

A named list of Google Cloud Storage options suitable for passing to cloud_object_name(), download_cloud_file(), or upload_cloud_file(); or NULL when the type is unconfigured and error_if_missing = FALSE.

Details

The bucket types map to the following storage contexts:

typecoasts packagedownstream package
"coasts"peskas-coasts-devpeskas-coasts-dev
"country"peskas-coasts-devmozambique-dev
"pds"pds-peskas-coastspds-mozambique-dev
"public"(unconfigured)timor-public-dev
"api"(unconfigured)peskas-api-dev

"public" is deliberately optional. coasts itself has no public bucket, so asking for it here returns NULL; a caller can then decide whether to skip the publishing step or fail. The Timor-Leste pipeline, which serves live portal JSON from a public bucket, previously had to reach into its config directly because this helper could not express the bucket at all.

Examples

if (FALSE) { # \dontrun{
conf <- read_config(package = "peskas.mozambique.data.pipeline")

# Read device metadata from shared coasts bucket
coasts_opts <- resolve_storage_opts(conf, "coasts")

# Write processed output to country bucket
country_opts <- resolve_storage_opts(conf, "country")

# Access raw GPS tracks from PDS bucket
pds_opts <- resolve_storage_opts(conf, "pds")

# Public portal bucket, tolerating its absence
public_opts <- resolve_storage_opts(conf, "public")
if (is.null(public_opts)) message("no public bucket configured")

# Fail fast instead
public_opts <- resolve_storage_opts(conf, "public", error_if_missing = TRUE)
} # }