Skip to content

Commit 1bb6fea

Browse files
authored
Merge pull request #107 from scitokens/apply-lint
Empty commit to apply lint
2 parents 3187cae + 2aff6be commit 1bb6fea

File tree

13 files changed

+1485
-1125
lines changed

13 files changed

+1485
-1125
lines changed

.github/workflows/linter.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ jobs:
3636
with:
3737
github_token: ${{ secrets.github_token }} # For providing the commit authorization for the auto_fix feature
3838
clang_format: true
39-
clang_format_auto_fix: true
40-
auto_fix: true
41-
commit: true
42-
continue_on_error: false
39+
clang_format_auto_fix: false
40+
auto_fix: false
41+
commit: false
42+
continue_on_error: true
4343
git_email: github.event.commits[0].author.name # Uses the author's git email instead of the default git email associated with the action ("lint-action@samuelmeuli.com")
4444
clang_format_args: -style=file # Any additional arguments for clang_format
4545

src/create.cpp

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11

22
#include "scitokens.h"
33

4-
#include <stdlib.h>
54
#include <getopt.h>
5+
#include <stdlib.h>
66

77
#include <cstdio>
8-
#include <string>
9-
#include <vector>
108
#include <fstream>
119
#include <memory>
10+
#include <string>
11+
#include <vector>
1212

