mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-03-19 17:30:27 +08:00
Allow region and bucket inference with NCS3UNK S3 server type
This commit is contained in:
parent
9b570f37e3
commit
e6a26a28b3
@ -110,17 +110,24 @@ NC_s3urlrebuild(NCURI* url, NCS3INFO* s3, NCURI** newurlp)
|
||||
/* split the path by "/" */
|
||||
if((stat = NC_split_delim(url->path,'/',pathsegments))) goto done;
|
||||
|
||||
/* Distinguish path-style from virtual-host style from s3: and from other.
|
||||
Virtual: https://<bucket-name>.s3.<region>.amazonaws.com/<path> (1)
|
||||
or: https://<bucket-name>.s3.amazonaws.com/<path> -- region defaults (to us-east-1) (2)
|
||||
Path: https://s3.<region>.amazonaws.com/<bucket-name>/<path> (3)
|
||||
or: https://s3.amazonaws.com/<bucket-name>/<path> -- region defaults to us-east-1 (4)
|
||||
S3: s3://<bucket-name>/<path> (5)
|
||||
Google: https://storage.googleapis.com/<bucket-name>/<path> (6)
|
||||
or: gs3://<bucket-name>/<path> (7)
|
||||
Other: https://<host>/<bucket-name>/<path> (8)
|
||||
*/
|
||||
if(url->host == NULL || strlen(url->host) == 0)
|
||||
/* Distinguish path-style from virtual-host style from s3: and from other.
|
||||
Virtual:
|
||||
(1) https://<bucket-name>.s3.<region>.amazonaws.com/<path>
|
||||
(2) https://<bucket-name>.s3.amazonaws.com/<path> -- region defaults (to us-east-1)
|
||||
Path:
|
||||
(3) https://s3.<region>.amazonaws.com/<bucket-name>/<path>
|
||||
(4) https://s3.amazonaws.com/<bucket-name>/<path> -- region defaults to us-east-1
|
||||
S3:
|
||||
(5) s3://<bucket-name>/<path>
|
||||
Google:
|
||||
(6) https://storage.googleapis.com/<bucket-name>/<path>
|
||||
(7) gs3://<bucket-name>/<path>
|
||||
Other:
|
||||
(8) https://<host>/<bucket-name>/<path>
|
||||
(9) https://<bucket-name>.s3.<region>.domain.example.com/<path>
|
||||
(10)https://s3.<region>.example.com/<bucket>/<path>
|
||||
*/
|
||||
if(url->host == NULL || strlen(url->host) == 0)
|
||||
{stat = NC_EURL; goto done;}
|
||||
|
||||
/* Reduce the host to standard form such as s3.amazonaws.com by pulling out the
|
||||
@ -168,12 +175,21 @@ NC_s3urlrebuild(NCURI* url, NCS3INFO* s3, NCURI** newurlp)
|
||||
/* region is unknown */
|
||||
/* bucket is unknown at this point */
|
||||
svc = NCS3GS;
|
||||
} else { /* Presume Format (8) */
|
||||
if((host = strdup(url->host))==NULL)
|
||||
{stat = NC_ENOMEM; goto done;}
|
||||
/* region is unknown */
|
||||
/* bucket is unknown */
|
||||
}
|
||||
} else { /* Presume Formats (8),(9),(10) */
|
||||
if (nclistlength(hostsegments) > 3 && strcasecmp(nclistget(hostsegments, 1), "s3") == 0){
|
||||
bucket = nclistremove(hostsegments, 0);
|
||||
region = nclistremove(hostsegments, 2);
|
||||
host = strdup(url->host + sizeof(bucket) + 1);
|
||||
}else{
|
||||
if (nclistlength(hostsegments) > 2 && strcasecmp(nclistget(hostsegments, 0), "s3") == 0){
|
||||
region = nclistremove(hostsegments, 1);
|
||||
}
|
||||
if ((host = strdup(url->host)) == NULL){
|
||||
stat = NC_ENOMEM;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* region = (1) from url, (2) s3->region, (3) default */
|
||||
if(region == NULL && s3 != NULL)
|
||||
|
Loading…
x
Reference in New Issue
Block a user