Skip to content

Commit

Permalink
https://telecominfraproject.atlassian.net/browse/WIFI-7831
Browse files Browse the repository at this point in the history
Signed-off-by: stephb9959 <[email protected]>
  • Loading branch information
stephb9959 committed Sep 12, 2023
1 parent 797a7f2 commit 4fecee4
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/OpenRoamin_GlobalReach.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,40 @@ namespace OpenWifi {
ProvObjects::GLBLRCertificateInfo &NewCertificate) {

try {
std::cout << __LINE__ << std::endl;
auto BearerToken = MakeToken(GlobalReachAccountId);
Poco::URI URI{"https://config.openro.am/v1/radsec/issue"};
std::string Path(URI.getPathAndQuery());
std::cout << __LINE__ << std::endl;
Poco::Net::HTTPRequest Request(Poco::Net::HTTPRequest::HTTP_POST, Path,
Poco::Net::HTTPMessage::HTTP_1_1);
std::cout << __LINE__ << std::endl;

Request.add("Authorization", "Bearer " + BearerToken);
std::cout << __LINE__ << std::endl;

Poco::Net::HTTPSClientSession Session(URI.getHost(), URI.getPort());
Session.setTimeout(Poco::Timespan(10000, 10000));
std::cout << __LINE__ << std::endl;
Poco::JSON::Object CertRequestBody;
CertRequestBody.set("name", Name);
CertRequestBody.set("csr", CSR);
std::cout << __LINE__ << std::endl;

std::ostringstream os;
std::cout << __LINE__ << std::endl;
CertRequestBody.stringify(os);
Request.setContentType("application/json");
Request.setContentLength((long) os.str().size());

std::cout << __LINE__ << std::endl;
auto &Body = Session.sendRequest(Request);
Body << os.str();

std::cout << __LINE__ << std::endl;
Poco::Net::HTTPResponse Response;
std::istream &is = Session.receiveResponse(Response);
std::cout << __LINE__ << std::endl;
if (Response.getStatus() == Poco::Net::HTTPResponse::HTTP_OK) {
Poco::JSON::Parser P;
auto Result = P.parse(is).extract<Poco::JSON::Object::Ptr>();
Expand All @@ -80,8 +90,10 @@ namespace OpenWifi {
NewCertificate.certificateChain = Result->get("certificate_chain").toString();
NewCertificate.certificateId = Result->get("certificate_id").toString();
NewCertificate.expiresAt = Result->get("expires_at");
std::cout << __LINE__ << std::endl;
return true;
}
std::cout << Response.getStatus() << std::endl;
} catch( const Poco::Exception &E) {
poco_error(Logger(),fmt::format("Could not create a new RADSEC certificate: {},{}",E.name(),E.displayText()));
}
Expand Down
43 changes: 40 additions & 3 deletions test_scripts/curl/cli
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,7 @@ getsystemconfiguration() {
}

creategraccount() {
payload="{ \"name\" : \"Test account\" , \"country\" : \"CA\", \"province\" : \"BC\" , \"city\" : \"Vancouver\", \"organization\" : \"Arilia Wireless Inc.\", \"commonName\" : \"arilia.com\", \"GlobalReachAcctId\" : \"bd63aaa7-b14d-4cdb-85ae-8de6cf2cfa31\", \"privateKey\" : \"-----BEGIN PRIVATE KEY-----MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgl1FpARtuOtw1F9sR2DD82jh6sZFGRn619IY0rmNIFEuhRANCAATB7ji6OF/+heGRCocgVNhw4QGvaL9Kp8F6ZqqZ3aMewRMOfzi3TQaXN12FNBsvXnptx5vk8GAzZk6UAzzvMBVK-----END PRIVATE KEY-----\" }"
echo $payload | jq

payload="{ \"name\" : \"Test account\" , \"country\" : \"CA\", \"province\" : \"BC\" , \"city\" : \"Vancouver\", \"organization\" : \"Arilia Wireless Inc.\", \"commonName\" : \"arilia.com\", \"GlobalReachAcctId\" : \"bd63aaa7-b14d-4cdb-85ae-8de6cf2cfa31\", \"privateKey\" : \"-----BEGIN PRIVATE KEY-----\nMIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgl1FpARtuOtw1F9sR2DD82jh6sZFGRn619IY0rmNIFEuhRANCAATB7ji6OF/+heGRCocgVNhw4QGvaL9Kp8F6ZqqZ3aMewRMOfzi3TQaXN12FNBsvXnptx5vk8GAzZk6UAzzvMBVK\n-----END PRIVATE KEY-----\" }"
curl ${FLAGS} -X POST "https://${OWPROV}/api/v1/openroaming/globalreach/account/0" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${token}" \
Expand All @@ -629,6 +627,41 @@ creategraccount() {
jq < ${result_file}
}

getgraccount() {
curl ${FLAGS} -X GET "https://${OWPROV}/api/v1/openroaming/globalreach/account/$1" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${token}" \
-H "Accept: application/json" > ${result_file}
jq < ${result_file}
}

deletegraccount() {
curl ${FLAGS} -X DELETE "https://${OWPROV}/api/v1/openroaming/globalreach/account/$1" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${token}" \
-H "Accept: application/json" > ${result_file}
jq < ${result_file}
}

getgraccounts() {
curl ${FLAGS} -X GET "https://${OWPROV}/api/v1/openroaming/globalreach/accounts" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${token}" \
-H "Accept: application/json" > ${result_file}
jq < ${result_file}
}

creategrcert() {
payload="{ \"name\" : \"$2\" }"
curl ${FLAGS} -X POST "https://${OWPROV}/api/v1/openroaming/globalreach/certificate/$1/0" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${token}" \
-H "Accept: application/json" \
-d "$payload" > ${result_file}
jq < ${result_file}

}

shopt -s nocasematch
case "$1" in
"login") login; echo "You are logged in..." ; logout ;;
Expand Down Expand Up @@ -686,6 +719,10 @@ case "$1" in
"venueupgraderevisions") login; venueupgraderevisions "$2"; logout;;
"getsystemconfiguration") login; getsystemconfiguration "$2"; logout;;
"creategraccount") login; creategraccount ; logout;;
"getgraccount") login; getgraccount "$2"; logout;;
"getgraccounts") login; getgraccounts ; logout;;
"creategrcert") login; creategrcert "$2" "$3"; logout;;
"deletegraccount") login; deletegraccount "$2"; logout;;
"getvenuesperrrm") login; getvenuesperrrm "$2"; logout;;
*) help ;;
esac
Expand Down

0 comments on commit 4fecee4

Please sign in to comment.