1313
namespace {
1414

15-
const char usage[] = \
16-
"\n"
17-
"Syntax: %s [--cred cred_file] [--key key_file] [--keyid kid]\n"
18-
" [--claim key=val] ...\n"
19-
"\n"
20-
" Options\n"
21-
" -h | --help Display usage\n"
22-
" -c | --cred <cred_file> File containing signing credential.\n"
23-
" -k | --key <key_file> File containing the signing private key.\n"
24-
" -K | --keyid <kid> Name of the token key.\n"
25-
" -i | --issuer <issuer> Issuer for the token.\n"
26-
" -p | --profile <profile> Token profile (wlcg, scitokens1, scitokens2, atjwt).\n"
27-
"\n";
28-
29-
const struct option long_options[] =
30-
{
31-
{"help", no_argument, NULL, 'h'},
32-
{"cred", required_argument, NULL, 'c'},
33-
{"key", required_argument, NULL, 'k'},
34-
{"keyid", required_argument, NULL, 'K'},
35-
{"issuer", required_argument, NULL, 'i'},
36-
{"claim", required_argument, NULL, 'C'},
37-
{"profile", required_argument, NULL, 'p'},
38-
{0, 0, 0, 0}
39-
};
15+
const char usage[] =
16+
"\n"
17+
"Syntax: %s [--cred cred_file] [--key key_file] [--keyid kid]\n"
18+
" [--claim key=val] ...\n"
19+
"\n"
20+
" Options\n"
21+
" -h | --help Display usage\n"
22+
" -c | --cred <cred_file> File containing signing "
23+
"credential.\n"
24+
" -k | --key <key_file> File containing the signing "
25+
"private key.\n"
26+
" -K | --keyid <kid> Name of the token key.\n"
27+
" -i | --issuer <issuer> Issuer for the token.\n"
28+
" -p | --profile <profile> Token profile (wlcg, scitokens1, "
29+
"scitokens2, atjwt).\n"
30+
"\n";
31+
32+
const struct option long_options[] = {{"help", no_argument, NULL, 'h'},
33+
{"cred", required_argument, NULL, 'c'},
34+
{"key", required_argument, NULL, 'k'},
35+
{"keyid", required_argument, NULL, 'K'},
36+
{"issuer", required_argument, NULL, 'i'},
37+
{"claim", required_argument, NULL, 'C'},
38+
{"profile", required_argument, NULL, 'p'},
39+
{0, 0, 0, 0}};
4040

4141
const char short_options[] = "hc:k:K:i:C:p:";
4242

@@ -46,10 +46,9 @@ std::vector<std::string> g_claims;
4646
int init_arguments(int argc, char *argv[]) {
4747

4848
int arg;
49-
while((arg = getopt_long(argc, argv, short_options, long_options, nullptr)) != -1)
50-
{
51-
switch (arg)
52-
{
49+
while ((arg = getopt_long(argc, argv, short_options, long_options,
50+
nullptr)) != -1) {
51+
switch (arg) {
5352
case 'h':
5453
printf(usage, argv[0]);
5554
exit(0);
@@ -112,7 +111,7 @@ int init_arguments(int argc, char *argv[]) {
112111
return 0;
113112
}
114113

115-
}
114+
} // namespace
116115

117116
int main(int argc, char *argv[]) {
118117

@@ -122,33 +121,33 @@ int main(int argc, char *argv[]) {
122121
}
123122

124123
std::ifstream priv_ifs(g_key);
125-
std::string private_contents( (std::istreambuf_iterator<char>(priv_ifs)),
126-
(std::istreambuf_iterator<char>())
127-
);
124+
std::string private_contents((std::istreambuf_iterator<char>(priv_ifs)),
125+
(std::istreambuf_iterator<char>()));
128126
std::ifstream pub_ifs(g_cred);
129-
std::string public_contents( (std::istreambuf_iterator<char>(pub_ifs)),
130-
(std::istreambuf_iterator<char>())
131-
);
127+
std::string public_contents((std::istreambuf_iterator<char>(pub_ifs)),
128+
(std::istreambuf_iterator<char>()));
132129

133130
char *err_msg;
134-
auto key_raw = scitoken_key_create(g_kid.c_str(), "ES256", public_contents.c_str(),
135-
private_contents.c_str(), &err_msg);
136-
std::unique_ptr<void, decltype(&scitoken_key_destroy)>
137-
key(key_raw, scitoken_key_destroy);
131+
auto key_raw =
132+
scitoken_key_create(g_kid.c_str(), "ES256", public_contents.c_str(),
133+
private_contents.c_str(), &err_msg);
134+
std::unique_ptr<void, decltype(&scitoken_key_destroy)> key(
135+
key_raw, scitoken_key_destroy);
138136
if (key_raw == nullptr) {
139137
fprintf(stderr, "Failed to generate a key: %s\n", err_msg);
140138
free(err_msg);
141139
return 1;
142140
}
143141

144-
std::unique_ptr<void, decltype(&scitoken_destroy)>
145-
token(scitoken_create(key_raw), scitoken_destroy);
142+
std::unique_ptr<void, decltype(&scitoken_destroy)> token(
143+
scitoken_create(key_raw), scitoken_destroy);
146144
if (token.get() == nullptr) {
147145
fprintf(stderr, "Failed to generate a new token.\n");
148146
return 1;
149147
}
150148

151-
rv = scitoken_set_claim_string(token.get(), "iss", g_issuer.c_str(), &err_msg);
149+
rv = scitoken_set_claim_string(token.get(), "iss", g_issuer.c_str(),
150+
&err_msg);
152151
if (rv) {
153152
fprintf(stderr, "Failed to set issuer: %s\n", err_msg);
154153
free(err_msg);
@@ -158,15 +157,18 @@ int main(int argc, char *argv[]) {
158157
for (const auto &claim : g_claims) {
159158
auto pos = claim.find("=");
160159
if (pos == std::string::npos) {
161-
fprintf(stderr, "Claim must contain a '=' character: %s\n", claim.c_str());
160+
fprintf(stderr, "Claim must contain a '=' character: %s\n",
161+
claim.c_str());
162162
return 1;
163163
}
164164
auto key = claim.substr(0, pos);
165165
auto val = claim.substr(pos + 1);
166166

167-
rv = scitoken_set_claim_string(token.get(), key.c_str(), val.c_str(), &err_msg);
167+
rv = scitoken_set_claim_string(token.get(), key.c_str(), val.c_str(),
168+
&err_msg);
168169
if (rv) {
169-
fprintf(stderr, "Failed to set claim (%s=%s): %s\n", key.c_str(), val.c_str(), err_msg);
170+
fprintf(stderr, "Failed to set claim (%s=%s): %s\n", key.c_str(),
171+
val.c_str(), err_msg);
170172
free(err_msg);
171173
return 1;
172174
}

src/list_access.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
#include "scitokens.h"
44

5-
int main(int argc, const char** argv) {
5+
int main(int argc, const char **argv) {
66
if (argc < 4) {
7-
std::cerr << "Usage: " << argv[0] << " (TOKEN) (ISSUER) (AUDIENCE)" << std::endl;
7+
std::cerr << "Usage: " << argv[0] << " (TOKEN) (ISSUER) (AUDIENCE)"
8+
<< std::endl;
89
return 1;
910
}
1011
std::string token(argv[1]);
@@ -21,10 +22,12 @@ int main(int argc, const char** argv) {
2122
std::cout << "Failed to deserialize a token: " << err_msg << std::endl;
2223
return 1;
2324
}
24-
std::cout << "Token deserialization successful. Checking authorizations." << std::endl;
25+
std::cout << "Token deserialization successful. Checking authorizations."
26+
<< std::endl;
2527
Enforcer enf;
2628
if (!(enf = enforcer_create(issuer.c_str(), aud_list, &err_msg))) {
27-
std::cout << "Failed to create a new enforcer object: " << err_msg << std::endl;
29+
std::cout << "Failed to create a new enforcer object: " << err_msg
30+
<< std::endl;
2831
return 1;
2932
}
3033
Acl *acls;
@@ -33,12 +36,12 @@ int main(int argc, const char** argv) {
3336
return 1;
3437
}
3538
std::cout << "Start of ACLs:" << std::endl;
36-
for (int idx=0; acls[idx].authz && acls[idx].resource; idx++) {
37-
std::cout << "ACL: " << acls[idx].authz << ":" << acls[idx].resource << std::endl;
39+
for (int idx = 0; acls[idx].authz && acls[idx].resource; idx++) {
40+
std::cout << "ACL: " << acls[idx].authz << ":" << acls[idx].resource
41+
<< std::endl;
3842
}
3943
std::cout << "End of ACLs:" << std::endl;
4044

4145
enforcer_destroy(enf);
4246
return 0;
4347
}
44-

0 commit comments

Comments
 (0)