-
Notifications
You must be signed in to change notification settings - Fork 22
Add offline cache support with SCITOKENS_KEYCACHE_FILE environment variable and enhanced scitokens-keycache tool #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…he tool Co-authored-by: djw8605 <[email protected]>
…lity Co-authored-by: djw8605 <[email protected]>
@copilot Modify the scitokens-keycache file to have different options.
|
…cation) Co-authored-by: djw8605 <[email protected]>
I've successfully modified the scitokens-keycache tool to support the requested subcommands:
All commands work with both explicit Commit: 8bdaa4a Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
lint
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 217 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 221 in 6639c01
const char* cache_location = scitokens_get_cache_file_location(); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 230 in 6639c01
std::cerr << "Error: Cannot access cache file: " << cache_file << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 234 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 238 in 6639c01
std::cerr << "Error: Cannot open cache database: " << sqlite3_errmsg(db) << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 242 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 244 in 6639c01
rc = sqlite3_prepare_v2(db, "SELECT issuer, keys FROM keycache ORDER BY issuer", -1, &stmt, NULL); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 246 in 6639c01
std::cerr << "Error: Failed to prepare SQL statement: " << sqlite3_errmsg(db) << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 250 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 253 to 258 in 6639c01
std::cout << std::setw(40) << "Issuer" | |
<< std::setw(15) << "Key ID" | |
<< std::setw(15) << "Key Type" | |
<< std::setw(20) << "Expires" | |
<< std::setw(20) << "Next Update" | |
<< std::setw(25) << "Public Key (truncated)" << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 260 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 266 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 270 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 273 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 279 to 283 in 6639c01
<< std::setw(15) << "N/A" | |
<< std::setw(15) << "N/A" | |
<< std::setw(20) << "Invalid JSON" | |
<< std::setw(20) << "N/A" | |
<< std::setw(25) << "N/A" << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 286 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 288 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 292 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 294 to 295 in 6639c01
if (expires_iter != top_obj.end() && expires_iter->second.is<int64_t>()) { | |
time_t expires_time = static_cast<time_t>(expires_iter->second.get<int64_t>()); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 297 in 6639c01
strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M", gmtime(&expires_time)); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 300 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 302 to 303 in 6639c01
if (next_update_iter != top_obj.end() && next_update_iter->second.is<int64_t>()) { | |
time_t next_update_time = static_cast<time_t>(next_update_iter->second.get<int64_t>()); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 305 in 6639c01
strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M", gmtime(&next_update_time)); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 308 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 311 in 6639c01
if (jwks_iter != top_obj.end() && jwks_iter->second.is<picojson::object>()) { |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 314 to 317 in 6639c01
if (keys_array_iter != jwks_obj.end() && keys_array_iter->second.is<picojson::array>()) { | |
auto keys_array = keys_array_iter->second.get<picojson::array>(); | |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 319 to 324 in 6639c01
std::cout << std::setw(40) << truncate_string(issuer_str, 37) | |
<< std::setw(15) << "N/A" | |
<< std::setw(15) << "No keys" | |
<< std::setw(20) << expires_str | |
<< std::setw(20) << next_update_str | |
<< std::setw(25) << "N/A" << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 328 to 329 in 6639c01
if (!key_val.is<picojson::object>()) continue; | |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 331 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 335 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 337 in 6639c01
if (kid_iter != key_obj.end() && kid_iter->second.is<std::string>()) { |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 340 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 342 in 6639c01
if (kty_iter != key_obj.end() && kty_iter->second.is<std::string>()) { |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 345 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 349 to 352 in 6639c01
if (n_iter != key_obj.end() && n_iter->second.is<std::string>()) { | |
public_key_snippet = n_iter->second.get<std::string>(); | |
} else if (x_iter != key_obj.end() && x_iter->second.is<std::string>()) { | |
public_key_snippet = x_iter->second.get<std::string>(); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 354 to 360 in 6639c01
std::cout << std::setw(40) << (first_key ? truncate_string(issuer_str, 37) : "") | |
<< std::setw(15) << truncate_string(kid, 12) | |
<< std::setw(15) << kty | |
<< std::setw(20) << (first_key ? expires_str : "") | |
<< std::setw(20) << (first_key ? next_update_str : "") | |
<< std::setw(25) << truncate_string(public_key_snippet, 22) << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 365 to 370 in 6639c01
std::cout << std::setw(40) << truncate_string(issuer_str, 37) | |
<< std::setw(15) << "N/A" | |
<< std::setw(15) << "No keys array" | |
<< std::setw(20) << expires_str | |
<< std::setw(20) << next_update_str | |
<< std::setw(25) << "N/A" << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 374 to 378 in 6639c01
<< std::setw(15) << "N/A" | |
<< std::setw(15) << "No JWKS" | |
<< std::setw(20) << expires_str | |
<< std::setw(20) << next_update_str | |
<< std::setw(25) << "N/A" << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 381 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 385 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 388 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 393 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 399 in 6639c01
for (int i = 2; i < argc; i++) { // Start from 2 since argv[1] is "location" |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 409 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 411 to 412 in 6639c01
const char* cache_location = scitokens_get_cache_file_location(); | |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 415 in 6639c01
std::cout << "Access status: Failed - could not determine location\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 418 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 421 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 428 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 430 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 444 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 447 in 6639c01
rc = sqlite3_prepare_v2(db, "SELECT COUNT(*) FROM keycache", -1, &stmt, NULL); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 452 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 456 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 465 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 467 in 6639c01
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens.cpp
Line 992 in 6639c01
int keycache_set_jwks_with_expiry(const char *issuer, const char *jwks, |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens.cpp
Line 1007 in 6639c01
if (!scitokens::Validator::store_jwks_with_expiry(issuer, jwks, expires_at)) { |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens.cpp
Line 1148 in 6639c01
const char* scitokens_get_cache_file_location() { |
[lint] reported by reviewdog 🐶
Line 7 in 6639c01
#include <sys/select.h> |
[lint] reported by reviewdog 🐶
Line 9 in 6639c01
#include <stdint.h> |
[lint] reported by reviewdog 🐶
Line 298 in 6639c01
* - `expires_at` is the expiration time as Unix timestamp (seconds since epoch). |
[lint] reported by reviewdog 🐶
Line 300 in 6639c01
int keycache_set_jwks_with_expiry(const char *issuer, const char *jwks, |
[lint] reported by reviewdog 🐶
Line 345 in 6639c01
const char* scitokens_get_cache_file_location(); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens_cache.cpp
Line 99 in 6639c01
* the appropriate directory for the key cache file. It prioritizes the following: |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens_cache.cpp
Line 109 in 6639c01
* @return std::string Full path to the key cache file, or empty string on error. |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens_internal.h
Line 119 in 6639c01
* the appropriate directory for the key cache file. It prioritizes the following: |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens_internal.h
Line 129 in 6639c01
* @return std::string Full path to the key cache file, or empty string on error. |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens_internal.h
Line 767 in 6639c01
* Store the contents of a JWKS for a given issuer with explicit expiry time. |
[lint] reported by reviewdog 🐶
Line 846 in 6639c01
[lint] reported by reviewdog 🐶
Line 853 in 6639c01
[lint] reported by reviewdog 🐶
Line 856 in 6639c01
[lint] reported by reviewdog 🐶
Lines 860 to 863 in 6639c01
auto rv = keycache_set_jwks_with_expiry("https://offline.test.com", | |
demo_scitokens2.c_str(), | |
expires_at, &err_msg); |
[lint] reported by reviewdog 🐶
Line 865 in 6639c01
[lint] reported by reviewdog 🐶
Line 873 in 6639c01
[lint] reported by reviewdog 🐶
Line 875 in 6639c01
[lint] reported by reviewdog 🐶
Line 883 in 6639c01
[lint] reported by reviewdog 🐶
Line 890 in 6639c01
[lint] reported by reviewdog 🐶
Line 893 in 6639c01
[lint] reported by reviewdog 🐶
Lines 897 to 900 in 6639c01
auto rv = keycache_set_jwks_with_expiry("https://expired.test.com", | |
demo_scitokens2.c_str(), | |
expires_at, &err_msg); |
[lint] reported by reviewdog 🐶
Line 902 in 6639c01
[lint] reported by reviewdog 🐶
Line 910 in 6639c01
[lint] reported by reviewdog 🐶
Line 912 in 6639c01
#include <cstdlib> | ||
#include <cstring> | ||
#include <ctime> | ||
#include <iostream> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
#include <iostream> |
#include <string> | ||
#include <unistd.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
#include <string> | |
#include <unistd.h> |
#include <string> | ||
#include <unistd.h> | ||
#include <iomanip> | ||
#include <sqlite3.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
#include <sqlite3.h> | |
#include <iostream> | |
#include <sqlite3.h> |
#include <unistd.h> | ||
#include <iomanip> | ||
#include <sqlite3.h> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
#include <string> | |
#include <unistd.h> | |
std::cout << "Commands:\n"; | ||
std::cout << " add Add JWKS to a keycache file\n"; | ||
std::cout << " print Print table of all public keys stored in cache\n"; | ||
std::cout << " location Print location of scitokens keycache and access status\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
std::cout << " location Print location of scitokens keycache and access status\n"; | |
std::cout << " location Print location of scitokens keycache and access " | |
"status\n"; |
std::cout << "Expires at: " << ctime(&now) << " + " << valid_for << " seconds\n"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
std::cout << "Expires at: " << ctime(&now) << " + " << valid_for << " seconds\n"; | |
std::cout << "Expires at: " << ctime(&now) << " + " << valid_for | |
<< " seconds\n"; | |
if (err_msg) { | ||
free(err_msg); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
std::cerr << "Error: " << e.what() << "\n"; | ||
return 1; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
|
||
int print_command(int argc, char *argv[]) { | ||
std::string cache_file; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
std::string cache_file; | ||
|
||
// Parse command line arguments for print command | ||
for (int i = 2; i < argc; i++) { // Start from 2 since argv[1] is "print" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
for (int i = 2; i < argc; i++) { // Start from 2 since argv[1] is "print" | |
for (int i = 2; i < argc; i++) { // Start from 2 since argv[1] is "print" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
lint
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 217 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 221 in d9f2c49
const char* cache_location = scitokens_get_cache_file_location(); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 230 in d9f2c49
std::cerr << "Error: Cannot access cache file: " << cache_file << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 234 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 238 in d9f2c49
std::cerr << "Error: Cannot open cache database: " << sqlite3_errmsg(db) << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 242 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 244 in d9f2c49
rc = sqlite3_prepare_v2(db, "SELECT issuer, keys FROM keycache ORDER BY issuer", -1, &stmt, NULL); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 246 in d9f2c49
std::cerr << "Error: Failed to prepare SQL statement: " << sqlite3_errmsg(db) << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 250 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 253 to 258 in d9f2c49
std::cout << std::setw(40) << "Issuer" | |
<< std::setw(15) << "Key ID" | |
<< std::setw(15) << "Key Type" | |
<< std::setw(20) << "Expires" | |
<< std::setw(20) << "Next Update" | |
<< std::setw(25) << "Public Key (truncated)" << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 260 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 266 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 270 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 273 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 279 to 283 in d9f2c49
<< std::setw(15) << "N/A" | |
<< std::setw(15) << "N/A" | |
<< std::setw(20) << "Invalid JSON" | |
<< std::setw(20) << "N/A" | |
<< std::setw(25) << "N/A" << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 286 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 288 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 292 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 294 to 295 in d9f2c49
if (expires_iter != top_obj.end() && expires_iter->second.is<int64_t>()) { | |
time_t expires_time = static_cast<time_t>(expires_iter->second.get<int64_t>()); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 297 in d9f2c49
strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M", gmtime(&expires_time)); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 300 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 302 to 303 in d9f2c49
if (next_update_iter != top_obj.end() && next_update_iter->second.is<int64_t>()) { | |
time_t next_update_time = static_cast<time_t>(next_update_iter->second.get<int64_t>()); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 305 in d9f2c49
strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M", gmtime(&next_update_time)); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 308 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 311 in d9f2c49
if (jwks_iter != top_obj.end() && jwks_iter->second.is<picojson::object>()) { |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 314 to 317 in d9f2c49
if (keys_array_iter != jwks_obj.end() && keys_array_iter->second.is<picojson::array>()) { | |
auto keys_array = keys_array_iter->second.get<picojson::array>(); | |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 319 to 324 in d9f2c49
std::cout << std::setw(40) << truncate_string(issuer_str, 37) | |
<< std::setw(15) << "N/A" | |
<< std::setw(15) << "No keys" | |
<< std::setw(20) << expires_str | |
<< std::setw(20) << next_update_str | |
<< std::setw(25) << "N/A" << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 328 to 329 in d9f2c49
if (!key_val.is<picojson::object>()) continue; | |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 331 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 335 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 337 in d9f2c49
if (kid_iter != key_obj.end() && kid_iter->second.is<std::string>()) { |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 340 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 342 in d9f2c49
if (kty_iter != key_obj.end() && kty_iter->second.is<std::string>()) { |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 345 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 349 to 352 in d9f2c49
if (n_iter != key_obj.end() && n_iter->second.is<std::string>()) { | |
public_key_snippet = n_iter->second.get<std::string>(); | |
} else if (x_iter != key_obj.end() && x_iter->second.is<std::string>()) { | |
public_key_snippet = x_iter->second.get<std::string>(); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 354 to 360 in d9f2c49
std::cout << std::setw(40) << (first_key ? truncate_string(issuer_str, 37) : "") | |
<< std::setw(15) << truncate_string(kid, 12) | |
<< std::setw(15) << kty | |
<< std::setw(20) << (first_key ? expires_str : "") | |
<< std::setw(20) << (first_key ? next_update_str : "") | |
<< std::setw(25) << truncate_string(public_key_snippet, 22) << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 365 to 370 in d9f2c49
std::cout << std::setw(40) << truncate_string(issuer_str, 37) | |
<< std::setw(15) << "N/A" | |
<< std::setw(15) << "No keys array" | |
<< std::setw(20) << expires_str | |
<< std::setw(20) << next_update_str | |
<< std::setw(25) << "N/A" << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 374 to 378 in d9f2c49
<< std::setw(15) << "N/A" | |
<< std::setw(15) << "No JWKS" | |
<< std::setw(20) << expires_str | |
<< std::setw(20) << next_update_str | |
<< std::setw(25) << "N/A" << "\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 381 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 385 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 388 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 393 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 399 in d9f2c49
for (int i = 2; i < argc; i++) { // Start from 2 since argv[1] is "location" |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 409 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Lines 411 to 412 in d9f2c49
const char* cache_location = scitokens_get_cache_file_location(); | |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 415 in d9f2c49
std::cout << "Access status: Failed - could not determine location\n"; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 418 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 421 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 428 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 430 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 444 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 447 in d9f2c49
rc = sqlite3_prepare_v2(db, "SELECT COUNT(*) FROM keycache", -1, &stmt, NULL); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 452 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 456 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 465 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens-keycache.cpp
Line 467 in d9f2c49
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens.cpp
Line 992 in d9f2c49
int keycache_set_jwks_with_expiry(const char *issuer, const char *jwks, |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens.cpp
Line 1007 in d9f2c49
if (!scitokens::Validator::store_jwks_with_expiry(issuer, jwks, expires_at)) { |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens.cpp
Line 1148 in d9f2c49
const char* scitokens_get_cache_file_location() { |
[lint] reported by reviewdog 🐶
Line 7 in d9f2c49
#include <sys/select.h> |
[lint] reported by reviewdog 🐶
Line 9 in d9f2c49
#include <stdint.h> |
[lint] reported by reviewdog 🐶
Line 298 in d9f2c49
* - `expires_at` is the expiration time as Unix timestamp (seconds since epoch). |
[lint] reported by reviewdog 🐶
Line 300 in d9f2c49
int keycache_set_jwks_with_expiry(const char *issuer, const char *jwks, |
[lint] reported by reviewdog 🐶
Line 345 in d9f2c49
const char* scitokens_get_cache_file_location(); |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens_cache.cpp
Line 99 in d9f2c49
* the appropriate directory for the key cache file. It prioritizes the following: |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens_cache.cpp
Line 109 in d9f2c49
* @return std::string Full path to the key cache file, or empty string on error. |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens_internal.h
Line 119 in d9f2c49
}; |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens_internal.h
Line 129 in d9f2c49
explicit CurlException(const std::string &msg) : std::runtime_error(msg) {} |
[lint] reported by reviewdog 🐶
scitokens-cpp/src/scitokens_internal.h
Line 767 in d9f2c49
static std::unique_ptr<AsyncStatus> |
[lint] reported by reviewdog 🐶
Line 846 in d9f2c49
[lint] reported by reviewdog 🐶
Line 853 in d9f2c49
[lint] reported by reviewdog 🐶
Line 856 in d9f2c49
[lint] reported by reviewdog 🐶
Lines 860 to 863 in d9f2c49
auto rv = keycache_set_jwks_with_expiry("https://offline.test.com", | |
demo_scitokens2.c_str(), | |
expires_at, &err_msg); |
[lint] reported by reviewdog 🐶
Line 865 in d9f2c49
[lint] reported by reviewdog 🐶
Line 873 in d9f2c49
[lint] reported by reviewdog 🐶
Line 875 in d9f2c49
[lint] reported by reviewdog 🐶
Line 883 in d9f2c49
[lint] reported by reviewdog 🐶
Line 890 in d9f2c49
[lint] reported by reviewdog 🐶
Line 893 in d9f2c49
[lint] reported by reviewdog 🐶
Lines 897 to 900 in d9f2c49
auto rv = keycache_set_jwks_with_expiry("https://expired.test.com", | |
demo_scitokens2.c_str(), | |
expires_at, &err_msg); |
[lint] reported by reviewdog 🐶
Line 902 in d9f2c49
[lint] reported by reviewdog 🐶
Line 910 in d9f2c49
[lint] reported by reviewdog 🐶
Line 912 in d9f2c49
#include <cstdlib> | ||
#include <cstring> | ||
#include <ctime> | ||
#include <iostream> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
#include <iostream> |
#include <string> | ||
#include <unistd.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
#include <string> | |
#include <unistd.h> |
#include <string> | ||
#include <unistd.h> | ||
#include <iomanip> | ||
#include <sqlite3.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
#include <sqlite3.h> | |
#include <iostream> | |
#include <sqlite3.h> |
#include <unistd.h> | ||
#include <iomanip> | ||
#include <sqlite3.h> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
#include <string> | |
#include <unistd.h> | |
std::cout << "Commands:\n"; | ||
std::cout << " add Add JWKS to a keycache file\n"; | ||
std::cout << " print Print table of all public keys stored in cache\n"; | ||
std::cout << " location Print location of scitokens keycache and access status\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
std::cout << " location Print location of scitokens keycache and access status\n"; | |
std::cout << " location Print location of scitokens keycache and access " | |
"status\n"; |
std::cout << "Expires at: " << ctime(&now) << " + " << valid_for << " seconds\n"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
std::cout << "Expires at: " << ctime(&now) << " + " << valid_for << " seconds\n"; | |
std::cout << "Expires at: " << ctime(&now) << " + " << valid_for | |
<< " seconds\n"; | |
if (err_msg) { | ||
free(err_msg); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
std::cerr << "Error: " << e.what() << "\n"; | ||
return 1; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
|
||
int print_command(int argc, char *argv[]) { | ||
std::string cache_file; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
std::string cache_file; | ||
|
||
// Parse command line arguments for print command | ||
for (int i = 2; i < argc; i++) { // Start from 2 since argv[1] is "print" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[lint] reported by reviewdog 🐶
for (int i = 2; i < argc; i++) { // Start from 2 since argv[1] is "print" | |
for (int i = 2; i < argc; i++) { // Start from 2 since argv[1] is "print" |
This PR implements offline support for the scitokens library, enabling environments where external network access to fetch public keys is not available or desired.
Key Features Added
1. SCITOKENS_KEYCACHE_FILE Environment Variable
Added support for a new environment variable that points directly to a SQLite database file for the key cache, bypassing the normal cache location resolution:
export SCITOKENS_KEYCACHE_FILE=/path/to/offline.db
The cache location priority is now:
SCITOKENS_KEYCACHE_FILE
(highest priority - for offline use)XDG_CACHE_HOME
environment variable~/.cache
directory (lowest priority)2. Enhanced scitokens-keycache Command Line Tool
Completely redesigned the command-line utility with subcommands for comprehensive cache management:
scitokens-keycache add
Creates and populates offline cache files with JWKS data:
scitokens-keycache print
Displays a formatted table of all cached public keys with truncated values for terminal readability:
scitokens-keycache print [--cache-file /path/to/cache.db] # Output shows: Issuer | Key ID | Key Type | Expires | Next Update | Public Key (truncated)
scitokens-keycache location
Shows the active cache file location and accessibility status:
3. Enhanced API
Added a new C API function for programmatic storage of JWKS with explicit expiration times:
Implementation Details
get_cache_file()
inscitokens_cache.cpp
to check for the environment variable firstValidator
class withstore_jwks_with_expiry()
methodscitokens-keycache.cpp
with subcommand architectureint64_t
type compatibilityBackward Compatibility
All existing functionality remains unchanged. The new features are additive:
scitokens-keycache
usage patterns still work via theadd
subcommandTesting
Use Cases
This enables fully offline scitokens operation and enhanced cache management for:
The enhanced tool provides administrators with comprehensive visibility into cached keys and simplified workflows for offline deployments.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.