Skip to content

Commit 78f259a

Browse files
committedJul 30, 2024
Provide Documentation for the .rc File Mechanism and API
re: Issue Unidata#2952 The documentation -- such as it is -- is lost inside docs/auth.md. So, create docs/quickstart_env.md to describe how .rc file mechanism is used, and include the netcdf-c API. Also add list of environment variables used by the netcdf-c library.
1 parent 150db23 commit 78f259a

File tree

7 files changed

+173
-66
lines changed

7 files changed

+173
-66
lines changed
 

‎RELEASE_NOTES.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ This file contains a high-level description of this package's evolution. Release
77

88
## 4.9.3 - TBD
99

10-
* Convert NCZarr V2 to store all netcdf-4 specific info as attributes. This improves interoperability with other Zarr implementations by no longer using non-standard keys. The price to be paid is that lazy attribute reading cannot be supported. See [Github #2836](https://github.com/Unidata/netcdf-c/issues/2936) for more information.
11-
* Cleanup the option code for NETCDF_ENABLE_SET_LOG_LEVEL\[_FUNC\] See [Github #2931](https://github.com/Unidata/netcdf-c/issues/2931) for more information.
10+
* Provide better documentation for the .rc file mechanism and API. See [Github #????](https://github.com/Unidata/netcdf-c/pull/????) for more information.
11+
* Convert NCZarr V2 to store all netcdf-4 specific info as attributes. This improves interoperability with other Zarr implementations by no longer using non-standard keys. The price to be paid is that lazy attribute reading cannot be supported. See [Github #2836](https://github.com/Unidata/netcdf-c/pull/2936) for more information.
12+
* Cleanup the option code for NETCDF_ENABLE_SET_LOG_LEVEL\[_FUNC\] See [Github #2931](https://github.com/Unidata/netcdf-c/pull/2931) for more information.
1213
* Fix duplicate definition when using aws-sdk-cpp. See [Github #2928](https://github.com/Unidata/netcdf-c/issues/2928) for more information.
13-
* Cleanup various obsolete options and do some code refactoring. See [Github #2926](https://github.com/Unidata/netcdf-c/issues/2926) for more information.
14-
* Convert the Zarr-related ENABLE_XXX options to NETCDF_ENABLE_XXX options (part of the cmake overhaul). See [Github #2923](https://github.com/Unidata/netcdf-c/issues/2923) for more information.
14+
* Cleanup various obsolete options and do some code refactoring. See [Github #2926](https://github.com/Unidata/netcdf-c/pull/2926) for more information.
15+
* Convert the Zarr-related ENABLE_XXX options to NETCDF_ENABLE_XXX options (part of the cmake overhaul). See [Github #2923](https://github.com/Unidata/netcdf-c/pull/2923) for more information.
1516
* Refactor macro `_FillValue` to `NC_FillValue` to avoid conflict with libc++ headers. See [Github #2858](https://github.com/Unidata/netcdf-c/issues/2858) for more information.
1617
* Changed `cmake` build options to be prefaced with `NETCDF`, to bring things in to line with best practices. This will permit a number of overall quality of life improvements to netCDF, in terms of allowing it to be more easily integrated with upstream projects via `FetchContent()`, `subdirectory()`, etc. Currently, the naming convention in use thus far will still work, but will result in warning messages about deprecation, and instructions on how to update your workflow. See [Github #2895](https://github.com/Unidata/netcdf-c/pull/2895) for more information.
1718
* Incorporate a more modern look and feel to user documentation generated by Doxygen. See [Doxygen Awesome CSS](https://github.com/jothepro/doxygen-awesome-css) and [Github #2864](https://github.com/Unidata/netcdf-c/pull/2864) for more information.

‎docs/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,6 @@ inmemory.md DAP2.dox FAQ.md
9696
known_problems.md
9797
COPYRIGHT.dox user_defined_formats.md DAP4.md DAP4.dox
9898
testserver.dox byterange.md filters.md nczarr.md auth.md quantize.md
99-
quickstart_paths.md cloud.md)
99+
quickstart_paths.md quickstart_filters.md quickstart_env.md cloud.md)
100100

101101
ADD_EXTRA_DIST("${CUR_EXTRA_DIST}")

‎docs/Doxyfile.in

+1
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ INPUT = @abs_top_srcdir@/docs/mainpage.dox \
965965
@abs_top_srcdir@/docs/filters.md \
966966
@abs_top_srcdir@/docs/quickstart_filters.md \
967967
@abs_top_srcdir@/docs/quickstart_paths.md \
968+
@abs_top_srcdir@/docs/quickstart_env.md \
968969
@abs_top_srcdir@/include/netcdf.h \
969970
@abs_top_srcdir@/include/netcdf_mem.h \
970971
@abs_top_srcdir@/include/netcdf_par.h \

‎docs/Makefile.am

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ obsolete/fan_utils.html indexing.dox inmemory.md FAQ.md \
1515
known_problems.md COPYRIGHT.md inmeminternal.dox testserver.dox \
1616
byterange.md nczarr.md quantize.md all-error-codes.md \
1717
quickstart_paths.md cloud.md header.html attribute_conventions.md \
18-
file_format_specifications.md quickstart_filters.md \
18+
file_format_specifications.md quickstart_filters.md quickstart_env.md \
1919
doxygen-awesome-css netcdf-50x50.png
2020

2121
# Turn off parallel builds in this directory.

‎docs/auth.md

+3-58
Original file line numberDiff line numberDiff line change
@@ -44,67 +44,12 @@ how to properly escape the user and password.
4444

4545
## RC File Authentication {#auth_dodsrc}
4646
The netcdf library supports an _rc_ file mechanism to allow the passing
47-
of a number of parameters to libnetcdf and libcurl.
48-
Locating the _rc_ file is a multi-step process.
49-
50-
### Search Order
51-
52-
The netcdf-c library searches for, and loads from, the following files,
53-
in this order:
54-
1. $HOME/.ncrc
55-
2. $HOME/.dodsrc
56-
3. $CWD/.ncrc
57-
4. $CWD/.dodsrc
58-
59-
*$HOME* is the user's home directory and *$CWD* is the current working directory. Entries in later files override any of the earlier files
60-
61-
It is strongly suggested that you pick a uniform location and a uniform name
62-
and use them always. Otherwise you may observe unexpected results
63-
when the netcdf-c library loads an rc file you did not expect.
64-
65-
### RC File Format
66-
67-
The rc file format is a series of lines of the general form:
68-
69-
[<host:port>]<key>=<value>
70-
71-
where the bracket-enclosed host:port is optional.
72-
73-
### URL Constrained RC File Entries
74-
75-
Each line of the rc file can begin with a host+port enclosed in
76-
square brackets. The form is "host:port". If the port is not
77-
specified then the form is just "host". The reason that more of
78-
the url is not used is that libcurl's authorization grain is not
79-
any finer than host level.
80-
81-
Here are some examples.
82-
````
83-
[remotetest.unidata.ucar.edu]HTTP.VERBOSE=1
84-
or
85-
[fake.ucar.edu:9090]HTTP.VERBOSE=0
86-
````
87-
If the url request from, say, the _netcdf_open_ method
88-
has a host+port matching one of the prefixes in the rc file, then
89-
the corresponding entry will be used, otherwise ignored.
90-
This means that an entry with a matching host+port will take
91-
precedence over an entry without a host+port.
92-
93-
For example, the URL
94-
````
95-
http://remotetest.unidata.ucar.edu/thredds/dodsC/testdata/testData.nc
96-
````
97-
will have HTTP.VERBOSE set to 1 because its host matches the example above.
98-
99-
Similarly,
100-
````
101-
http://fake.ucar.edu:9090/dts/test.01
102-
````
103-
will have HTTP.VERBOSE set to 0 because its host+port matches the example above.
47+
of a number of run-time parameters to libnetcdf and libcurl.
48+
This is described in the file "quickstart_env.md".
10449

10550
## Authorization-Related Keys {#auth_keys}
10651

107-
The currently defined set of authorization-related keys are as follows.
52+
The currently defined set of authorization-related keys recognized in .netrc are as follows.
10853
The second column is the affected curl_easy_setopt option(s), if any
10954
(see reference #1).
11055
<table>

‎docs/quickstart_env.md

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
Appendix D.3. Environment Variables and .RC files {#nc_env_quickstart}
2+
==============================
3+
4+
The netCDF-c library provides several parameterization mechanisms to
5+
control its behavior at run-time. The term _run-time_ means that the
6+
library's behavior can be changed every time the library is initialized
7+
8+
The most commonly used parameterization mechanisms are:
9+
1. Environment Variables -- accessed by the getenv() function.
10+
2. .RC files -- accessed from the file system.
11+
12+
## Environment Variables {#nc_env_vars}
13+
14+
The following table describes (most of) the environment variables
15+
used by the netcdf-c library. There are some not listed that are only
16+
used for specialized debugging.
17+
18+
<table>
19+
<tr><th>Name<th>Description
20+
<tr><td>ALLUSERSPROFILE<td>This is more-or-less the Windows equivalent of "HOME"
21+
<tr><td>AWS_ACCESS_KEY_ID<td>Used by the aws access libraries; overrides ${HOME}/.aws/config entries.
22+
<tr><td>AWS_CONFIG_FILE<td>Used by the aws access libraries; specifies absolute path to the config file.
23+
<tr><td>AWS_DEFAULT_REGION<td>Used by the aws access libraries; specifies default S3 region.
24+
<tr><td>AWS_PROFILE<td>Used by the aws access libraries; specifies default AWS profile.
25+
<tr><td>AWS_REGION<td>Used by the aws access libraries; specifies specific region to use.
26+
<tr><td>AWS_SECRET_ACCESS_KEY<td>Used by the aws access libraries; overrides ${HOME}/.aws/config entries.
27+
<tr><td>CURLOPT_VERBOSE<td>Causes libcurl to produce verbose output.
28+
<tr><td>HOME<td>The user's home directory.
29+
<tr><td>MSYS2_PREFIX<td>If platform is MSYS2, then specify the root prefix.
30+
<tr><td>NC_DEFAULT_CREATE_PERMS<td>For NCZarr, specify the default creation permissions for a file.
31+
<tr><td>NC_DEFAULT_DIR_PERMS<td>For NCZarr, specify the default creation permissions for a directory.
32+
<tr><td>NCLOGGING<td>Specify the log level: one of "OFF","ERR","WARN","NOTE","DEBUG".
33+
<tr><td>NCPATHDEBUG<td>Causes path manager to output debugging information.
34+
<tr><td>NCRCENV_HOME<td>Overrides ${HOME} as the location of the .rc file.
35+
<tr><td>NCRCENV_IGNORE<td>Causes any .rc files to be ignored.
36+
<tr><td>NCRCENV_RC<td>The absolute path to use for the .rc file.
37+
<tr><td>NCTRACING<td>Specify the level of tracing detail.
38+
<tr><td>NCZARRFORMAT<td>Force use of a specific Zarr format version: 2 or 3.
39+
<tr><td>NETCDF_LOG_LEVEL<td>Specify the log level for HDF5 logging (separate from e.g. NCLOGGING).
40+
<tr><td>TEMP<td>For Windows platform, specifies the location of a directory to store temporary files.
41+
<tr><td>USERPROFILE<td>For Windows platform, overrides ${HOME}.
42+
</table>
43+
44+
## Resource Control (.rc) Files {#nc_env_rc}
45+
46+
In addition to using environment variables,
47+
the netcdf-c library supports run-time configuration
48+
of the library using the so-called ".rc" file mechanism.
49+
This means that as part of its initialization, the netcdf-c
50+
library will search for and process a set of files where
51+
these files contain entries specifying (key,value) pairs.
52+
These pairs are compiled into a single internal database
53+
that can be queried by other parts of the netcdf-c library.
54+
55+
### Locating The _.rc_ Files
56+
57+
For historical reasons, multiple .rc files are allowed.
58+
59+
### Search Order
60+
61+
The netcdf-c library searches for, and loads from, the following files,
62+
in this order:
63+
1. $HOME/.ncrc
64+
2. $HOME/.dodsrc
65+
3. $CWD/.ncrc
66+
4. $CWD/.dodsrc
67+
68+
*$HOME* is the user's home directory and *$CWD* is the current working directory.
69+
Entries in later files override any of the earlier files
70+
71+
It is strongly suggested that you pick a uniform location and a uniform name
72+
and use them always. Otherwise you may observe unexpected results
73+
when the netcdf-c library loads an rc file you did not expect.
74+
75+
### RC File Format
76+
77+
The rc file format is a series of lines of the general form:
78+
````
79+
[<URL>]<key>=<value>
80+
````
81+
where the bracket-enclosed URL is optional. Note that the brackets
82+
are part of the line.
83+
84+
### URL Constrained RC File Entries
85+
86+
Each line of the rc file can begin with a URL enclosed in
87+
square brackets. The parts of the URL that are used for choosing
88+
an entry are the host, the port, and the URL path.
89+
Note that the host+port is the only part used when searching for
90+
libcurl related entries. This is because libcurl's authorization grain is not
91+
any finer than host+port level.
92+
The URL path may be used for non-curl related entries.
93+
Also note that the protocol is ignored.
94+
95+
Here are some examples.
96+
````
97+
[https://remotetest.unidata.ucar.edu/thredds]HTTP.VERBOSE=1
98+
or
99+
[https://fake.ucar.edu:9090]HTTP.VERBOSE=0
100+
````
101+
102+
For selection purposes, the host+port+path is used when the path argument
103+
for _nc_open()_ or _nc_create()_ takes the form of a URL.
104+
If the url request from, say, the _netcdf_open_ method
105+
has a host,port, and path matching one of the prefixes in the rc file, then
106+
the corresponding entry will be used, otherwise ignored.
107+
This means that an entry with a matching host+port+path will take
108+
precedence over an entry without a host+port+path.
109+
110+
For example, passing this URL to _nc_open_
111+
````
112+
http://remotetest.unidata.ucar.edu/thredds/dodsC/testdata/testData.nc
113+
````
114+
will have HTTP.VERBOSE set to 1 because its host and path match the example above.
115+
116+
Similarly, using this path
117+
````
118+
http://fake.ucar.edu:9090/dts/test.01
119+
````
120+
will have HTTP.VERBOSE set to 0 because its host+port matches the example above.
121+
122+
### Programmatic Access to .rc File
123+
124+
It is possible for client programs to query and modify the internal .rc database
125+
through the following API.
126+
* ````char* nc_rc_get(const char* key);````
127+
Get the value corresponding to key or return NULL if not defined. The caller must free the resulting value.
128+
* ````int nc_rc_set(const char* key, const char* value);````
129+
Set/overwrite the value corresponding to the specified key.
130+
131+
Note that this API does not (currently) support URL prefixed keys, so the client will need to take this into account.
132+
133+
### Defined .rc file keys
134+
135+
There a a number of keys used by the netcdf-c library. Most of them
136+
are authorization-related. The file "auth.md" describes these keys.
137+
138+
Other keys are as follows:
139+
* libdap4/d4curlfunctions.c and oc2/ocinternal.c
140+
- HTTP.READ.BUFFERSIZE -- set the read buffer size for DAP2/4 connection
141+
- HTTP.KEEPALIVE -- turn on keep-alive for DAP2/4 connection
142+
* libdispatch/ds3util.c
143+
- AWS.PROFILE -- alternate way to specify the default AWS profile
144+
- AWS.REGION -- alternate way to specify the default AWS region
145+
* libnczarr/zinternal.c
146+
- ZARR.DIMENSION_SEPARATOR -- alternate way to specify the Zarr dimension separator character
147+
* oc2/occurlfunctions.c
148+
- HTTP.NETRC -- alternate way to specify the path of the .netrc file
149+
150+
## Point of Contact {#nc_env_poc}
151+
152+
__Author__: Dennis Heimbigner<br>
153+
__Email__: dmh at ucar dot edu<br>
154+
__Initial Version__: 01/09/2023<br>
155+
__Last Revised__: 07/30/2024

‎libdispatch/drc.c

+7-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ where the .rc entry has the simple form "key=value".
7171
If that entry is not found, then return NULL.
7272
7373
@param key table entry key field
74+
@param table entry key field
7475
@return value matching the key -- caller frees
7576
@return NULL if no entry of the form key=value exists
7677
*/
@@ -269,8 +270,12 @@ NC_rcload(void)
269270
}
270271

271272
/**
272-
* Locate a entry by property key and host+port (may be null)
273+
* Locate a entry by property key.
273274
* If duplicate keys, first takes precedence.
275+
* @param key to lookup
276+
* @param hostport to use for lookup
277+
* @param urlpath to use for lookup
278+
* @return the value of the key or NULL if not found.
274279
*/
275280
char*
276281
NC_rclookup(const char* key, const char* hostport, const char* urlpath)
@@ -468,7 +473,7 @@ rccompile(const char* filepath)
468473
}
469474
line = rtag + 1;
470475
*rtag = '\0';
471-
/* compile the url and pull out the host and protocol */
476+
/* compile the url and pull out the host, port, and path */
472477
if(uri) ncurifree(uri);
473478
if(ncuriparse(url,&uri)) {
474479
nclog(NCLOGERR, "Malformed [url] in %s entry: %s",filepath,line);

0 commit comments

Comments
 (0)
Please sign in to comment.