Skip to content

Commit

Permalink
Allow region and bucket inference with NCS3UNK S3 server type
Browse files Browse the repository at this point in the history
  • Loading branch information
mannreis committed Nov 11, 2024
1 parent b084ad4 commit e8bb351
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions libdispatch/ds3util.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,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
Expand Down Expand Up @@ -186,12 +193,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)
Expand Down

0 comments on commit e8bb351

Please sign in to comment.