function get_projects_for_member($sa_url, $signer, $member_id, $is_member) { if (!is_object($signer)) { throw new InvalidArgumentException('Null signer'); } if (!$signer instanceof GeniUser) { /* Signer must be a GeniUser because we need its URN. */ throw new InvalidArgumentException('Signer is not a GeniUser'); } $client = XMLRPCClient::get_client($sa_url, $signer); $member_urn = get_member_urn(sa_to_ma_url($sa_url), $signer, $member_id); $rows = $client->lookup_projects_for_member($member_urn, $client->creds(), $client->options()); if ($is_member) { $project_uuids = array_map(function ($row) { return $row['PROJECT_UID']; }, array_values($rows)); return $project_uuids; } // if not a member $current = array(); foreach ($rows as $row) { if ($row['EXPIRED'] == false) { $current[] = $row; } } $project_uuids = array_map(function ($row) { return $row['PROJECT_UID']; }, array_values($current)); //print "<p> privatekey ".print_r($signer->privateKey(), true)."<\p>\n"; //print "<p> cert ".print_r($signer->certificate(), true)."<\p>\n"; $options = array('match' => array('PROJECT_EXPIRED' => "false"), 'filter' => array('PROJECT_UID')); $options = array_merge($options, $client->options()); $rows = $client->lookup_projects($client->creds(), $options); $all_uuids = array_map(function ($row) { return $row['PROJECT_UID']; }, array_values($rows)); return array_values(array_diff($all_uuids, $project_uuids)); }
function get_slices_for_member($sa_url, $signer, $member_id, $is_member, $role = null) { $member_urn = get_member_urn(sa_to_ma_url($sa_url), $signer, $member_id); $client = XMLRPCClient::get_client($sa_url, $signer); if ($is_member) { $options = array(); if (!is_null($role)) { $options = array('match' => array('SLICE_ROLE' => $role)); } $options = array_merge($options, $client->options()); $results = $client->lookup_slices_for_member($member_urn, $client->creds(), $options); } else { // CHAPI: TODO: implement is_member = FALSE error_log("get_slices_for_member using is_member=false is unimplemented."); return array(); } // Convert columns from 'external' to 'internal' format $converted_results = array(); foreach ($results as $row) { $converted_row = array(SA_SLICE_MEMBER_TABLE_FIELDNAME::SLICE_ID => $row['SLICE_UID'], SA_SLICE_MEMBER_TABLE_FIELDNAME::ROLE => $row['SLICE_ROLE'], SA_SLICE_TABLE_FIELDNAME::EXPIRED => $row['EXPIRED']); $converted_row = convert_role($converted_row); $converted_results[] = $converted_row; } $results = $converted_results; // error_log("GSFM.RESULTS = " . print_r($results, true)); return $results; }
/** * Get the outside cert and private key for member. * * @return Array containing certificate and private_key as key_value * pairs. If no private_key exists, that key will not be * included. If no outside certificate exists, return NULL * (instead of an array). */ function ma_lookup_certificate($ma_url, $signer, $member_id) { $member_urn = get_member_urn($ma_url, $signer, $member_id); if (is_null($member_urn)) { error_log("ma_lookup_cert: No member URN found for ID: " . $member_id); return NULL; } $client = XMLRPCClient::get_client($ma_url, $signer); $public_options = array('match' => array('MEMBER_UID' => $member_id), 'filter' => array('_GENI_MEMBER_SSL_CERTIFICATE', '_GENI_MEMBER_SSL_EXPIRATION')); $public_options = array_merge($public_options, $client->options()); $public_res = $client->lookup_public_member_info($client->creds(), $public_options); if (!array_key_exists($member_urn, $public_res)) { error_log("No public member info available for {$member_urn}" . " in ma_lookup_certificate"); return NULL; } $certificate = NULL; if (array_key_exists('_GENI_MEMBER_SSL_CERTIFICATE', $public_res[$member_urn])) { $certificate = $public_res[$member_urn]['_GENI_MEMBER_SSL_CERTIFICATE']; } if ($certificate) { $result = array(MA_ARGUMENT::CERTIFICATE => $certificate); } else { // If there is no certificate, return NULL. return NULL; } if (array_key_exists('_GENI_MEMBER_SSL_EXPIRATION', $public_res[$member_urn])) { // Convert expiration to DateTime from string $expiration = $public_res[$member_urn]['_GENI_MEMBER_SSL_EXPIRATION']; $expiration = new DateTime($expiration); $result[MA_ARGUMENT::EXPIRATION] = $expiration; } $private_options = array('match' => array('MEMBER_UID' => $member_id), 'filter' => array('_GENI_MEMBER_SSL_PRIVATE_KEY')); $private_options = array_merge($private_options, $client->options()); $private_res = $client->lookup_private_member_info($client->creds(), $private_options); if (array_key_exists($member_urn, $private_res)) { $private_key = $private_res[$member_urn]['_GENI_MEMBER_SSL_PRIVATE_KEY']; if ($private_key) { $result[MA_ARGUMENT::PRIVATE_KEY] = $private_key; } } return $result; }