Merge branch 'fronkdev' into 'master'
OFAA OAID API v2 See merge request fronk/thetool!1995
This commit is contained in:
@@ -27,18 +27,17 @@ $headers = [
|
||||
];
|
||||
|
||||
$confirm_url = str_replace("{oaid}", $oaid, $ep_confirm_oaid);
|
||||
$out = putRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
|
||||
if($output == "__err__401") {
|
||||
$out = patchRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
|
||||
if($out == "__err__401") {
|
||||
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
|
||||
$headers = [
|
||||
"Authorization: Bearer $access_token",
|
||||
"Accept: application/json",
|
||||
"Content-type: application/json",
|
||||
];
|
||||
$out = putRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
|
||||
$u++;
|
||||
$out = patchRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
|
||||
}
|
||||
|
||||
echo "$oaid_name confirmed.\n";
|
||||
echo "$oaid confirmed.\n";
|
||||
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ $u = 0;
|
||||
echo "Creating and confirming $batch_size version ".$content['version']." OAIDs for tenant ".$content['tenant']."\n";
|
||||
|
||||
for($i = 0; $i < $batch_size; $i++) {
|
||||
$content['external_id'] = guidv4();
|
||||
$content['customer_reference'] = guidv4();
|
||||
|
||||
$output = postRestUrl($ep_request_oaid, $headers, $content, "application/json");
|
||||
if($output == "__err__401") {
|
||||
@@ -61,16 +61,16 @@ for($i = 0; $i < $batch_size; $i++) {
|
||||
$c++;
|
||||
|
||||
$oaid = $output_json->oaid;
|
||||
$tenant = $output_json->tenant;
|
||||
//$tenant = $output_json->tenant;
|
||||
$token = $output_json->token;
|
||||
$status = $output_json->status;
|
||||
$external_id = $output_json->external_id;
|
||||
$customer_reference = $output_json->customer_reference;
|
||||
|
||||
//echo "oaid: $oaid, tenant: $tenant, token: $token, status: $status, external_id: $external_id\n";
|
||||
|
||||
if($token == "requested") {
|
||||
$confirm_url = str_replace("{oaid}", $oaid, $ep_confirm_oaid);
|
||||
$out = putRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
|
||||
$out = patchRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
|
||||
if($out == "__err__401") {
|
||||
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
|
||||
$headers = [
|
||||
@@ -78,7 +78,7 @@ for($i = 0; $i < $batch_size; $i++) {
|
||||
"Accept: application/json",
|
||||
"Content-type: application/json",
|
||||
];
|
||||
$out = putRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
|
||||
$out = patchRestUrl($confirm_url, $headers, ["token" => "confirmed"], "application/json");
|
||||
}
|
||||
echo ".";
|
||||
$u++;
|
||||
|
||||
@@ -19,7 +19,7 @@ $client_secret = "6e74e7e8-0cc2-43df-83c2-12937452b916";
|
||||
$ep_mgm_credits = $baseurl."/pip/mgm/credits/";
|
||||
$ep_list_oaids = $baseurl."/pip/codes/";
|
||||
$ep_request_oaid = $baseurl."/pip/codes/";
|
||||
$ep_confirm_oaid = $baseurl."/pip/codes/{oaid}/token/";
|
||||
$ep_confirm_oaid = $baseurl."/pip/codes/{oaid}/";
|
||||
|
||||
//$default_scope = ["oaid:mgm:read","oaid:codes:read","oaid:codes:write"];
|
||||
$default_scope = ["read","write"]; // since v2
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
$rest_last_api_request_nexturl = "";
|
||||
|
||||
function fetchAccessToken($oauth_url, $client_id, $client_secret, $scopes = ["oaid:codes:read"]) {
|
||||
//echo "called fetchAccessToken $oauth_url\n";
|
||||
global $token_file;
|
||||
@@ -30,6 +32,8 @@ function fetchAccessToken($oauth_url, $client_id, $client_secret, $scopes = ["oa
|
||||
}
|
||||
|
||||
function getRestUrl($url, $headers, $params = [], $debug = false) {
|
||||
global $rest_last_api_request_nexturl;
|
||||
|
||||
//echo "called getRestUrl $url\n";
|
||||
$ctx_options = ["http" => [
|
||||
"ignore_errors" => true,
|
||||
@@ -50,25 +54,44 @@ function getRestUrl($url, $headers, $params = [], $debug = false) {
|
||||
$ctx = stream_context_create($ctx_options);
|
||||
$output = file_get_contents($_url, false, $ctx);
|
||||
|
||||
if($debug) {
|
||||
echo $output;
|
||||
}
|
||||
|
||||
$_return = "";
|
||||
$http_status_line = "";
|
||||
|
||||
foreach($http_response_header as $h_line) {
|
||||
$m = [];
|
||||
if($debug) {
|
||||
echo "HEADER: " . trim($h_line) . "\n";
|
||||
}
|
||||
if(preg_match('/HTTP\/\d+(?:\.\d+) ([245]\d+)/', $h_line, $m)) {
|
||||
$http_status_line = $h_line;
|
||||
$response_code = $m[1];
|
||||
if(substr($response_code, 0, 1) == "2") {
|
||||
return $output;
|
||||
$_return = $output;
|
||||
} elseif($response_code == "401") {
|
||||
return "__err__401";
|
||||
} else {
|
||||
die("getRestUrl():\n$h_line\n$output");
|
||||
$_return = "__err__401";
|
||||
}
|
||||
}
|
||||
|
||||
if(preg_match('/^Link: .*<([^>]+)>; rel=next/', $h_line, $m)) {
|
||||
$rest_last_api_request_nexturl = $m[1];
|
||||
}
|
||||
}
|
||||
|
||||
if(!$_return) die("getRestUrl():\n$http_status_line\n$output");
|
||||
return $_return;
|
||||
}
|
||||
|
||||
function putRestUrl($url, $headers, $content, $content_type = "application/x-www-form-urlencoded", $follow_location = true, $debug = false) {
|
||||
return postRestUrl($url, $headers, $content, $content_type, $follow_location, $debug, 'PUT');
|
||||
}
|
||||
|
||||
function patchRestUrl($url, $headers, $content, $content_type = "application/x-www-form-urlencoded", $follow_location = true, $debug = false) {
|
||||
return postRestUrl($url, $headers, $content, $content_type, $follow_location, $debug, 'PATCH');
|
||||
}
|
||||
|
||||
function postRestUrl($url, $headers, $content, $content_type = "application/x-www-form-urlencoded", $follow_location = true, $debug = false, $method = "POST") {
|
||||
//echo "called postResturl $url\n";
|
||||
$ctx_options = ["http" => [
|
||||
@@ -84,6 +107,9 @@ function postRestUrl($url, $headers, $content, $content_type = "application/x-ww
|
||||
if($method == "PUT") {
|
||||
$ctx_options["http"]["method"] = "PUT";
|
||||
}
|
||||
if($method == "PATCH") {
|
||||
$ctx_options["http"]["method"] = "PATCH";
|
||||
}
|
||||
|
||||
if($content_type == "application/x-www-form-urlencoded") {
|
||||
$ctx_options["http"]["content"] = http_build_query($content);
|
||||
|
||||
@@ -15,15 +15,24 @@ if(!$access_token) {
|
||||
$headers[] = "Accept: application/json";
|
||||
$headers[] = "Authorization: Bearer $access_token";
|
||||
|
||||
$request_url = $ep_list_oaids;
|
||||
$page_size = 500;
|
||||
$page = 1;
|
||||
$page_param = ["_page_size" => $page_size];
|
||||
$last_ref = false;
|
||||
while(1) {
|
||||
$output = getRestUrl($ep_list_oaids, $headers, ["tenant"=> $tenant, "_page" => $page]);
|
||||
if($rest_last_api_request_nexturl) {
|
||||
$request_url = $rest_last_api_request_nexturl;
|
||||
$page_param = [];
|
||||
}
|
||||
|
||||
$output = getRestUrl($request_url, $headers, $page_param);
|
||||
if($output == "__err__401") {
|
||||
$access_token = fetchAccessToken($oauth_url, $client_id, $client_secret, $default_scope);
|
||||
$headers = [];
|
||||
$headers[] = "Accept: application/json";
|
||||
$headers[] = "Authorization: Bearer $access_token";
|
||||
$output = getRestUrl($ep_list_oaids, $headers, ["tenant"=> $tenant, "_page" => $page]);
|
||||
$output = getRestUrl($request_url, $headers, $page_param);
|
||||
}
|
||||
|
||||
$output_values = json_decode($output);
|
||||
@@ -39,12 +48,14 @@ while(1) {
|
||||
|
||||
foreach($output_values as $oaid_obj) {
|
||||
echo $oaid_obj->oaid.";";
|
||||
echo $oaid_obj->external_id.";";
|
||||
echo $oaid_obj->customer_reference.";";
|
||||
echo ";";
|
||||
if($oaid_obj->token != "confirmed") {
|
||||
file_put_contents( "php://stderr", "; ".$oaid_obj->token );
|
||||
}
|
||||
echo "\n";
|
||||
$last_ref = $oaid_obj->customer_reference;
|
||||
//$last_ref = $oaid_obj->oaid;
|
||||
}
|
||||
$page++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user