2017-08-31 02:05:04 +08:00
|
|
|
/*
|
2018-12-07 05:29:57 +08:00
|
|
|
Copyright (c) 1998-2018 University Corporation for Atmospheric Research/Unidata
|
|
|
|
See COPYRIGHT for license information.
|
2017-08-31 02:05:04 +08:00
|
|
|
*/
|
2017-03-09 08:01:10 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STDARG_H
|
|
|
|
#include <stdarg.h>
|
|
|
|
#endif
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2021-09-28 08:36:33 +08:00
|
|
|
#include <assert.h>
|
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
#include "netcdf.h"
|
2017-03-09 08:01:10 +08:00
|
|
|
#include "ncbytes.h"
|
2017-08-31 07:44:57 +08:00
|
|
|
#include "ncuri.h"
|
2017-03-09 08:01:10 +08:00
|
|
|
#include "ncrc.h"
|
2023-04-26 07:15:06 +08:00
|
|
|
#include "ncs3sdk.h"
|
2017-08-31 07:44:57 +08:00
|
|
|
#include "nclog.h"
|
2021-09-28 08:36:33 +08:00
|
|
|
#include "ncauth.h"
|
2020-10-14 09:12:15 +08:00
|
|
|
#include "ncpathmgr.h"
|
2022-01-30 06:27:52 +08:00
|
|
|
#include "nc4internal.h"
|
2022-06-21 04:09:05 +08:00
|
|
|
#include "ncdispatch.h"
|
2017-08-31 07:44:57 +08:00
|
|
|
|
2021-12-24 13:18:56 +08:00
|
|
|
#undef NOREAD
|
|
|
|
|
2021-04-26 12:02:29 +08:00
|
|
|
#undef DRCDEBUG
|
2021-09-28 08:36:33 +08:00
|
|
|
#undef LEXDEBUG
|
|
|
|
#undef PARSEDEBUG
|
|
|
|
#undef AWSDEBUG
|
2021-04-26 12:02:29 +08:00
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
#define RTAG ']'
|
|
|
|
#define LTAG '['
|
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
#undef MEMCHECK
|
|
|
|
#define MEMCHECK(x) if((x)==NULL) {goto nomem;} else {}
|
|
|
|
|
2021-09-28 08:36:33 +08:00
|
|
|
/* Alternate .aws directory location */
|
|
|
|
#define NC_TEST_AWS_DIR "NC_TEST_AWS_DIR"
|
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
/* Forward */
|
2021-09-28 08:36:33 +08:00
|
|
|
static int NC_rcload(void);
|
2017-08-31 07:44:57 +08:00
|
|
|
static char* rcreadline(char** nextlinep);
|
|
|
|
static void rctrim(char* text);
|
2018-02-09 10:53:40 +08:00
|
|
|
static void rcorder(NClist* rc);
|
2017-08-31 07:44:57 +08:00
|
|
|
static int rccompile(const char* path);
|
2022-06-18 04:35:12 +08:00
|
|
|
static int rcequal(NCRCentry* e1, NCRCentry* e2);
|
|
|
|
static int rclocatepos(const char* key, const char* hostport, const char* urlpath);
|
|
|
|
static struct NCRCentry* rclocate(const char* key, const char* hostport, const char* urlpath);
|
2017-08-31 07:44:57 +08:00
|
|
|
static int rcsearch(const char* prefix, const char* rcname, char** pathp);
|
2021-09-28 08:36:33 +08:00
|
|
|
static void rcfreeentries(NClist* rc);
|
2022-06-18 04:35:12 +08:00
|
|
|
static void rcfreeentry(NCRCentry* t);
|
2021-09-28 08:36:33 +08:00
|
|
|
#ifdef DRCDEBUG
|
|
|
|
static void storedump(char* msg, NClist* entrys);
|
2017-08-31 07:44:57 +08:00
|
|
|
#endif
|
2022-01-30 06:27:52 +08:00
|
|
|
static int aws_load_credentials(NCglobalstate*);
|
2021-09-28 08:36:33 +08:00
|
|
|
static void freeprofile(struct AWSprofile* profile);
|
|
|
|
static void freeprofilelist(NClist* profiles);
|
2017-03-09 08:01:10 +08:00
|
|
|
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
/* Define default rc files and aliases, also defines load order*/
|
2023-06-11 08:51:13 +08:00
|
|
|
static const char* rcfilenames[] = {".ncrc", ".daprc", ".dodsrc", NULL};
|
2017-03-09 08:01:10 +08:00
|
|
|
|
2023-04-26 07:15:06 +08:00
|
|
|
/* Read these files in order and later overriding earlier */
|
|
|
|
static const char* awsconfigfiles[] = {".aws/config",".aws/credentials",NULL};
|
2021-09-28 08:36:33 +08:00
|
|
|
|
2022-06-18 04:35:12 +08:00
|
|
|
static int NCRCinitialized = 0;
|
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
/**************************************************/
|
2022-06-18 04:35:12 +08:00
|
|
|
/* User API */
|
2017-03-09 08:01:10 +08:00
|
|
|
|
2022-06-18 04:35:12 +08:00
|
|
|
/**
|
|
|
|
The most common case is to get the most general value for a key,
|
|
|
|
where most general means that the urlpath and hostport are null
|
|
|
|
So this function returns the value associated with the key
|
|
|
|
where the .rc entry has the simple form "key=value".
|
|
|
|
If that entry is not found, then return NULL.
|
|
|
|
|
|
|
|
@param key table entry key field
|
|
|
|
@return value matching the key -- caller frees
|
|
|
|
@return NULL if no entry of the form key=value exists
|
|
|
|
*/
|
|
|
|
char*
|
|
|
|
nc_rc_get(const char* key)
|
|
|
|
{
|
|
|
|
NCglobalstate* ncg = NULL;
|
|
|
|
char* value = NULL;
|
|
|
|
|
2022-06-21 04:09:05 +08:00
|
|
|
if(!NC_initialized) nc_initialize();
|
|
|
|
|
2022-06-18 04:35:12 +08:00
|
|
|
ncg = NC_getglobalstate();
|
|
|
|
assert(ncg != NULL && ncg->rcinfo != NULL && ncg->rcinfo->entries != NULL);
|
2023-06-11 08:51:13 +08:00
|
|
|
if(ncg->rcinfo->ignore) goto done;
|
2022-06-18 04:35:12 +08:00
|
|
|
value = NC_rclookup(key,NULL,NULL);
|
2023-06-11 08:51:13 +08:00
|
|
|
done:
|
|
|
|
value = nulldup(value);
|
|
|
|
return value;
|
2022-06-18 04:35:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Set simple key=value in .rc table.
|
|
|
|
Will overwrite any existing value.
|
|
|
|
|
|
|
|
@param key
|
|
|
|
@param value
|
|
|
|
@return NC_NOERR if success
|
|
|
|
@return NC_EINVAL if fail
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
nc_rc_set(const char* key, const char* value)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
NCglobalstate* ncg = NULL;
|
|
|
|
|
2022-06-21 04:09:05 +08:00
|
|
|
if(!NC_initialized) nc_initialize();
|
|
|
|
|
2022-06-18 04:35:12 +08:00
|
|
|
ncg = NC_getglobalstate();
|
|
|
|
assert(ncg != NULL && ncg->rcinfo != NULL && ncg->rcinfo->entries != NULL);
|
2023-06-11 08:51:13 +08:00
|
|
|
if(ncg->rcinfo->ignore) goto done;;
|
2022-06-18 04:35:12 +08:00
|
|
|
stat = NC_rcfile_insert(key,NULL,NULL,value);
|
2023-06-11 08:51:13 +08:00
|
|
|
done:
|
2022-06-18 04:35:12 +08:00
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************/
|
|
|
|
/* External Entry Points */
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
|
2021-09-28 08:36:33 +08:00
|
|
|
/*
|
|
|
|
Initialize defaults and load:
|
|
|
|
* .ncrc
|
|
|
|
* .dodsrc
|
|
|
|
* ${HOME}/.aws/config
|
|
|
|
* ${HOME}/.aws/credentials
|
|
|
|
|
|
|
|
For debugging support, it is possible
|
|
|
|
to change where the code looks for the .aws directory.
|
2022-01-25 04:48:41 +08:00
|
|
|
This is set by the environment variable NC_TEST_AWS_DIR.
|
2021-09-28 08:36:33 +08:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
ncrc_initialize(void)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
2022-01-30 06:27:52 +08:00
|
|
|
NCglobalstate* ncg = NULL;
|
2022-01-25 04:48:41 +08:00
|
|
|
|
2021-09-28 08:36:33 +08:00
|
|
|
if(NCRCinitialized) return;
|
|
|
|
NCRCinitialized = 1; /* prevent recursion */
|
2022-01-25 04:48:41 +08:00
|
|
|
|
2022-06-18 04:35:12 +08:00
|
|
|
ncg = NC_getglobalstate();
|
|
|
|
|
2021-12-24 13:18:56 +08:00
|
|
|
#ifndef NOREAD
|
2021-09-28 08:36:33 +08:00
|
|
|
/* Load entrys */
|
|
|
|
if((stat = NC_rcload())) {
|
|
|
|
nclog(NCLOGWARN,".rc loading failed");
|
|
|
|
}
|
2023-04-26 07:15:06 +08:00
|
|
|
/* Load .aws/config &/ credentials */
|
2022-01-30 06:27:52 +08:00
|
|
|
if((stat = aws_load_credentials(ncg))) {
|
2021-09-28 08:36:33 +08:00
|
|
|
nclog(NCLOGWARN,"AWS config file not loaded");
|
|
|
|
}
|
2021-12-24 13:18:56 +08:00
|
|
|
#endif
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
}
|
|
|
|
|
2021-11-04 02:49:54 +08:00
|
|
|
static void
|
|
|
|
ncrc_setrchome(void)
|
|
|
|
{
|
|
|
|
const char* tmp = NULL;
|
2022-01-30 06:27:52 +08:00
|
|
|
NCglobalstate* ncg = NC_getglobalstate();
|
|
|
|
assert(ncg && ncg->home);
|
|
|
|
if(ncg->rcinfo->rchome) return;
|
2021-11-04 02:49:54 +08:00
|
|
|
tmp = getenv(NCRCENVHOME);
|
|
|
|
if(tmp == NULL || strlen(tmp) == 0)
|
2022-01-30 06:27:52 +08:00
|
|
|
tmp = ncg->home;
|
|
|
|
ncg->rcinfo->rchome = strdup(tmp);
|
2022-06-18 04:35:12 +08:00
|
|
|
#ifdef DRCDEBUG
|
|
|
|
fprintf(stderr,"ncrc_setrchome: %s\n",ncg->rcinfo->rchome);
|
|
|
|
#endif
|
2019-03-31 04:06:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NC_rcclear(NCRCinfo* info)
|
|
|
|
{
|
|
|
|
if(info == NULL) return;
|
|
|
|
nullfree(info->rcfile);
|
2021-11-04 02:49:54 +08:00
|
|
|
nullfree(info->rchome);
|
2021-09-28 08:36:33 +08:00
|
|
|
rcfreeentries(info->entries);
|
2022-01-30 06:27:52 +08:00
|
|
|
freeprofilelist(info->s3profiles);
|
2022-07-06 12:03:52 +08:00
|
|
|
|
2019-03-31 04:06:20 +08:00
|
|
|
}
|
|
|
|
|
2022-01-30 06:27:52 +08:00
|
|
|
static void
|
2022-06-18 04:35:12 +08:00
|
|
|
rcfreeentry(NCRCentry* t)
|
2019-03-31 04:06:20 +08:00
|
|
|
{
|
|
|
|
nullfree(t->host);
|
2022-06-18 04:35:12 +08:00
|
|
|
nullfree(t->urlpath);
|
2019-03-31 04:06:20 +08:00
|
|
|
nullfree(t->key);
|
|
|
|
nullfree(t->value);
|
|
|
|
free(t);
|
2022-06-18 04:35:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rcfreeentries(NClist* rc)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=0;i<nclistlength(rc);i++) {
|
|
|
|
NCRCentry* t = (NCRCentry*)nclistget(rc,i);
|
|
|
|
rcfreeentry(t);
|
2019-03-31 04:06:20 +08:00
|
|
|
}
|
|
|
|
nclistfree(rc);
|
|
|
|
}
|
2017-03-09 08:01:10 +08:00
|
|
|
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
/* locate, read and compile the rc files, if any */
|
2021-09-28 08:36:33 +08:00
|
|
|
static int
|
2017-08-31 07:44:57 +08:00
|
|
|
NC_rcload(void)
|
2017-03-09 08:01:10 +08:00
|
|
|
{
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
int i,ret = NC_NOERR;
|
2017-03-09 08:01:10 +08:00
|
|
|
char* path = NULL;
|
2022-01-30 06:27:52 +08:00
|
|
|
NCglobalstate* globalstate = NULL;
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
NClist* rcfileorder = nclistnew();
|
2017-03-09 08:01:10 +08:00
|
|
|
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
if(!NCRCinitialized) ncrc_initialize();
|
2022-01-30 06:27:52 +08:00
|
|
|
globalstate = NC_getglobalstate();
|
2021-12-24 13:18:56 +08:00
|
|
|
|
2022-01-30 06:27:52 +08:00
|
|
|
if(globalstate->rcinfo->ignore) {
|
Mitigate S3 test interference + Unlimited Dimensions in NCZarr
This PR started as an attempt to add unlimited dimensions to NCZarr.
It did that, but this exposed significant problems with test interference.
So this PR is mostly about fixing -- well mitigating anyway -- test
interference.
The problem of test interference is now documented in the document docs/internal.md.
The solutions implemented here are also describe in that document.
The solution is somewhat fragile but multiple cleanup mechanisms
are provided. Note that this feature requires that the
AWS command line utility must be installed.
## Unlimited Dimensions.
The existing NCZarr extensions to Zarr are modified to support unlimited dimensions.
NCzarr extends the Zarr meta-data for the ".zgroup" object to include netcdf-4 model extensions. This information is stored in ".zgroup" as dictionary named "_nczarr_group".
Inside "_nczarr_group", there is a key named "dims" that stores information about netcdf-4 named dimensions. The value of "dims" is a dictionary whose keys are the named dimensions. The value associated with each dimension name has one of two forms
Form 1 is a special case of form 2, and is kept for backward compatibility. Whenever a new file is written, it uses format 1 if possible, otherwise format 2.
* Form 1: An integer representing the size of the dimension, which is used for simple named dimensions.
* Form 2: A dictionary with the following keys and values"
- "size" with an integer value representing the (current) size of the dimension.
- "unlimited" with a value of either "1" or "0" to indicate if this dimension is an unlimited dimension.
For Unlimited dimensions, the size is initially zero, and as variables extend the length of that dimension, the size value for the dimension increases.
That dimension size is shared by all arrays referencing that dimension, so if one array extends an unlimited dimension, it is implicitly extended for all other arrays that reference that dimension.
This is the standard semantics for unlimited dimensions.
Adding unlimited dimensions required a number of other changes to the NCZarr code-base. These included the following.
* Did a partial refactor of the slice handling code in zwalk.c to clean it up.
* Added a number of tests for unlimited dimensions derived from the same test in nc_test4.
* Added several NCZarr specific unlimited tests; more are needed.
* Add test of endianness.
## Misc. Other Changes
* Modify libdispatch/ncs3sdk_aws.cpp to optionally support use of the
AWS Transfer Utility mechanism. This is controlled by the
```#define TRANSFER```` command in that file. It defaults to being disabled.
* Parameterize both the standard Unidata S3 bucket (S3TESTBUCKET) and the netcdf-c test data prefix (S3TESTSUBTREE).
* Fixed an obscure memory leak in ncdump.
* Removed some obsolete unit testing code and test cases.
* Uncovered a bug in the netcdf-c handling of big-endian floats and doubles. Have not fixed yet. See tst_h5_endians.c.
* Renamed some nczarr_tests testcases to avoid name conflicts with nc_test4.
* Modify the semantics of zmap\#ncsmap_write to only allow total rewrite of objects.
* Modify the semantics of zodom to properly handle stride > 1.
* Add a truncate operation to the libnczarr zmap code.
2023-09-27 06:56:48 +08:00
|
|
|
nclog(NCLOGNOTE,".rc file loading suppressed");
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
goto done;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
2022-01-30 06:27:52 +08:00
|
|
|
if(globalstate->rcinfo->loaded) goto done;
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
|
|
|
|
/* locate the configuration files in order of use:
|
|
|
|
1. Specified by NCRCENV_RC environment variable.
|
|
|
|
2. If NCRCENV_RC is not set then merge the set of rc files in this order:
|
2023-06-11 08:51:13 +08:00
|
|
|
1. $HOME/.ncrc
|
|
|
|
2. $HOME/.dodsrc
|
|
|
|
3. $CWD/.ncrc
|
|
|
|
4. $CWD/.dodsrc
|
|
|
|
Entries in later files override any of the earlier files
|
2017-03-09 08:01:10 +08:00
|
|
|
*/
|
2022-01-30 06:27:52 +08:00
|
|
|
if(globalstate->rcinfo->rcfile != NULL) { /* always use this */
|
|
|
|
nclistpush(rcfileorder,strdup(globalstate->rcinfo->rcfile));
|
2017-08-31 07:44:57 +08:00
|
|
|
} else {
|
2019-03-31 04:06:20 +08:00
|
|
|
const char** rcname;
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
const char* dirnames[3];
|
|
|
|
const char** dir;
|
2022-01-25 04:48:41 +08:00
|
|
|
|
2022-06-18 04:35:12 +08:00
|
|
|
/* Make sure rcinfo.rchome is defined */
|
2021-11-04 02:49:54 +08:00
|
|
|
ncrc_setrchome();
|
2022-01-30 06:27:52 +08:00
|
|
|
dirnames[0] = globalstate->rcinfo->rchome;
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
dirnames[1] = globalstate->cwd;
|
|
|
|
dirnames[2] = NULL;
|
|
|
|
|
2022-01-25 04:48:41 +08:00
|
|
|
for(dir=dirnames;*dir;dir++) {
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
for(rcname=rcfilenames;*rcname;rcname++) {
|
|
|
|
ret = rcsearch(*dir,*rcname,&path);
|
|
|
|
if(ret == NC_NOERR && path != NULL)
|
|
|
|
nclistpush(rcfileorder,path);
|
2022-01-25 04:48:41 +08:00
|
|
|
path = NULL;
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
}
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
}
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
for(i=0;i<nclistlength(rcfileorder);i++) {
|
|
|
|
path = (char*)nclistget(rcfileorder,i);
|
|
|
|
if((ret=rccompile(path))) {
|
|
|
|
nclog(NCLOGWARN, "Error parsing %s\n",path);
|
|
|
|
ret = NC_NOERR; /* ignore it */
|
2017-08-31 07:44:57 +08:00
|
|
|
goto done;
|
|
|
|
}
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
done:
|
2022-01-30 06:27:52 +08:00
|
|
|
globalstate->rcinfo->loaded = 1; /* even if not exists */
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
nclistfreeall(rcfileorder);
|
2017-08-31 07:44:57 +08:00
|
|
|
return (ret);
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
/**
|
2022-06-18 04:35:12 +08:00
|
|
|
* Locate a entry by property key and host+port (may be null)
|
2017-08-31 07:44:57 +08:00
|
|
|
* If duplicate keys, first takes precedence.
|
|
|
|
*/
|
|
|
|
char*
|
2022-06-18 04:35:12 +08:00
|
|
|
NC_rclookup(const char* key, const char* hostport, const char* urlpath)
|
2017-08-31 07:44:57 +08:00
|
|
|
{
|
2021-09-28 08:36:33 +08:00
|
|
|
struct NCRCentry* entry = NULL;
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
if(!NCRCinitialized) ncrc_initialize();
|
2022-06-18 04:35:12 +08:00
|
|
|
entry = rclocate(key,hostport,urlpath);
|
2021-09-28 08:36:33 +08:00
|
|
|
return (entry == NULL ? NULL : entry->value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Locate a entry by property key and uri.
|
|
|
|
* If duplicate keys, first takes precedence.
|
|
|
|
*/
|
|
|
|
char*
|
|
|
|
NC_rclookupx(NCURI* uri, const char* key)
|
|
|
|
{
|
|
|
|
char* hostport = NULL;
|
|
|
|
char* result = NULL;
|
|
|
|
|
|
|
|
hostport = NC_combinehostport(uri);
|
|
|
|
result = NC_rclookup(key,hostport,uri->path);
|
|
|
|
nullfree(hostport);
|
|
|
|
return result;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
#if 0
|
2017-08-31 07:44:57 +08:00
|
|
|
/*!
|
|
|
|
Set the absolute path to use for the rc file.
|
|
|
|
WARNING: this MUST be called before any other
|
|
|
|
call in order for this to take effect.
|
2017-03-09 08:01:10 +08:00
|
|
|
|
2022-06-18 04:35:12 +08:00
|
|
|
\param[in] rcfile The path to use. If NULL then do not use any rcfile.
|
2017-08-31 07:44:57 +08:00
|
|
|
|
|
|
|
\retval OC_NOERR if the request succeeded.
|
|
|
|
\retval OC_ERCFILE if the file failed to load
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
NC_set_rcfile(const char* rcfile)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
FILE* f = NULL;
|
2022-01-30 06:27:52 +08:00
|
|
|
NCglobalstate* globalstate = NC_getglobalstate();
|
2017-08-31 07:44:57 +08:00
|
|
|
|
|
|
|
if(rcfile != NULL && strlen(rcfile) == 0)
|
|
|
|
rcfile = NULL;
|
|
|
|
f = NCfopen(rcfile,"r");
|
|
|
|
if(f == NULL) {
|
|
|
|
stat = NC_ERCFILE;
|
|
|
|
goto done;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
2017-08-31 07:44:57 +08:00
|
|
|
fclose(f);
|
2022-01-30 06:27:52 +08:00
|
|
|
nullfree(globalstate->rcinfo->rcfile);
|
|
|
|
globalstate->rcinfo->rcfile = strdup(rcfile);
|
2019-03-31 04:06:20 +08:00
|
|
|
/* Clear globalstate->rcinfo */
|
|
|
|
NC_rcclear(&globalstate->rcinfo);
|
2021-09-28 08:36:33 +08:00
|
|
|
/* (re) load the rcfile and esp the entriestore*/
|
2017-08-31 07:44:57 +08:00
|
|
|
stat = NC_rcload();
|
|
|
|
done:
|
|
|
|
return stat;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
#endif
|
2017-03-09 08:01:10 +08:00
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
/**************************************************/
|
|
|
|
/* RC processing functions */
|
|
|
|
|
|
|
|
static char*
|
|
|
|
rcreadline(char** nextlinep)
|
2017-03-09 08:01:10 +08:00
|
|
|
{
|
2017-08-31 07:44:57 +08:00
|
|
|
char* line;
|
|
|
|
char* p;
|
|
|
|
|
|
|
|
line = (p = *nextlinep);
|
|
|
|
if(*p == '\0') return NULL; /*signal done*/
|
|
|
|
for(;*p;p++) {
|
|
|
|
if(*p == '\r' && p[1] == '\n') *p = '\0';
|
|
|
|
else if(*p == '\n') break;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
2017-08-31 07:44:57 +08:00
|
|
|
*p++ = '\0'; /* null terminate line; overwrite newline */
|
|
|
|
*nextlinep = p;
|
|
|
|
return line;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
/* Trim TRIMCHARS from both ends of text; */
|
2017-03-09 08:01:10 +08:00
|
|
|
static void
|
2017-08-31 07:44:57 +08:00
|
|
|
rctrim(char* text)
|
2017-03-09 08:01:10 +08:00
|
|
|
{
|
2022-06-18 04:35:12 +08:00
|
|
|
char* p;
|
|
|
|
char* q;
|
2018-06-08 06:17:32 +08:00
|
|
|
size_t len = 0;
|
2017-08-31 07:44:57 +08:00
|
|
|
int i;
|
|
|
|
|
2022-06-18 04:35:12 +08:00
|
|
|
if(text == NULL || *text == '\0') return;
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
len = strlen(text);
|
2022-06-18 04:35:12 +08:00
|
|
|
|
|
|
|
/* elide upto first non-trimchar */
|
|
|
|
for(q=text,p=text;*p;p++) {
|
|
|
|
if(*p != ' ' && *p != '\t' && *p != '\r') {*q++ = *p;}
|
|
|
|
}
|
|
|
|
len = strlen(p);
|
2017-08-31 07:44:57 +08:00
|
|
|
/* locate last non-trimchar */
|
|
|
|
if(len > 0) {
|
|
|
|
for(i=(len-1);i>=0;i--) {
|
2022-06-18 04:35:12 +08:00
|
|
|
p = &text[i];
|
|
|
|
if(*p != ' ' && *p != '\t' && *p != '\r') {break;}
|
|
|
|
*p = '\0'; /* elide trailing trimchars */
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
2017-08-31 07:44:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-28 08:36:33 +08:00
|
|
|
/* Order the entries: those with urls must be first,
|
2017-08-31 07:44:57 +08:00
|
|
|
but otherwise relative order does not matter.
|
|
|
|
*/
|
2018-02-09 10:53:40 +08:00
|
|
|
static void
|
2017-08-31 07:44:57 +08:00
|
|
|
rcorder(NClist* rc)
|
|
|
|
{
|
2017-11-09 21:24:18 +08:00
|
|
|
int i;
|
2017-08-31 07:44:57 +08:00
|
|
|
int len = nclistlength(rc);
|
2018-05-19 10:28:51 +08:00
|
|
|
NClist* tmprc = NULL;
|
2018-02-09 10:53:40 +08:00
|
|
|
if(rc == NULL || len == 0) return;
|
2018-05-19 10:28:51 +08:00
|
|
|
tmprc = nclistnew();
|
2021-09-28 08:36:33 +08:00
|
|
|
/* Two passes: 1) pull entries with host */
|
2018-02-09 10:53:40 +08:00
|
|
|
for(i=0;i<len;i++) {
|
2022-06-18 04:35:12 +08:00
|
|
|
NCRCentry* ti = nclistget(rc,i);
|
2017-08-31 07:44:57 +08:00
|
|
|
if(ti->host == NULL) continue;
|
2022-06-18 04:35:12 +08:00
|
|
|
nclistpush(tmprc,ti);
|
2017-08-31 07:44:57 +08:00
|
|
|
}
|
2021-09-28 08:36:33 +08:00
|
|
|
/* pass 2 pull entries without host*/
|
2017-08-31 07:44:57 +08:00
|
|
|
for(i=0;i<len;i++) {
|
2022-06-18 04:35:12 +08:00
|
|
|
NCRCentry* ti = nclistget(rc,i);
|
2017-08-31 07:44:57 +08:00
|
|
|
if(ti->host != NULL) continue;
|
2022-06-18 04:35:12 +08:00
|
|
|
nclistpush(tmprc,ti);
|
|
|
|
}
|
|
|
|
/* Move tmp to rc */
|
|
|
|
nclistsetlength(rc,0);
|
|
|
|
for(i=0;i<len;i++) {
|
|
|
|
NCRCentry* ti = nclistget(tmprc,i);
|
2018-02-09 10:53:40 +08:00
|
|
|
nclistpush(rc,ti);
|
2017-08-31 07:44:57 +08:00
|
|
|
}
|
2021-09-28 08:36:33 +08:00
|
|
|
#ifdef DRCDEBUG
|
2018-02-09 10:53:40 +08:00
|
|
|
storedump("reorder:",rc);
|
2017-08-31 07:44:57 +08:00
|
|
|
#endif
|
2018-02-09 10:53:40 +08:00
|
|
|
nclistfree(tmprc);
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
2021-09-28 08:36:33 +08:00
|
|
|
/* Merge a entry store from a file*/
|
2017-03-09 08:01:10 +08:00
|
|
|
static int
|
2022-06-18 04:35:12 +08:00
|
|
|
rccompile(const char* filepath)
|
2017-03-09 08:01:10 +08:00
|
|
|
{
|
2017-08-31 07:44:57 +08:00
|
|
|
int ret = NC_NOERR;
|
2018-02-09 10:53:40 +08:00
|
|
|
NClist* rc = NULL;
|
2017-08-31 07:44:57 +08:00
|
|
|
char* contents = NULL;
|
|
|
|
NCbytes* tmp = ncbytesnew();
|
|
|
|
NCURI* uri = NULL;
|
|
|
|
char* nextline = NULL;
|
2022-01-30 06:27:52 +08:00
|
|
|
NCglobalstate* globalstate = NC_getglobalstate();
|
2023-10-09 01:22:52 +08:00
|
|
|
NCS3INFO s3;
|
|
|
|
|
|
|
|
memset(&s3,0,sizeof(s3));
|
2017-08-31 07:44:57 +08:00
|
|
|
|
2022-06-18 04:35:12 +08:00
|
|
|
if((ret=NC_readfile(filepath,tmp))) {
|
|
|
|
nclog(NCLOGWARN, "Could not open configuration file: %s",filepath);
|
2018-06-08 06:17:32 +08:00
|
|
|
goto done;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
2017-08-31 07:44:57 +08:00
|
|
|
contents = ncbytesextract(tmp);
|
|
|
|
if(contents == NULL) contents = strdup("");
|
2018-02-09 10:53:40 +08:00
|
|
|
/* Either reuse or create new */
|
2022-01-30 06:27:52 +08:00
|
|
|
rc = globalstate->rcinfo->entries;
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
if(rc == NULL) {
|
2018-02-09 10:53:40 +08:00
|
|
|
rc = nclistnew();
|
2022-01-30 06:27:52 +08:00
|
|
|
globalstate->rcinfo->entries = rc;
|
2018-02-09 10:53:40 +08:00
|
|
|
}
|
2017-08-31 07:44:57 +08:00
|
|
|
nextline = contents;
|
2017-03-09 08:01:10 +08:00
|
|
|
for(;;) {
|
|
|
|
char* line;
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
char* key = NULL;
|
|
|
|
char* value = NULL;
|
|
|
|
char* host = NULL;
|
2022-06-18 04:35:12 +08:00
|
|
|
char* urlpath = NULL;
|
2017-08-31 07:44:57 +08:00
|
|
|
size_t llen;
|
2021-09-28 08:36:33 +08:00
|
|
|
NCRCentry* entry;
|
2017-08-31 07:44:57 +08:00
|
|
|
|
|
|
|
line = rcreadline(&nextline);
|
|
|
|
if(line == NULL) break; /* done */
|
|
|
|
rctrim(line); /* trim leading and trailing blanks */
|
|
|
|
if(line[0] == '#') continue; /* comment */
|
|
|
|
if((llen=strlen(line)) == 0) continue; /* empty line */
|
2018-10-02 05:51:43 +08:00
|
|
|
if(line[0] == LTAG) {
|
|
|
|
char* url = ++line;
|
|
|
|
char* rtag = strchr(line,RTAG);
|
|
|
|
if(rtag == NULL) {
|
2022-06-18 04:35:12 +08:00
|
|
|
nclog(NCLOGERR, "Malformed [url] in %s entry: %s",filepath,line);
|
2017-08-31 07:44:57 +08:00
|
|
|
continue;
|
2018-10-02 05:51:43 +08:00
|
|
|
}
|
|
|
|
line = rtag + 1;
|
|
|
|
*rtag = '\0';
|
2021-09-28 08:36:33 +08:00
|
|
|
/* compile the url and pull out the host and protocol */
|
2018-10-02 05:51:43 +08:00
|
|
|
if(uri) ncurifree(uri);
|
2019-09-30 02:59:28 +08:00
|
|
|
if(ncuriparse(url,&uri)) {
|
2022-06-18 04:35:12 +08:00
|
|
|
nclog(NCLOGERR, "Malformed [url] in %s entry: %s",filepath,line);
|
2018-10-02 05:51:43 +08:00
|
|
|
continue;
|
|
|
|
}
|
2023-03-03 10:51:02 +08:00
|
|
|
if(NC_iss3(uri)) {
|
|
|
|
NCURI* newuri = NULL;
|
2022-06-18 04:35:12 +08:00
|
|
|
/* Rebuild the url to S3 "path" format */
|
2023-10-09 01:22:52 +08:00
|
|
|
NC_s3clear(&s3);
|
|
|
|
if((ret = NC_s3urlrebuild(uri,&s3,&newuri))) goto done;
|
2021-09-28 08:36:33 +08:00
|
|
|
ncurifree(uri);
|
|
|
|
uri = newuri;
|
|
|
|
newuri = NULL;
|
|
|
|
}
|
2022-06-18 04:35:12 +08:00
|
|
|
/* Get the host+port */
|
2018-10-02 05:51:43 +08:00
|
|
|
ncbytesclear(tmp);
|
|
|
|
ncbytescat(tmp,uri->host);
|
|
|
|
if(uri->port != NULL) {
|
2017-08-31 07:44:57 +08:00
|
|
|
ncbytesappend(tmp,':');
|
2018-10-02 05:51:43 +08:00
|
|
|
ncbytescat(tmp,uri->port);
|
|
|
|
}
|
|
|
|
ncbytesnull(tmp);
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
host = ncbytesextract(tmp);
|
2022-06-18 04:35:12 +08:00
|
|
|
if(strlen(host)==0) /* nullify host */
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
{free(host); host = NULL;}
|
2022-06-18 04:35:12 +08:00
|
|
|
/* Get the url path part */
|
|
|
|
urlpath = uri->path;
|
|
|
|
if(urlpath && strlen(urlpath)==0) urlpath = NULL; /* nullify */
|
2018-10-02 05:51:43 +08:00
|
|
|
}
|
2017-03-09 08:01:10 +08:00
|
|
|
/* split off key and value */
|
2017-08-31 07:44:57 +08:00
|
|
|
key=line;
|
2017-03-09 08:01:10 +08:00
|
|
|
value = strchr(line, '=');
|
|
|
|
if(value == NULL)
|
|
|
|
value = line + strlen(line);
|
|
|
|
else {
|
|
|
|
*value = '\0';
|
|
|
|
value++;
|
|
|
|
}
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
/* See if key already exists */
|
2022-06-18 04:35:12 +08:00
|
|
|
entry = rclocate(key,host,urlpath);
|
|
|
|
if(entry == NULL) {
|
2021-09-28 08:36:33 +08:00
|
|
|
entry = (NCRCentry*)calloc(1,sizeof(NCRCentry));
|
|
|
|
if(entry == NULL) {ret = NC_ENOMEM; goto done;}
|
|
|
|
nclistpush(rc,entry);
|
2022-06-18 04:35:12 +08:00
|
|
|
entry->host = host; host = NULL;
|
|
|
|
entry->urlpath = nulldup(urlpath);
|
|
|
|
entry->key = nulldup(key);
|
|
|
|
rctrim(entry->host);
|
|
|
|
rctrim(entry->urlpath);
|
|
|
|
rctrim(entry->key);
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
}
|
2022-06-18 04:35:12 +08:00
|
|
|
nullfree(entry->value);
|
2021-09-28 08:36:33 +08:00
|
|
|
entry->value = nulldup(value);
|
|
|
|
rctrim(entry->value);
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
|
2021-04-26 12:02:29 +08:00
|
|
|
#ifdef DRCDEBUG
|
2022-06-18 04:35:12 +08:00
|
|
|
fprintf(stderr,"rc: host=%s urlpath=%s key=%s value=%s\n",
|
2021-09-28 08:36:33 +08:00
|
|
|
(entry->host != NULL ? entry->host : "<null>"),
|
2022-06-18 04:35:12 +08:00
|
|
|
(entry->urlpath != NULL ? entry->urlpath : "<null>"),
|
2021-09-28 08:36:33 +08:00
|
|
|
entry->key,entry->value);
|
2017-08-31 07:44:57 +08:00
|
|
|
#endif
|
2021-09-28 08:36:33 +08:00
|
|
|
entry = NULL;
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
2022-06-18 04:35:12 +08:00
|
|
|
#ifdef DRCDEBUG
|
|
|
|
fprintf(stderr,"reorder.path=%s\n",filepath);
|
|
|
|
#endif
|
2017-08-31 07:44:57 +08:00
|
|
|
rcorder(rc);
|
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
done:
|
2023-10-09 01:22:52 +08:00
|
|
|
NC_s3clear(&s3);
|
2018-02-09 10:53:40 +08:00
|
|
|
if(contents) free(contents);
|
2017-08-31 07:44:57 +08:00
|
|
|
ncurifree(uri);
|
|
|
|
ncbytesfree(tmp);
|
|
|
|
return (ret);
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
2017-08-31 07:44:57 +08:00
|
|
|
/**
|
2022-06-18 04:35:12 +08:00
|
|
|
Encapsulate equality comparison: return 1|0
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
rcequal(NCRCentry* e1, NCRCentry* e2)
|
|
|
|
{
|
|
|
|
int nulltest;
|
|
|
|
if(e1->key == NULL || e2->key == NULL) return 0;
|
|
|
|
if(strcmp(e1->key,e2->key) != 0) return 0;
|
|
|
|
/* test hostport; take NULL into account*/
|
|
|
|
nulltest = 0;
|
|
|
|
if(e1->host == NULL) nulltest |= 1;
|
|
|
|
if(e2->host == NULL) nulltest |= 2;
|
2023-04-30 05:02:59 +08:00
|
|
|
/* Use host to decide if entry applies */
|
2022-06-18 04:35:12 +08:00
|
|
|
switch (nulltest) {
|
|
|
|
case 0: if(strcmp(e1->host,e2->host) != 0) {return 0;} break;
|
2023-04-30 05:02:59 +08:00
|
|
|
case 1: break; /* .rc->host == NULL && candidate->host != NULL */
|
|
|
|
case 2: return 0; /* .rc->host != NULL && candidate->host == NULL */
|
|
|
|
case 3: break; /* .rc->host == NULL && candidate->host == NULL */
|
2022-06-18 04:35:12 +08:00
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
/* test urlpath take NULL into account*/
|
|
|
|
nulltest = 0;
|
|
|
|
if(e1->urlpath == NULL) nulltest |= 1;
|
|
|
|
if(e2->urlpath == NULL) nulltest |= 2;
|
|
|
|
switch (nulltest) {
|
|
|
|
case 0: if(strcmp(e1->urlpath,e2->urlpath) != 0) {return 0;} break;
|
2023-04-30 05:02:59 +08:00
|
|
|
case 1: break; /* .rc->urlpath == NULL && candidate->urlpath != NULL */
|
|
|
|
case 2: return 0; /* .rc->urlpath != NULL && candidate->urlpath == NULL */
|
|
|
|
case 3: break; /* .rc->urlpath == NULL && candidate->urlpath == NULL */
|
2022-06-18 04:35:12 +08:00
|
|
|
default: return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* (Internal) Locate a entry by property key and host+port (may be null) and urlpath (may be null)
|
2017-08-31 07:44:57 +08:00
|
|
|
* If duplicate keys, first takes precedence.
|
|
|
|
*/
|
2022-06-18 04:35:12 +08:00
|
|
|
static int
|
|
|
|
rclocatepos(const char* key, const char* hostport, const char* urlpath)
|
2017-08-31 07:44:57 +08:00
|
|
|
{
|
2022-06-18 04:35:12 +08:00
|
|
|
int i;
|
2022-01-30 06:27:52 +08:00
|
|
|
NCglobalstate* globalstate = NC_getglobalstate();
|
2022-06-18 04:35:12 +08:00
|
|
|
struct NCRCinfo* info = globalstate->rcinfo;
|
2021-09-28 08:36:33 +08:00
|
|
|
NCRCentry* entry = NULL;
|
2022-06-18 04:35:12 +08:00
|
|
|
NCRCentry candidate;
|
|
|
|
NClist* rc = info->entries;
|
2017-08-31 07:44:57 +08:00
|
|
|
|
2022-06-18 04:35:12 +08:00
|
|
|
if(info->ignore) return -1;
|
2017-08-31 07:44:57 +08:00
|
|
|
|
2022-06-18 04:35:12 +08:00
|
|
|
candidate.key = (char*)key;
|
|
|
|
candidate.value = (char*)NULL;
|
|
|
|
candidate.host = (char*)hostport;
|
|
|
|
candidate.urlpath = (char*)urlpath;
|
2017-08-31 07:44:57 +08:00
|
|
|
|
2022-06-18 04:35:12 +08:00
|
|
|
for(i=0;i<nclistlength(rc);i++) {
|
2021-09-28 08:36:33 +08:00
|
|
|
entry = (NCRCentry*)nclistget(rc,i);
|
2022-06-18 04:35:12 +08:00
|
|
|
if(rcequal(entry,&candidate)) return i;
|
2017-08-31 07:44:57 +08:00
|
|
|
}
|
2022-06-18 04:35:12 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* (Internal) Locate a entry by property key and host+port (may be null or "").
|
|
|
|
* If duplicate keys, first takes precedence.
|
|
|
|
*/
|
|
|
|
static struct NCRCentry*
|
|
|
|
rclocate(const char* key, const char* hostport, const char* urlpath)
|
|
|
|
{
|
|
|
|
int pos;
|
|
|
|
NCglobalstate* globalstate = NC_getglobalstate();
|
|
|
|
struct NCRCinfo* info = globalstate->rcinfo;
|
|
|
|
|
|
|
|
if(globalstate->rcinfo->ignore) return NULL;
|
|
|
|
if(key == NULL || info == NULL) return NULL;
|
|
|
|
pos = rclocatepos(key,hostport,urlpath);
|
|
|
|
if(pos < 0) return NULL;
|
|
|
|
return NC_rcfile_ith(info,(size_t)pos);
|
2017-08-31 07:44:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Locate rc file by searching in directory prefix.
|
|
|
|
*/
|
|
|
|
static
|
|
|
|
int
|
|
|
|
rcsearch(const char* prefix, const char* rcname, char** pathp)
|
2017-03-09 08:01:10 +08:00
|
|
|
{
|
|
|
|
char* path = NULL;
|
|
|
|
FILE* f = NULL;
|
2019-10-25 04:28:39 +08:00
|
|
|
size_t plen = (prefix?strlen(prefix):0);
|
2019-01-12 02:41:09 +08:00
|
|
|
size_t rclen = strlen(rcname);
|
2017-08-31 07:44:57 +08:00
|
|
|
int ret = NC_NOERR;
|
|
|
|
|
2021-05-15 01:33:03 +08:00
|
|
|
size_t pathlen = plen+rclen+1+1; /*+1 for '/' +1 for nul */
|
|
|
|
path = (char*)malloc(pathlen); /* +1 for nul*/
|
2017-08-31 07:44:57 +08:00
|
|
|
if(path == NULL) {ret = NC_ENOMEM; goto done;}
|
2021-07-28 06:08:04 +08:00
|
|
|
snprintf(path, pathlen, "%s/%s", prefix, rcname);
|
2017-03-09 08:01:10 +08:00
|
|
|
/* see if file is readable */
|
Codify cross-platform file paths
The netcdf-c code has to deal with a variety of platforms:
Windows, OSX, Linux, Cygwin, MSYS, etc. These platforms differ
significantly in the kind of file paths that they accept. So in
order to handle this, I have created a set of replacements for
the most common file system operations such as _open_ or _fopen_
or _access_ to manage the file path differences correctly.
A more limited version of this idea was already implemented via
the ncwinpath.h and dwinpath.c code. So this can be viewed as a
replacement for that code. And in path in many cases, the only
change that was required was to replace '#include <ncwinpath.h>'
with '#include <ncpathmgt.h>' and then replace file operation
calls with the NCxxx equivalent from ncpathmgr.h Note that
recently, the ncwinpath.h was renamed ncpathmgmt.h, so this pull
request should not require dealing with winpath.
The heart of the change is include/ncpathmgmt.h, which provides
alternate operations such as NCfopen or NCaccess and which properly
parse and rebuild path arguments to work for the platform on which
the code is executing. This mostly matters for Windows because of the
way that it uses backslash and drive letters, as compared to *nix*.
One important feature is that the user can do string manipulations
on a file path without having to worry too much about the platform
because the path management code will properly handle most mixed cases.
So one can for example concatenate a path suffix that uses forward
slashes to a Windows path and have it work correctly.
The conversion code is in libdispatch/dpathmgr.c, and the
important function there is NCpathcvt which does the proper
conversions to the local path format.
As a rule, most code should just replace their file operations with
the corresponding NCxxx ones defined in include/ncpathmgmt.h. These
NCxxx functions all call NCpathcvt on their path arguments before
executing the actual file operation.
In some rare cases, the client may need to directly use NCpathcvt,
but this should be avoided as much as possible. If there is a need
for supporting a new file operation not already in ncpathmgmt.h, then
use the code in dpathmgr.c as a template. Also please notify Unidata
so we can include it as a formal part or our supported operations.
Also, if you see an operation in the library that is not using the
NCxxx form, then please submit an issue so we can fix it.
Misc. Changes:
* Clean up the utf8 testing code; it is impossible to get some
tests to work under windows using shell scripts; the args do
not pass as utf8 but as some other encoding.
* Added an extra utf8 test case: test_unicode_path.sh
* Add a true test for HDF5 1.10.6 or later because as noted in
PR https://github.com/Unidata/netcdf-c/pull/1794,
HDF5 changed its Windows file path handling.
2021-03-05 04:41:31 +08:00
|
|
|
f = NCfopen(path,"r");
|
2017-03-09 08:01:10 +08:00
|
|
|
if(f != NULL)
|
Mitigate S3 test interference + Unlimited Dimensions in NCZarr
This PR started as an attempt to add unlimited dimensions to NCZarr.
It did that, but this exposed significant problems with test interference.
So this PR is mostly about fixing -- well mitigating anyway -- test
interference.
The problem of test interference is now documented in the document docs/internal.md.
The solutions implemented here are also describe in that document.
The solution is somewhat fragile but multiple cleanup mechanisms
are provided. Note that this feature requires that the
AWS command line utility must be installed.
## Unlimited Dimensions.
The existing NCZarr extensions to Zarr are modified to support unlimited dimensions.
NCzarr extends the Zarr meta-data for the ".zgroup" object to include netcdf-4 model extensions. This information is stored in ".zgroup" as dictionary named "_nczarr_group".
Inside "_nczarr_group", there is a key named "dims" that stores information about netcdf-4 named dimensions. The value of "dims" is a dictionary whose keys are the named dimensions. The value associated with each dimension name has one of two forms
Form 1 is a special case of form 2, and is kept for backward compatibility. Whenever a new file is written, it uses format 1 if possible, otherwise format 2.
* Form 1: An integer representing the size of the dimension, which is used for simple named dimensions.
* Form 2: A dictionary with the following keys and values"
- "size" with an integer value representing the (current) size of the dimension.
- "unlimited" with a value of either "1" or "0" to indicate if this dimension is an unlimited dimension.
For Unlimited dimensions, the size is initially zero, and as variables extend the length of that dimension, the size value for the dimension increases.
That dimension size is shared by all arrays referencing that dimension, so if one array extends an unlimited dimension, it is implicitly extended for all other arrays that reference that dimension.
This is the standard semantics for unlimited dimensions.
Adding unlimited dimensions required a number of other changes to the NCZarr code-base. These included the following.
* Did a partial refactor of the slice handling code in zwalk.c to clean it up.
* Added a number of tests for unlimited dimensions derived from the same test in nc_test4.
* Added several NCZarr specific unlimited tests; more are needed.
* Add test of endianness.
## Misc. Other Changes
* Modify libdispatch/ncs3sdk_aws.cpp to optionally support use of the
AWS Transfer Utility mechanism. This is controlled by the
```#define TRANSFER```` command in that file. It defaults to being disabled.
* Parameterize both the standard Unidata S3 bucket (S3TESTBUCKET) and the netcdf-c test data prefix (S3TESTSUBTREE).
* Fixed an obscure memory leak in ncdump.
* Removed some obsolete unit testing code and test cases.
* Uncovered a bug in the netcdf-c handling of big-endian floats and doubles. Have not fixed yet. See tst_h5_endians.c.
* Renamed some nczarr_tests testcases to avoid name conflicts with nc_test4.
* Modify the semantics of zmap\#ncsmap_write to only allow total rewrite of objects.
* Modify the semantics of zodom to properly handle stride > 1.
* Add a truncate operation to the libnczarr zmap code.
2023-09-27 06:56:48 +08:00
|
|
|
nclog(NCLOGNOTE, "Found rc file=%s",path);
|
2017-03-09 08:01:10 +08:00
|
|
|
done:
|
2017-08-31 07:44:57 +08:00
|
|
|
if(f == NULL || ret != NC_NOERR) {
|
|
|
|
nullfree(path);
|
2017-03-09 08:01:10 +08:00
|
|
|
path = NULL;
|
|
|
|
}
|
|
|
|
if(f != NULL)
|
2017-08-31 07:44:57 +08:00
|
|
|
fclose(f);
|
2017-03-09 08:01:10 +08:00
|
|
|
if(pathp != NULL)
|
2017-08-31 07:44:57 +08:00
|
|
|
*pathp = path;
|
|
|
|
else {
|
|
|
|
nullfree(path);
|
|
|
|
path = NULL;
|
|
|
|
}
|
2021-09-03 07:04:26 +08:00
|
|
|
errno = 0; /* silently ignore errors */
|
2017-08-31 07:44:57 +08:00
|
|
|
return (ret);
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
|
|
|
|
2018-08-27 07:04:46 +08:00
|
|
|
int
|
2022-06-18 04:35:12 +08:00
|
|
|
NC_rcfile_insert(const char* key, const char* hostport, const char* urlpath, const char* value)
|
2018-08-27 07:04:46 +08:00
|
|
|
{
|
|
|
|
int ret = NC_NOERR;
|
|
|
|
/* See if this key already defined */
|
2021-09-28 08:36:33 +08:00
|
|
|
struct NCRCentry* entry = NULL;
|
2022-01-30 06:27:52 +08:00
|
|
|
NCglobalstate* globalstate = NULL;
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
NClist* rc = NULL;
|
2018-08-27 07:04:46 +08:00
|
|
|
|
Upgrade the nczarr code to match Zarr V2
Re: https://github.com/zarr-developers/zarr-python/pull/716
The Zarr version 2 spec has been extended to include the ability
to choose the dimension separator in chunk name keys. The legal
separators has been extended from {'.'} to {'.' '/'}. So now it
is possible to use a key like "0/1/2/0" for chunk names.
This PR implements this for NCZarr. The V2 spec now says that
this separator can be set on a per-variable basis. For now, I
have chosen to allow this be set only globally by adding a key
named "ZARR.DIMENSION_SEPARATOR=<char>" in the
.daprc/.dodsrc/ncrc file. Currently, the only legal separator
characters are '.' (the default) and '/'. On writing, this key
will only be written if its value is different than the default.
This change caused problems because supporting a separator of '/'
is difficult to parse when keys/paths use '/' as the path separator.
A test case was added for this.
Additionally, make nczarr be enabled default by default. This required
some additional changes so that if zip and/or AWS S3 sdk are unavailable,
then they are disabled for NCZarr.
In addition the following unrelated changes were made.
1. Tested that pure-zarr mode could read an nczarr formatted store.
1. The .rc file handling now merges all known .rc files (.ncrc,.daprc, and .dodsrc) in that order and using those in HOME first, then in current directory. For duplicate entries, the later ones override the earlier ones. This change is to remove some of the conflicts inherent in the current .rc file load process. A set of test cases was also added.
1. Re-order tests in configure.ac and CMakeLists.txt so that if libcurl
is not found then the other options that depend upon it properly
are disabled.
1. I decided that xarray support should be enabled by default for pure
zarr. In order to allow disabling, I added a new mode flag "noxarray".
1. Certain test in nczarr_test depend on use of .dodsrc. In order for these
to work when testing in parallel, some inter-test dependencies needed to
be added.
1. Improved authorization testing to use changes in thredds.ucar.edu
2021-04-25 09:48:15 +08:00
|
|
|
if(!NCRCinitialized) ncrc_initialize();
|
2022-06-18 04:35:12 +08:00
|
|
|
|
|
|
|
if(key == NULL || value == NULL)
|
|
|
|
{ret = NC_EINVAL; goto done;}
|
|
|
|
|
2022-01-30 06:27:52 +08:00
|
|
|
globalstate = NC_getglobalstate();
|
|
|
|
rc = globalstate->rcinfo->entries;
|
2022-01-25 04:48:41 +08:00
|
|
|
|
2018-08-27 07:04:46 +08:00
|
|
|
if(rc == NULL) {
|
|
|
|
rc = nclistnew();
|
2022-05-20 02:28:43 +08:00
|
|
|
globalstate->rcinfo->entries = rc;
|
2018-08-27 07:04:46 +08:00
|
|
|
if(rc == NULL) {ret = NC_ENOMEM; goto done;}
|
|
|
|
}
|
2022-06-18 04:35:12 +08:00
|
|
|
entry = rclocate(key,hostport,urlpath);
|
2021-09-28 08:36:33 +08:00
|
|
|
if(entry == NULL) {
|
|
|
|
entry = (NCRCentry*)calloc(1,sizeof(NCRCentry));
|
|
|
|
if(entry == NULL) {ret = NC_ENOMEM; goto done;}
|
|
|
|
entry->key = strdup(key);
|
|
|
|
entry->value = NULL;
|
|
|
|
rctrim(entry->key);
|
2022-06-18 04:35:12 +08:00
|
|
|
entry->host = nulldup(hostport);
|
|
|
|
rctrim(entry->host);
|
|
|
|
entry->urlpath = nulldup(urlpath);
|
|
|
|
rctrim(entry->urlpath);
|
2021-09-28 08:36:33 +08:00
|
|
|
nclistpush(rc,entry);
|
|
|
|
}
|
|
|
|
if(entry->value != NULL) free(entry->value);
|
|
|
|
entry->value = strdup(value);
|
|
|
|
rctrim(entry->value);
|
2022-06-18 04:35:12 +08:00
|
|
|
#ifdef DRCDEBUG
|
|
|
|
storedump("NC_rcfile_insert",rc);
|
|
|
|
#endif
|
2018-08-27 07:04:46 +08:00
|
|
|
done:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-09-28 08:36:33 +08:00
|
|
|
/* Obtain the count of number of entries */
|
Provide byte-range reading of remote datasets
re: issue https://github.com/Unidata/netcdf-c/issues/1251
Assume that you have the URL to a remote dataset
which is a normal netcdf-3 or netcdf-4 file.
This PR allows the netcdf-c to read that dataset's
contents as a netcdf file using HTTP byte ranges
if the remote server supports byte-range access.
Originally, this PR was set up to access Amazon S3 objects,
but it can also access other remote datasets such as those
provided by a Thredds server via the HTTPServer access protocol.
It may also work for other kinds of servers.
Note that this is not intended as a true production
capability because, as is known, this kind of access to
can be quite slow. In addition, the byte-range IO drivers
do not currently do any sort of optimization or caching.
An additional goal here is to gain some experience with
the Amazon S3 REST protocol.
This architecture and its use documented in
the file docs/byterange.dox.
There are currently two test cases:
1. nc_test/tst_s3raw.c - this does a simple open, check format, close cycle
for a remote netcdf-3 file and a remote netcdf-4 file.
2. nc_test/test_s3raw.sh - this uses ncdump to investigate some remote
datasets.
This PR also incorporates significantly changed model inference code
(see the superceded PR https://github.com/Unidata/netcdf-c/pull/1259).
1. It centralizes the code that infers the dispatcher.
2. It adds support for byte-range URLs
Other changes:
1. NC_HDF5_finalize was not being properly called by nc_finalize().
2. Fix minor bug in ncgen3.l
3. fix memory leak in nc4info.c
4. add code to walk the .daprc triples and to replace protocol=
fragment tag with a more general mode= tag.
Final Note:
Th inference code is still way too complicated. We need to move
to the validfile() model used by netcdf Java, where each
dispatcher is asked if it can process the file. This decentralizes
the inference code. This will be done after all the major new
dispatchers (PIO, Zarr, etc) have been implemented.
2019-01-02 09:27:36 +08:00
|
|
|
size_t
|
|
|
|
NC_rcfile_length(NCRCinfo* info)
|
|
|
|
{
|
2021-09-28 08:36:33 +08:00
|
|
|
return nclistlength(info->entries);
|
Provide byte-range reading of remote datasets
re: issue https://github.com/Unidata/netcdf-c/issues/1251
Assume that you have the URL to a remote dataset
which is a normal netcdf-3 or netcdf-4 file.
This PR allows the netcdf-c to read that dataset's
contents as a netcdf file using HTTP byte ranges
if the remote server supports byte-range access.
Originally, this PR was set up to access Amazon S3 objects,
but it can also access other remote datasets such as those
provided by a Thredds server via the HTTPServer access protocol.
It may also work for other kinds of servers.
Note that this is not intended as a true production
capability because, as is known, this kind of access to
can be quite slow. In addition, the byte-range IO drivers
do not currently do any sort of optimization or caching.
An additional goal here is to gain some experience with
the Amazon S3 REST protocol.
This architecture and its use documented in
the file docs/byterange.dox.
There are currently two test cases:
1. nc_test/tst_s3raw.c - this does a simple open, check format, close cycle
for a remote netcdf-3 file and a remote netcdf-4 file.
2. nc_test/test_s3raw.sh - this uses ncdump to investigate some remote
datasets.
This PR also incorporates significantly changed model inference code
(see the superceded PR https://github.com/Unidata/netcdf-c/pull/1259).
1. It centralizes the code that infers the dispatcher.
2. It adds support for byte-range URLs
Other changes:
1. NC_HDF5_finalize was not being properly called by nc_finalize().
2. Fix minor bug in ncgen3.l
3. fix memory leak in nc4info.c
4. add code to walk the .daprc triples and to replace protocol=
fragment tag with a more general mode= tag.
Final Note:
Th inference code is still way too complicated. We need to move
to the validfile() model used by netcdf Java, where each
dispatcher is asked if it can process the file. This decentralizes
the inference code. This will be done after all the major new
dispatchers (PIO, Zarr, etc) have been implemented.
2019-01-02 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
2021-09-28 08:36:33 +08:00
|
|
|
/* Obtain the ith entry; return NULL if out of range */
|
|
|
|
NCRCentry*
|
Provide byte-range reading of remote datasets
re: issue https://github.com/Unidata/netcdf-c/issues/1251
Assume that you have the URL to a remote dataset
which is a normal netcdf-3 or netcdf-4 file.
This PR allows the netcdf-c to read that dataset's
contents as a netcdf file using HTTP byte ranges
if the remote server supports byte-range access.
Originally, this PR was set up to access Amazon S3 objects,
but it can also access other remote datasets such as those
provided by a Thredds server via the HTTPServer access protocol.
It may also work for other kinds of servers.
Note that this is not intended as a true production
capability because, as is known, this kind of access to
can be quite slow. In addition, the byte-range IO drivers
do not currently do any sort of optimization or caching.
An additional goal here is to gain some experience with
the Amazon S3 REST protocol.
This architecture and its use documented in
the file docs/byterange.dox.
There are currently two test cases:
1. nc_test/tst_s3raw.c - this does a simple open, check format, close cycle
for a remote netcdf-3 file and a remote netcdf-4 file.
2. nc_test/test_s3raw.sh - this uses ncdump to investigate some remote
datasets.
This PR also incorporates significantly changed model inference code
(see the superceded PR https://github.com/Unidata/netcdf-c/pull/1259).
1. It centralizes the code that infers the dispatcher.
2. It adds support for byte-range URLs
Other changes:
1. NC_HDF5_finalize was not being properly called by nc_finalize().
2. Fix minor bug in ncgen3.l
3. fix memory leak in nc4info.c
4. add code to walk the .daprc triples and to replace protocol=
fragment tag with a more general mode= tag.
Final Note:
Th inference code is still way too complicated. We need to move
to the validfile() model used by netcdf Java, where each
dispatcher is asked if it can process the file. This decentralizes
the inference code. This will be done after all the major new
dispatchers (PIO, Zarr, etc) have been implemented.
2019-01-02 09:27:36 +08:00
|
|
|
NC_rcfile_ith(NCRCinfo* info, size_t i)
|
|
|
|
{
|
2021-09-28 08:36:33 +08:00
|
|
|
if(i >= nclistlength(info->entries))
|
Provide byte-range reading of remote datasets
re: issue https://github.com/Unidata/netcdf-c/issues/1251
Assume that you have the URL to a remote dataset
which is a normal netcdf-3 or netcdf-4 file.
This PR allows the netcdf-c to read that dataset's
contents as a netcdf file using HTTP byte ranges
if the remote server supports byte-range access.
Originally, this PR was set up to access Amazon S3 objects,
but it can also access other remote datasets such as those
provided by a Thredds server via the HTTPServer access protocol.
It may also work for other kinds of servers.
Note that this is not intended as a true production
capability because, as is known, this kind of access to
can be quite slow. In addition, the byte-range IO drivers
do not currently do any sort of optimization or caching.
An additional goal here is to gain some experience with
the Amazon S3 REST protocol.
This architecture and its use documented in
the file docs/byterange.dox.
There are currently two test cases:
1. nc_test/tst_s3raw.c - this does a simple open, check format, close cycle
for a remote netcdf-3 file and a remote netcdf-4 file.
2. nc_test/test_s3raw.sh - this uses ncdump to investigate some remote
datasets.
This PR also incorporates significantly changed model inference code
(see the superceded PR https://github.com/Unidata/netcdf-c/pull/1259).
1. It centralizes the code that infers the dispatcher.
2. It adds support for byte-range URLs
Other changes:
1. NC_HDF5_finalize was not being properly called by nc_finalize().
2. Fix minor bug in ncgen3.l
3. fix memory leak in nc4info.c
4. add code to walk the .daprc triples and to replace protocol=
fragment tag with a more general mode= tag.
Final Note:
Th inference code is still way too complicated. We need to move
to the validfile() model used by netcdf Java, where each
dispatcher is asked if it can process the file. This decentralizes
the inference code. This will be done after all the major new
dispatchers (PIO, Zarr, etc) have been implemented.
2019-01-02 09:27:36 +08:00
|
|
|
return NULL;
|
2021-09-28 08:36:33 +08:00
|
|
|
return (NCRCentry*)nclistget(info->entries,i);
|
Provide byte-range reading of remote datasets
re: issue https://github.com/Unidata/netcdf-c/issues/1251
Assume that you have the URL to a remote dataset
which is a normal netcdf-3 or netcdf-4 file.
This PR allows the netcdf-c to read that dataset's
contents as a netcdf file using HTTP byte ranges
if the remote server supports byte-range access.
Originally, this PR was set up to access Amazon S3 objects,
but it can also access other remote datasets such as those
provided by a Thredds server via the HTTPServer access protocol.
It may also work for other kinds of servers.
Note that this is not intended as a true production
capability because, as is known, this kind of access to
can be quite slow. In addition, the byte-range IO drivers
do not currently do any sort of optimization or caching.
An additional goal here is to gain some experience with
the Amazon S3 REST protocol.
This architecture and its use documented in
the file docs/byterange.dox.
There are currently two test cases:
1. nc_test/tst_s3raw.c - this does a simple open, check format, close cycle
for a remote netcdf-3 file and a remote netcdf-4 file.
2. nc_test/test_s3raw.sh - this uses ncdump to investigate some remote
datasets.
This PR also incorporates significantly changed model inference code
(see the superceded PR https://github.com/Unidata/netcdf-c/pull/1259).
1. It centralizes the code that infers the dispatcher.
2. It adds support for byte-range URLs
Other changes:
1. NC_HDF5_finalize was not being properly called by nc_finalize().
2. Fix minor bug in ncgen3.l
3. fix memory leak in nc4info.c
4. add code to walk the .daprc triples and to replace protocol=
fragment tag with a more general mode= tag.
Final Note:
Th inference code is still way too complicated. We need to move
to the validfile() model used by netcdf Java, where each
dispatcher is asked if it can process the file. This decentralizes
the inference code. This will be done after all the major new
dispatchers (PIO, Zarr, etc) have been implemented.
2019-01-02 09:27:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-09-28 08:36:33 +08:00
|
|
|
#ifdef DRCDEBUG
|
2017-08-31 07:44:57 +08:00
|
|
|
static void
|
2021-09-28 08:36:33 +08:00
|
|
|
storedump(char* msg, NClist* entries)
|
2017-08-31 07:44:57 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(msg != NULL) fprintf(stderr,"%s\n",msg);
|
2021-09-28 08:36:33 +08:00
|
|
|
if(entries == NULL || nclistlength(entries)==0) {
|
2017-08-31 07:44:57 +08:00
|
|
|
fprintf(stderr,"<EMPTY>\n");
|
|
|
|
return;
|
|
|
|
}
|
2021-09-28 08:36:33 +08:00
|
|
|
for(i=0;i<nclistlength(entries);i++) {
|
|
|
|
NCRCentry* t = (NCRCentry*)nclistget(entries,i);
|
2017-08-31 07:44:57 +08:00
|
|
|
fprintf(stderr,"\t%s\t%s\t%s\n",
|
|
|
|
((t->host == NULL || strlen(t->host)==0)?"--":t->host),t->key,t->value);
|
|
|
|
}
|
|
|
|
fflush(stderr);
|
2017-03-09 08:01:10 +08:00
|
|
|
}
|
2017-08-31 07:44:57 +08:00
|
|
|
#endif
|
2021-09-28 08:36:33 +08:00
|
|
|
|
|
|
|
/**************************************************/
|
|
|
|
/*
|
|
|
|
Get the current active profile. The priority order is as follows:
|
|
|
|
1. aws.profile key in mode flags
|
|
|
|
2. aws.profile in .rc entries
|
|
|
|
4. "default"
|
2023-05-10 11:13:49 +08:00
|
|
|
5. "no" -- meaning do not use any profile => no secret key
|
2021-09-28 08:36:33 +08:00
|
|
|
|
|
|
|
@param uri uri with mode flags, may be NULL
|
|
|
|
@param profilep return profile name here or NULL if none found
|
|
|
|
@return NC_NOERR if no error.
|
|
|
|
@return NC_EINVAL if something else went wrong.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
NC_getactives3profile(NCURI* uri, const char** profilep)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
const char* profile = NULL;
|
2023-05-10 11:13:49 +08:00
|
|
|
struct AWSprofile* ap = NULL;
|
2021-09-28 08:36:33 +08:00
|
|
|
|
|
|
|
profile = ncurifragmentlookup(uri,"aws.profile");
|
|
|
|
if(profile == NULL)
|
|
|
|
profile = NC_rclookupx(uri,"AWS.PROFILE");
|
2023-05-10 11:13:49 +08:00
|
|
|
|
|
|
|
if(profile == NULL) {
|
|
|
|
if((stat=NC_authgets3profile("default",&ap))) goto done;
|
|
|
|
if(ap) profile = "default";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(profile == NULL) {
|
|
|
|
if((stat=NC_authgets3profile("no",&ap))) goto done;
|
|
|
|
if(ap) profile = "no";
|
|
|
|
}
|
|
|
|
|
2021-09-28 08:36:33 +08:00
|
|
|
#ifdef AWSDEBUG
|
|
|
|
fprintf(stderr,">>> activeprofile = %s\n",(profile?profile:"null"));
|
|
|
|
#endif
|
|
|
|
if(profilep) *profilep = profile;
|
2023-05-10 11:13:49 +08:00
|
|
|
done:
|
2021-09-28 08:36:33 +08:00
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Get the current default region. The search order is as follows:
|
|
|
|
1. aws.region key in mode flags
|
|
|
|
2. aws.region in .rc entries
|
|
|
|
3. aws_region key in current profile (only if profiles are being used)
|
|
|
|
4. "us-east-1"
|
|
|
|
|
|
|
|
@param uri uri with mode flags, may be NULL
|
|
|
|
@param regionp return region name here or NULL if none found
|
|
|
|
@return NC_NOERR if no error.
|
|
|
|
@return NC_EINVAL if something else went wrong.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
NC_getdefaults3region(NCURI* uri, const char** regionp)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
const char* region = NULL;
|
|
|
|
const char* profile = NULL;
|
|
|
|
|
|
|
|
region = ncurifragmentlookup(uri,"aws.region");
|
|
|
|
if(region == NULL)
|
|
|
|
region = NC_rclookupx(uri,"AWS.REGION");
|
|
|
|
if(region == NULL) {/* See if we can find a profile */
|
2023-05-10 11:13:49 +08:00
|
|
|
if(NC_getactives3profile(uri,&profile)==NC_NOERR) {
|
2022-01-25 04:48:41 +08:00
|
|
|
if(profile)
|
2021-09-28 08:36:33 +08:00
|
|
|
(void)NC_s3profilelookup(profile,"aws_region",®ion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(region == NULL)
|
|
|
|
region = "us-east-1";
|
|
|
|
#ifdef AWSDEBUG
|
|
|
|
fprintf(stderr,">>> activeregion = %s\n",(region?region:"null"));
|
|
|
|
#endif
|
|
|
|
if(regionp) *regionp = region;
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-10-01 03:45:09 +08:00
|
|
|
The .aws/config and .aws/credentials files
|
|
|
|
are in INI format (https://en.wikipedia.org/wiki/INI_file).
|
|
|
|
This format is not well defined, so the grammar used
|
|
|
|
here is restrictive. Here, the term "profile" is the same
|
|
|
|
as the INI term "section".
|
|
|
|
|
|
|
|
The grammar used is as follows:
|
2021-09-28 08:36:33 +08:00
|
|
|
|
|
|
|
Grammar:
|
|
|
|
|
2021-10-01 03:45:09 +08:00
|
|
|
inifile: profilelist ;
|
2021-09-28 08:36:33 +08:00
|
|
|
profilelist: profile | profilelist profile ;
|
2021-10-01 03:45:09 +08:00
|
|
|
profile: '[' profilename ']' EOL entries ;
|
2021-09-28 08:36:33 +08:00
|
|
|
entries: empty | entries entry ;
|
2021-10-01 03:45:09 +08:00
|
|
|
entry: WORD = WORD EOL ;
|
2021-09-28 08:36:33 +08:00
|
|
|
profilename: WORD ;
|
|
|
|
Lexical:
|
|
|
|
WORD sequence of printable characters - [ \[\]=]+
|
2021-10-01 03:45:09 +08:00
|
|
|
EOL '\n' | ';'
|
|
|
|
|
|
|
|
Note:
|
|
|
|
1. The semicolon at beginning of a line signals a comment.
|
|
|
|
2. # comments are not allowed
|
|
|
|
3. Duplicate profiles or keys are ignored.
|
|
|
|
4. Escape characters are not supported.
|
2021-09-28 08:36:33 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define AWS_EOF (-1)
|
|
|
|
#define AWS_ERR (0)
|
2021-10-01 03:45:09 +08:00
|
|
|
#define AWS_WORD (0x10001)
|
|
|
|
#define AWS_EOL (0x10002)
|
2021-09-28 08:36:33 +08:00
|
|
|
|
|
|
|
#ifdef LEXDEBUG
|
|
|
|
static const char*
|
|
|
|
tokenname(int token)
|
|
|
|
{
|
|
|
|
static char num[32];
|
|
|
|
switch(token) {
|
|
|
|
case AWS_EOF: return "EOF";
|
|
|
|
case AWS_ERR: return "ERR";
|
|
|
|
case AWS_WORD: return "WORD";
|
|
|
|
default: snprintf(num,sizeof(num),"%d",token); return num;
|
|
|
|
}
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct AWSparser {
|
|
|
|
char* text;
|
|
|
|
char* pos;
|
|
|
|
size_t yylen; /* |yytext| */
|
|
|
|
NCbytes* yytext;
|
|
|
|
int token; /* last token found */
|
2021-10-01 03:45:09 +08:00
|
|
|
int pushback; /* allow 1-token pushback */
|
2021-09-28 08:36:33 +08:00
|
|
|
} AWSparser;
|
|
|
|
|
|
|
|
static int
|
|
|
|
awslex(AWSparser* parser)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
int token = 0;
|
|
|
|
char* start;
|
|
|
|
size_t count;
|
|
|
|
|
|
|
|
parser->token = AWS_ERR;
|
2021-10-01 03:45:09 +08:00
|
|
|
ncbytesclear(parser->yytext);
|
|
|
|
ncbytesnull(parser->yytext);
|
|
|
|
|
|
|
|
if(parser->pushback != AWS_ERR) {
|
|
|
|
token = parser->pushback;
|
|
|
|
parser->pushback = AWS_ERR;
|
|
|
|
goto done;
|
|
|
|
}
|
2021-09-28 08:36:33 +08:00
|
|
|
|
|
|
|
while(token == 0) { /* avoid need to goto when retrying */
|
|
|
|
c = *parser->pos;
|
|
|
|
if(c == '\0') {
|
|
|
|
token = AWS_EOF;
|
2021-10-01 03:45:09 +08:00
|
|
|
} else if(c == '\n') {
|
|
|
|
parser->pos++;
|
|
|
|
token = AWS_EOL;
|
2021-09-28 08:36:33 +08:00
|
|
|
} else if(c <= ' ' || c == '\177') {
|
|
|
|
parser->pos++;
|
|
|
|
continue; /* ignore whitespace */
|
2021-10-01 03:45:09 +08:00
|
|
|
} else if(c == ';') {
|
|
|
|
char* p = parser->pos - 1;
|
|
|
|
if(*p == '\n') {
|
2022-01-25 04:48:41 +08:00
|
|
|
/* Skip comment */
|
2021-10-01 03:45:09 +08:00
|
|
|
do {p++;} while(*p != '\n' && *p != '\0');
|
|
|
|
parser->pos = p;
|
|
|
|
token = (*p == '\n'?AWS_EOL:AWS_EOF);
|
|
|
|
} else {
|
|
|
|
token = ';';
|
|
|
|
ncbytesappend(parser->yytext,';');
|
|
|
|
parser->pos++;
|
|
|
|
}
|
2021-09-28 08:36:33 +08:00
|
|
|
} else if(c == '[' || c == ']' || c == '=') {
|
|
|
|
ncbytesappend(parser->yytext,c);
|
2021-10-01 03:45:09 +08:00
|
|
|
ncbytesnull(parser->yytext);
|
2021-09-28 08:36:33 +08:00
|
|
|
token = c;
|
|
|
|
parser->pos++;
|
|
|
|
} else { /*Assume a word*/
|
|
|
|
start = parser->pos;
|
|
|
|
for(;;) {
|
|
|
|
c = *parser->pos++;
|
|
|
|
if(c <= ' ' || c == '\177' || c == '[' || c == ']' || c == '=') break; /* end of word */
|
|
|
|
}
|
|
|
|
/* Pushback last char */
|
|
|
|
parser->pos--;
|
|
|
|
count = ((parser->pos) - start);
|
|
|
|
ncbytesappendn(parser->yytext,start,count);
|
|
|
|
ncbytesnull(parser->yytext);
|
|
|
|
token = AWS_WORD;
|
|
|
|
}
|
|
|
|
#ifdef LEXDEBUG
|
|
|
|
fprintf(stderr,"%s(%d): |%s|\n",tokenname(token),token,ncbytescontents(parser->yytext));
|
|
|
|
#endif
|
|
|
|
} /*for(;;)*/
|
|
|
|
|
2021-10-01 03:45:09 +08:00
|
|
|
done:
|
2021-09-28 08:36:33 +08:00
|
|
|
parser->token = token;
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
@param text of the aws credentials file
|
|
|
|
@param profiles list of form struct AWSprofile (see ncauth.h)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LBR '['
|
|
|
|
#define RBR ']'
|
|
|
|
|
|
|
|
static int
|
|
|
|
awsparse(const char* text, NClist* profiles)
|
|
|
|
{
|
|
|
|
int i,stat = NC_NOERR;
|
|
|
|
size_t len;
|
|
|
|
AWSparser* parser = NULL;
|
|
|
|
struct AWSprofile* profile = NULL;
|
|
|
|
int token;
|
|
|
|
char* key = NULL;
|
|
|
|
char* value = NULL;
|
|
|
|
|
|
|
|
if(text == NULL) text = "";
|
|
|
|
|
|
|
|
parser = calloc(1,sizeof(AWSparser));
|
|
|
|
if(parser == NULL)
|
|
|
|
{stat = (NC_ENOMEM); goto done;}
|
|
|
|
len = strlen(text);
|
2021-10-01 03:45:09 +08:00
|
|
|
parser->text = (char*)malloc(len+1+1+1); /* double nul term plus leading EOL */
|
2021-09-28 08:36:33 +08:00
|
|
|
if(parser->text == NULL)
|
2021-12-24 13:18:56 +08:00
|
|
|
{stat = (NCTHROW(NC_EINVAL)); goto done;}
|
2021-10-01 03:45:09 +08:00
|
|
|
parser->pos = parser->text;
|
|
|
|
parser->pos[0] = '\n'; /* So we can test for comment unconditionally */
|
|
|
|
parser->pos++;
|
|
|
|
strcpy(parser->text+1,text);
|
|
|
|
parser->pos += len;
|
2021-09-28 08:36:33 +08:00
|
|
|
/* Double nul terminate */
|
2021-10-01 03:45:09 +08:00
|
|
|
parser->pos[0] = '\0';
|
|
|
|
parser->pos[1] = '\0';
|
|
|
|
parser->pos = &parser->text[0]; /* reset */
|
2021-09-28 08:36:33 +08:00
|
|
|
parser->yytext = ncbytesnew();
|
2021-10-01 03:45:09 +08:00
|
|
|
parser->pushback = AWS_ERR;
|
2021-09-28 08:36:33 +08:00
|
|
|
|
|
|
|
/* Do not need recursion, use simple loops */
|
|
|
|
for(;;) {
|
2021-10-01 03:45:09 +08:00
|
|
|
token = awslex(parser); /* make token always be defined */
|
2021-09-28 08:36:33 +08:00
|
|
|
if(token == AWS_EOF) break; /* finished */
|
2021-10-01 03:45:09 +08:00
|
|
|
if(token == AWS_EOL) {continue;} /* blank line */
|
2021-12-24 13:18:56 +08:00
|
|
|
if(token != LBR) {stat = NCTHROW(NC_EINVAL); goto done;}
|
2021-10-01 03:45:09 +08:00
|
|
|
/* parse [profile name] */
|
2021-09-28 08:36:33 +08:00
|
|
|
token = awslex(parser);
|
2021-12-24 13:18:56 +08:00
|
|
|
if(token != AWS_WORD) {stat = NCTHROW(NC_EINVAL); goto done;}
|
2021-09-28 08:36:33 +08:00
|
|
|
assert(profile == NULL);
|
|
|
|
if((profile = (struct AWSprofile*)calloc(1,sizeof(struct AWSprofile)))==NULL)
|
|
|
|
{stat = NC_ENOMEM; goto done;}
|
|
|
|
profile->name = ncbytesextract(parser->yytext);
|
|
|
|
profile->entries = nclistnew();
|
|
|
|
token = awslex(parser);
|
2021-12-24 13:18:56 +08:00
|
|
|
if(token != RBR) {stat = NCTHROW(NC_EINVAL); goto done;}
|
2021-09-28 08:36:33 +08:00
|
|
|
#ifdef PARSEDEBUG
|
|
|
|
fprintf(stderr,">>> parse: profile=%s\n",profile->name);
|
|
|
|
#endif
|
|
|
|
/* The fields can be in any order */
|
|
|
|
for(;;) {
|
|
|
|
struct AWSentry* entry = NULL;
|
|
|
|
token = awslex(parser);
|
2021-10-01 03:45:09 +08:00
|
|
|
if(token == AWS_EOL) {
|
|
|
|
continue; /* ignore empty lines */
|
|
|
|
} else if(token == AWS_EOF) {
|
|
|
|
break;
|
|
|
|
} else if(token == LBR) {/* start of next profile */
|
|
|
|
parser->pushback = token;
|
|
|
|
break;
|
|
|
|
} else if(token == AWS_WORD) {
|
|
|
|
key = ncbytesextract(parser->yytext);
|
|
|
|
token = awslex(parser);
|
2021-12-24 13:18:56 +08:00
|
|
|
if(token != '=') {stat = NCTHROW(NC_EINVAL); goto done;}
|
2021-10-01 03:45:09 +08:00
|
|
|
token = awslex(parser);
|
2021-12-24 13:18:56 +08:00
|
|
|
if(token != AWS_EOL && token != AWS_WORD) {stat = NCTHROW(NC_EINVAL); goto done;}
|
2021-10-01 03:45:09 +08:00
|
|
|
value = ncbytesextract(parser->yytext);
|
|
|
|
if((entry = (struct AWSentry*)calloc(1,sizeof(struct AWSentry)))==NULL)
|
|
|
|
{stat = NC_ENOMEM; goto done;}
|
|
|
|
entry->key = key; key = NULL;
|
2022-01-25 04:48:41 +08:00
|
|
|
entry->value = value; value = NULL;
|
2021-09-28 08:36:33 +08:00
|
|
|
#ifdef PARSEDEBUG
|
|
|
|
fprintf(stderr,">>> parse: entry=(%s,%s)\n",entry->key,entry->value);
|
|
|
|
#endif
|
2021-10-01 03:45:09 +08:00
|
|
|
nclistpush(profile->entries,entry); entry = NULL;
|
2022-01-25 04:48:41 +08:00
|
|
|
if(token == AWS_WORD) token = awslex(parser); /* finish the line */
|
2021-10-01 03:45:09 +08:00
|
|
|
} else
|
2021-12-24 13:18:56 +08:00
|
|
|
{stat = NCTHROW(NC_EINVAL); goto done;}
|
2021-09-28 08:36:33 +08:00
|
|
|
}
|
|
|
|
|
2023-04-26 07:15:06 +08:00
|
|
|
/* If this profile already exists, then replace old one */
|
2021-09-28 08:36:33 +08:00
|
|
|
for(i=0;i<nclistlength(profiles);i++) {
|
|
|
|
struct AWSprofile* p = (struct AWSprofile*)nclistget(profiles,i);
|
|
|
|
if(strcasecmp(p->name,profile->name)==0) {
|
2023-04-26 07:15:06 +08:00
|
|
|
nclistset(profiles,i,profile);
|
|
|
|
profile = NULL;
|
|
|
|
/* reclaim old one */
|
|
|
|
freeprofile(p);
|
2021-09-28 08:36:33 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(profile) nclistpush(profiles,profile);
|
|
|
|
profile = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if(profile) freeprofile(profile);
|
|
|
|
nullfree(key);
|
|
|
|
nullfree(value);
|
|
|
|
if(parser != NULL) {
|
|
|
|
nullfree(parser->text);
|
|
|
|
ncbytesfree(parser->yytext);
|
|
|
|
free(parser);
|
|
|
|
}
|
|
|
|
return (stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
freeentry(struct AWSentry* e)
|
|
|
|
{
|
|
|
|
if(e) {
|
|
|
|
#ifdef AWSDEBUG
|
2023-04-26 07:15:06 +08:00
|
|
|
fprintf(stderr,">>> freeentry: key=%p value=%p\n",e->key,e->value);
|
2021-09-28 08:36:33 +08:00
|
|
|
#endif
|
|
|
|
nullfree(e->key);
|
|
|
|
nullfree(e->value);
|
|
|
|
nullfree(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
freeprofile(struct AWSprofile* profile)
|
|
|
|
{
|
|
|
|
if(profile) {
|
|
|
|
int i;
|
|
|
|
#ifdef AWSDEBUG
|
|
|
|
fprintf(stderr,">>> freeprofile: %s\n",profile->name);
|
|
|
|
#endif
|
|
|
|
for(i=0;i<nclistlength(profile->entries);i++) {
|
|
|
|
struct AWSentry* e = (struct AWSentry*)nclistget(profile->entries,i);
|
|
|
|
freeentry(e);
|
|
|
|
}
|
|
|
|
nclistfree(profile->entries);
|
|
|
|
nullfree(profile->name);
|
|
|
|
nullfree(profile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
freeprofilelist(NClist* profiles)
|
|
|
|
{
|
|
|
|
if(profiles) {
|
|
|
|
int i;
|
|
|
|
for(i=0;i<nclistlength(profiles);i++) {
|
|
|
|
struct AWSprofile* p = (struct AWSprofile*)nclistget(profiles,i);
|
|
|
|
freeprofile(p);
|
|
|
|
}
|
|
|
|
nclistfree(profiles);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-26 07:15:06 +08:00
|
|
|
/* Find, load, and parse the aws config &/or credentials file */
|
2021-09-28 08:36:33 +08:00
|
|
|
static int
|
2022-01-30 06:27:52 +08:00
|
|
|
aws_load_credentials(NCglobalstate* gstate)
|
2021-09-28 08:36:33 +08:00
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
NClist* profiles = nclistnew();
|
|
|
|
const char** awscfg = awsconfigfiles;
|
|
|
|
const char* aws_root = getenv(NC_TEST_AWS_DIR);
|
|
|
|
NCbytes* buf = ncbytesnew();
|
|
|
|
char path[8192];
|
|
|
|
|
2023-05-10 11:13:49 +08:00
|
|
|
/* add a "no" credentials */
|
|
|
|
{
|
|
|
|
struct AWSprofile* noprof = (struct AWSprofile*)calloc(1,sizeof(struct AWSprofile));
|
|
|
|
noprof->name = strdup("no");
|
|
|
|
noprof->entries = nclistnew();
|
|
|
|
nclistpush(profiles,noprof); noprof = NULL;
|
|
|
|
}
|
|
|
|
|
2021-09-28 08:36:33 +08:00
|
|
|
for(;*awscfg;awscfg++) {
|
|
|
|
/* Construct the path ${HOME}/<file> or Windows equivalent. */
|
|
|
|
const char* cfg = *awscfg;
|
|
|
|
|
|
|
|
snprintf(path,sizeof(path),"%s%s%s",
|
|
|
|
(aws_root?aws_root:gstate->home),
|
|
|
|
(*cfg == '/'?"":"/"),
|
|
|
|
cfg);
|
|
|
|
ncbytesclear(buf);
|
|
|
|
if((stat=NC_readfile(path,buf))) {
|
2021-09-29 04:37:32 +08:00
|
|
|
nclog(NCLOGWARN, "Could not open file: %s",path);
|
2021-09-28 08:36:33 +08:00
|
|
|
} else {
|
|
|
|
/* Parse the credentials file */
|
|
|
|
const char* text = ncbytescontents(buf);
|
|
|
|
if((stat = awsparse(text,profiles))) goto done;
|
|
|
|
}
|
|
|
|
}
|
2023-08-01 07:33:56 +08:00
|
|
|
|
2021-09-28 08:36:33 +08:00
|
|
|
/* add a "none" credentials */
|
|
|
|
{
|
|
|
|
struct AWSprofile* noprof = (struct AWSprofile*)calloc(1,sizeof(struct AWSprofile));
|
2023-02-28 18:37:18 +08:00
|
|
|
if(noprof == NULL) {stat = NC_ENOMEM; goto done;}
|
2021-09-28 08:36:33 +08:00
|
|
|
noprof->name = strdup("none");
|
|
|
|
noprof->entries = nclistnew();
|
|
|
|
nclistpush(profiles,noprof); noprof = NULL;
|
|
|
|
}
|
|
|
|
|
2022-07-06 12:03:52 +08:00
|
|
|
if(gstate->rcinfo->s3profiles)
|
|
|
|
freeprofilelist(gstate->rcinfo->s3profiles);
|
2022-01-30 06:27:52 +08:00
|
|
|
gstate->rcinfo->s3profiles = profiles; profiles = NULL;
|
2021-09-28 08:36:33 +08:00
|
|
|
|
|
|
|
#ifdef AWSDEBUG
|
|
|
|
{int i,j;
|
|
|
|
fprintf(stderr,">>> profiles:\n");
|
2023-04-26 07:15:06 +08:00
|
|
|
for(i=0;i<nclistlength(gstate->rcinfo->s3profiles);i++) {
|
|
|
|
struct AWSprofile* p = (struct AWSprofile*)nclistget(gstate->rcinfo->s3profiles,i);
|
2021-09-28 08:36:33 +08:00
|
|
|
fprintf(stderr," [%s]",p->name);
|
|
|
|
for(j=0;j<nclistlength(p->entries);j++) {
|
|
|
|
struct AWSentry* e = (struct AWSentry*)nclistget(p->entries,j);
|
2023-04-26 07:15:06 +08:00
|
|
|
if(strcmp(e->key,"aws_access_key_id")
|
|
|
|
fprintf(stderr," %s=%d",e->key,(int)strlen(e->value));
|
|
|
|
else if(strcmp(e->key,"aws_secret_access_key")
|
|
|
|
fprintf(stderr," %s=%d",e->key,(int)strlen(e->value));
|
|
|
|
else fprintf(stderr," %s=%s",e->key,e->value);
|
2021-09-28 08:36:33 +08:00
|
|
|
}
|
|
|
|
fprintf(stderr,"\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
done:
|
|
|
|
ncbytesfree(buf);
|
|
|
|
freeprofilelist(profiles);
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2023-05-10 11:13:49 +08:00
|
|
|
/* Lookup a profile by name;
|
|
|
|
@param profilename to lookup
|
|
|
|
@param profilep return the matching profile; null if profile not found
|
|
|
|
@return NC_NOERR if no error
|
|
|
|
@return other error
|
|
|
|
*/
|
|
|
|
|
2021-09-28 08:36:33 +08:00
|
|
|
int
|
|
|
|
NC_authgets3profile(const char* profilename, struct AWSprofile** profilep)
|
|
|
|
{
|
|
|
|
int stat = NC_NOERR;
|
|
|
|
int i = -1;
|
2022-01-30 06:27:52 +08:00
|
|
|
NCglobalstate* gstate = NC_getglobalstate();
|
2022-05-20 02:28:43 +08:00
|
|
|
|
2022-01-30 06:27:52 +08:00
|
|
|
for(i=0;i<nclistlength(gstate->rcinfo->s3profiles);i++) {
|
|
|
|
struct AWSprofile* profile = (struct AWSprofile*)nclistget(gstate->rcinfo->s3profiles,i);
|
2021-09-28 08:36:33 +08:00
|
|
|
if(strcmp(profilename,profile->name)==0)
|
|
|
|
{if(profilep) {*profilep = profile; goto done;}}
|
|
|
|
}
|
|
|
|
if(profilep) *profilep = NULL; /* not found */
|
|
|
|
done:
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2023-04-29 04:05:06 +08:00
|
|
|
/**
|
|
|
|
@param profile name of profile
|
|
|
|
@param key key to search for in profile
|
2023-05-10 11:13:49 +08:00
|
|
|
@param value place to store the value if key is found; NULL if not found
|
|
|
|
@return NC_NOERR if key is found, Some other error otherwise.
|
2023-04-29 04:05:06 +08:00
|
|
|
*/
|
|
|
|
|
2021-09-28 08:36:33 +08:00
|
|
|
int
|
|
|
|
NC_s3profilelookup(const char* profile, const char* key, const char** valuep)
|
|
|
|
{
|
|
|
|
int i,stat = NC_NOERR;
|
|
|
|
struct AWSprofile* awsprof = NULL;
|
|
|
|
const char* value = NULL;
|
|
|
|
|
|
|
|
if(profile == NULL) return NC_ES3;
|
2023-05-10 11:13:49 +08:00
|
|
|
if((stat=NC_authgets3profile(profile,&awsprof))==NC_NOERR && awsprof != NULL) {
|
2021-09-28 08:36:33 +08:00
|
|
|
for(i=0;i<nclistlength(awsprof->entries);i++) {
|
|
|
|
struct AWSentry* entry = (struct AWSentry*)nclistget(awsprof->entries,i);
|
|
|
|
if(strcasecmp(entry->key,key)==0) {
|
|
|
|
value = entry->value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(valuep) *valuep = value;
|
|
|
|
return stat;
|
|
|
|
}
|