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. Usesconf$storage$google$options_coastsif present (downstream packages), falling back toconf$storage$google$options(coasts itself, whereoptionsalready points to the coasts bucket)."country": the country-specific pipeline bucket where processed outputs are written. Always usesconf$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 usesconf$pds_storage$google$options, which resolves to the correct bucket per package (pds-peskas-coastsin coasts,pds-mozambique-prodin the Mozambique pipeline, etc.)."public": the publicly readable bucket serving portal JSON. Usesconf$public_storage$google$options, falling back toconf$storage$google$options_public. Optional — seeerror_if_missing."api": the cross-country API bucket holding the harmonized trips parquet every country publishes. Usesconf$storage$google$options_api. Optional — coasts itself does not configure one — seeerror_if_missing.
- error_if_missing
Logical. Controls what happens when the requested type is not configured.
FALSE(the default) returnsNULL, 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. PassTRUEto 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:
type | coasts package | downstream package |
"coasts" | peskas-coasts-dev | peskas-coasts-dev |
"country" | peskas-coasts-dev | mozambique-dev |
"pds" | pds-peskas-coasts | pds-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)
} # }
