Skip to content

Commit 1ead755

Browse files
Copilotbbockelm
andcommitted
Fix clang-format linter issues
- Run clang-format on all modified files to fix formatting - No functional changes, only whitespace and formatting adjustments Co-authored-by: bbockelm <1093447+bbockelm@users.noreply.github.com>
1 parent 0f45e25 commit 1ead755

File tree

4 files changed

+136
-97
lines changed

4 files changed

+136
-97
lines changed

src/scitokens.cpp

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
#include <algorithm>
2+
#include <array>
13
#include <atomic>
4+
#include <cctype>
5+
#include <cstdlib>
26
#include <exception>
7+
#include <stdexcept>
38
#include <string.h>
49
#include <sys/stat.h>
5-
#include <cstdlib>
6-
#include <algorithm>
7-
#include <cctype>
8-
#include <array>
9-
#include <stdexcept>
1010

1111
#include "scitokens.h"
1212
#include "scitokens_internal.h"
@@ -35,39 +35,40 @@ std::string to_lowercase(const std::string &str) {
3535

3636
// Load configuration from environment variables on library initialization
3737
void load_config_from_environment() {
38-
// List of known configuration keys with their types and corresponding env var names
38+
// List of known configuration keys with their types and corresponding env
39+
// var names
3940
struct ConfigMapping {
4041
const char *config_key;
4142
const char *env_var_suffix; // After SCITOKEN_CONFIG_
4243
bool is_int;
4344
};
44-
45-
const std::array<ConfigMapping, 4> known_configs = {{
46-
{"keycache.update_interval_s", "KEYCACHE_UPDATE_INTERVAL_S", true},
47-
{"keycache.expiration_interval_s", "KEYCACHE_EXPIRATION_INTERVAL_S", true},
48-
{"keycache.cache_home", "KEYCACHE_CACHE_HOME", false},
49-
{"tls.ca_file", "TLS_CA_FILE", false}
50-
}};
51-
45+
46+
const std::array<ConfigMapping, 4> known_configs = {
47+
{{"keycache.update_interval_s", "KEYCACHE_UPDATE_INTERVAL_S", true},
48+
{"keycache.expiration_interval_s", "KEYCACHE_EXPIRATION_INTERVAL_S",
49+
true},
50+
{"keycache.cache_home", "KEYCACHE_CACHE_HOME", false},
51+
{"tls.ca_file", "TLS_CA_FILE", false}}};
52+
5253
const char *prefix = "SCITOKEN_CONFIG_";
53-
54+
5455
// Check each known configuration
5556
for (const auto &config : known_configs) {
5657
// Build the full environment variable name
5758
std::string env_var = prefix + std::string(config.env_var_suffix);
58-
59+
5960
// Also try case variations (uppercase, lowercase, mixed)
6061
const char *env_value = std::getenv(env_var.c_str());
6162
if (!env_value) {
6263
// Try with lowercase
6364
std::string env_var_lower = to_lowercase(env_var);
6465
env_value = std::getenv(env_var_lower.c_str());
6566
}
66-
67+
6768
if (!env_value) {
6869
continue; // Not set in environment
6970
}
70-
71+
7172
char *err_msg = nullptr;
7273
if (config.is_int) {
7374
try {
@@ -81,7 +82,7 @@ void load_config_from_environment() {
8182
} else {
8283
scitoken_config_set_str(config.config_key, env_value, &err_msg);
8384
}
84-
85+
8586
// Free error message if any (we ignore errors during initialization)
8687
if (err_msg) {
8788
free(err_msg);
@@ -90,8 +91,7 @@ void load_config_from_environment() {
9091
}
9192

9293
// Use constructor attribute to run on library load
93-
__attribute__((constructor))
94-
void init_scitokens_config() {
94+
__attribute__((constructor)) void init_scitokens_config() {
9595
load_config_from_environment();
9696
}
9797

@@ -323,10 +323,12 @@ int scitoken_get_expiration(const SciToken token, long long *expiry,
323323
// Float value - convert to integer (truncate)
324324
// Float value - convert to integer using std::floor().
325325
// This ensures expiration is not extended by fractional seconds.
326-
result = static_cast<long long>(std::floor(claim_value.get<double>()));
326+
result =
327+
static_cast<long long>(std::floor(claim_value.get<double>()));
327328
} else {
328329
if (err_msg) {
329-
*err_msg = strdup("'exp' claim must be a number (integer or float)");
330+
*err_msg =
331+
strdup("'exp' claim must be a number (integer or float)");
330332
}
331333
return -1;
332334
}
@@ -1157,9 +1159,9 @@ int scitoken_config_set_str(const char *key, const char *value,
11571159
return -1;
11581160
}
11591161
} else if (_key == "tls.ca_file") {
1160-
configurer::Configuration::set_tls_ca_file(value ? std::string(value) : "");
1161-
}
1162-
else {
1162+
configurer::Configuration::set_tls_ca_file(value ? std::string(value)
1163+
: "");
1164+
} else {
11631165
if (err_msg) {
11641166
*err_msg = strdup("Key not recognized.");
11651167
}

src/scitokens_internal.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,27 @@ class Configuration {
5151

5252
private:
5353
// Accessor functions for construct-on-first-use idiom
54-
static std::atomic_int& get_next_update_delta_ref() {
54+
static std::atomic_int &get_next_update_delta_ref() {
5555
static std::atomic_int instance{600};
5656
return instance;
5757
}
58-
static std::atomic_int& get_expiry_delta_ref() {
58+
static std::atomic_int &get_expiry_delta_ref() {
5959
static std::atomic_int instance{4 * 24 * 3600};
6060
return instance;
6161
}
62-
static std::shared_ptr<std::string>& get_cache_home_ref() {
63-
static std::shared_ptr<std::string> instance = std::make_shared<std::string>("");
62+
static std::shared_ptr<std::string> &get_cache_home_ref() {
63+
static std::shared_ptr<std::string> instance =
64+
std::make_shared<std::string>("");
6465
return instance;
6566
}
66-
static std::shared_ptr<std::string>& get_tls_ca_file_ref() {
67-
static std::shared_ptr<std::string> instance = std::make_shared<std::string>("");
67+
static std::shared_ptr<std::string> &get_tls_ca_file_ref() {
68+
static std::shared_ptr<std::string> instance =
69+
std::make_shared<std::string>("");
6870
return instance;
6971
}
70-
71-
// Keep old declarations for backwards compatibility (will forward to accessor functions)
72+
73+
// Keep old declarations for backwards compatibility (will forward to
74+
// accessor functions)
7275
static std::atomic_int m_next_update_delta;
7376
static std::atomic_int m_expiry_delta;
7477
static std::shared_ptr<std::string> m_cache_home;

test/main.cpp

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ TEST_F(SerializeTest, ExplicitTime) {
504504

505505
TEST_F(SerializeTest, GetExpirationErrorHandling) {
506506
char *err_msg = nullptr;
507-
507+
508508
// Test NULL token handling
509509
long long expiry;
510510
auto rv = scitoken_get_expiration(nullptr, &expiry, &err_msg);
@@ -513,27 +513,28 @@ TEST_F(SerializeTest, GetExpirationErrorHandling) {
513513
EXPECT_STREQ(err_msg, "Token cannot be NULL");
514514
free(err_msg);
515515
err_msg = nullptr;
516-
517-
// Test NULL expiry parameter handling
516+
517+
// Test NULL expiry parameter handling
518518
rv = scitoken_get_expiration(m_token.get(), nullptr, &err_msg);
519519
ASSERT_FALSE(rv == 0);
520520
ASSERT_TRUE(err_msg != nullptr);
521521
EXPECT_STREQ(err_msg, "Expiry output parameter cannot be NULL");
522522
free(err_msg);
523523
err_msg = nullptr;
524-
524+
525525
// Test normal operation works
526526
char *token_value = nullptr;
527527
rv = scitoken_serialize(m_token.get(), &token_value, &err_msg);
528528
ASSERT_TRUE(rv == 0) << err_msg;
529-
530-
rv = scitoken_deserialize_v2(token_value, m_read_token.get(), nullptr, &err_msg);
529+
530+
rv = scitoken_deserialize_v2(token_value, m_read_token.get(), nullptr,
531+
&err_msg);
531532
ASSERT_TRUE(rv == 0) << err_msg;
532-
533+
533534
rv = scitoken_get_expiration(m_read_token.get(), &expiry, &err_msg);
534535
ASSERT_TRUE(rv == 0) << err_msg;
535536
ASSERT_TRUE(expiry > 0);
536-
537+
537538
free(token_value);
538539
}
539540

@@ -725,7 +726,8 @@ TEST_F(KeycacheTest, SetGetTest) {
725726
TEST_F(KeycacheTest, SetGetConfiguredCacheHome) {
726727
// Set cache home
727728
char cache_path[FILENAME_MAX];
728-
ASSERT_TRUE(getcwd(cache_path, sizeof(cache_path)) != nullptr); // Side effect gets cwd
729+
ASSERT_TRUE(getcwd(cache_path, sizeof(cache_path)) !=
730+
nullptr); // Side effect gets cwd
729731
char *err_msg = nullptr;
730732
std::string key = "keycache.cache_home";
731733

@@ -947,71 +949,83 @@ class EnvConfigTest : public ::testing::Test {
947949
void SetUp() override {
948950
// Save original config values
949951
char *err_msg = nullptr;
950-
original_update_interval = scitoken_config_get_int("keycache.update_interval_s", &err_msg);
951-
original_expiry_interval = scitoken_config_get_int("keycache.expiration_interval_s", &err_msg);
952-
952+
original_update_interval =
953+
scitoken_config_get_int("keycache.update_interval_s", &err_msg);
954+
original_expiry_interval =
955+
scitoken_config_get_int("keycache.expiration_interval_s", &err_msg);
956+
953957
char *cache_home = nullptr;
954958
scitoken_config_get_str("keycache.cache_home", &cache_home, &err_msg);
955959
if (cache_home) {
956960
original_cache_home = cache_home;
957961
free(cache_home);
958962
}
959-
963+
960964
char *ca_file = nullptr;
961965
scitoken_config_get_str("tls.ca_file", &ca_file, &err_msg);
962966
if (ca_file) {
963967
original_ca_file = ca_file;
964968
free(ca_file);
965969
}
966970
}
967-
971+
968972
void TearDown() override {
969973
// Restore original config values
970974
char *err_msg = nullptr;
971-
scitoken_config_set_int("keycache.update_interval_s", original_update_interval, &err_msg);
972-
scitoken_config_set_int("keycache.expiration_interval_s", original_expiry_interval, &err_msg);
973-
scitoken_config_set_str("keycache.cache_home", original_cache_home.c_str(), &err_msg);
974-
scitoken_config_set_str("tls.ca_file", original_ca_file.c_str(), &err_msg);
975+
scitoken_config_set_int("keycache.update_interval_s",
976+
original_update_interval, &err_msg);
977+
scitoken_config_set_int("keycache.expiration_interval_s",
978+
original_expiry_interval, &err_msg);
979+
scitoken_config_set_str("keycache.cache_home",
980+
original_cache_home.c_str(), &err_msg);
981+
scitoken_config_set_str("tls.ca_file", original_ca_file.c_str(),
982+
&err_msg);
975983
}
976-
984+
977985
int original_update_interval = 600;
978986
int original_expiry_interval = 4 * 24 * 3600;
979987
std::string original_cache_home;
980988
std::string original_ca_file;
981989
};
982990

983991
TEST_F(EnvConfigTest, IntConfigFromEnv) {
984-
// Note: This test verifies that the environment variable was read at library load time
985-
// We can't test setting environment variables after library load in the same process
986-
// This test would need to be run with environment variables set before starting the test
987-
992+
// Note: This test verifies that the environment variable was read at
993+
// library load time We can't test setting environment variables after
994+
// library load in the same process This test would need to be run with
995+
// environment variables set before starting the test
996+
988997
// Test that we can manually set and get config values
989998
char *err_msg = nullptr;
990999
int test_value = 1234;
991-
auto rv = scitoken_config_set_int("keycache.update_interval_s", test_value, &err_msg);
1000+
auto rv = scitoken_config_set_int("keycache.update_interval_s", test_value,
1001+
&err_msg);
9921002
ASSERT_EQ(rv, 0) << (err_msg ? err_msg : "");
993-
994-
int retrieved = scitoken_config_get_int("keycache.update_interval_s", &err_msg);
1003+
1004+
int retrieved =
1005+
scitoken_config_get_int("keycache.update_interval_s", &err_msg);
9951006
EXPECT_EQ(retrieved, test_value) << (err_msg ? err_msg : "");
996-
997-
if (err_msg) free(err_msg);
1007+
1008+
if (err_msg)
1009+
free(err_msg);
9981010
}
9991011

10001012
TEST_F(EnvConfigTest, StringConfigFromEnv) {
10011013
// Test that we can manually set and get string config values
10021014
char *err_msg = nullptr;
10031015
const char *test_path = "/tmp/test_cache";
1004-
auto rv = scitoken_config_set_str("keycache.cache_home", test_path, &err_msg);
1016+
auto rv =
1017+
scitoken_config_set_str("keycache.cache_home", test_path, &err_msg);
10051018
ASSERT_EQ(rv, 0) << (err_msg ? err_msg : "");
1006-
1019+
10071020
char *output = nullptr;
10081021
rv = scitoken_config_get_str("keycache.cache_home", &output, &err_msg);
10091022
ASSERT_EQ(rv, 0) << (err_msg ? err_msg : "");
10101023
ASSERT_TRUE(output != nullptr);
10111024
EXPECT_STREQ(output, test_path);
1012-
1025+
10131026
free(output);
1014-
if (err_msg) free(err_msg);
1027+
if (err_msg)
1028+
free(err_msg);
10151029
}
10161030

10171031
int main(int argc, char **argv) {

0 commit comments

Comments
 (0)