change Metaverse API from setting

This commit is contained in:
Kasen IO 2019-12-17 00:03:59 +01:00 committed by Thijs Wenker
parent 7f56c090f8
commit c34cd996df
29 changed files with 123 additions and 57 deletions

View file

@ -22,6 +22,7 @@
#include <ResourceManager.h>
#include <NetworkAccessManager.h>
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
#include <EntityItem.h>
#include <EntityItemProperties.h>
#include "ClientTraitsHandler.h"
@ -235,7 +236,7 @@ void MixerAvatar::requestCurrentOwnership() {
QNetworkRequest networkRequest;
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QUrl requestURL = NetworkingConstants::METAVERSE_SERVER_URL();
QUrl requestURL = MetaverseAPI::getCurrentMetaverseServerURL();
requestURL.setPath(POP_MARKETPLACE_API);
networkRequest.setUrl(requestURL);

View file

@ -22,6 +22,7 @@
#include <plugins/PluginManager.h>
#include <EntityEditFilters.h>
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
#include <hfm/ModelFormatRegistry.h>
#include "../AssignmentDynamicFactory.h"

View file

@ -38,6 +38,7 @@
#include <HTTPConnection.h>
#include <LogUtils.h>
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
#include <udt/PacketHeaders.h>
#include <SettingHandle.h>
#include <SharedUtil.h>
@ -121,7 +122,7 @@ bool DomainServer::forwardMetaverseAPIRequest(HTTPConnection* connection,
root.insert(requestSubobjectKey, subobject);
QJsonDocument doc { root };
QUrl url { NetworkingConstants::METAVERSE_SERVER_URL().toString() + metaversePath };
QUrl url{ MetaverseAPI::getCurrentMetaverseServerURL().toString() + metaversePath };
QNetworkRequest req(url);
req.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
@ -516,7 +517,7 @@ bool DomainServer::optionallySetupOAuth() {
// if we don't have an oauth provider URL then we default to the default node auth url
if (_oauthProviderURL.isEmpty()) {
_oauthProviderURL = NetworkingConstants::METAVERSE_SERVER_URL();
_oauthProviderURL = MetaverseAPI::getCurrentMetaverseServerURL();
}
_oauthClientSecret = QProcessEnvironment::systemEnvironment().value(OAUTH_CLIENT_SECRET_ENV);
@ -2222,7 +2223,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
return true;
} else if (url.path() == URI_API_METAVERSE_INFO) {
QJsonObject rootJSON {
{ "metaverse_url", NetworkingConstants::METAVERSE_SERVER_URL().toString() }
{ "metaverse_url", MetaverseAPI::getCurrentMetaverseServerURL().toString() }
};
QJsonDocument docJSON{ rootJSON };
@ -2449,7 +2450,7 @@ bool DomainServer::handleHTTPRequest(HTTPConnection* connection, const QUrl& url
QJsonDocument doc(root);
QUrl url { NetworkingConstants::METAVERSE_SERVER_URL().toString() + "/api/v1/places/" + place_id };
QUrl url { MetaverseAPI::getCurrentMetaverseServerURL().toString() + "/api/v1/places/" + place_id };
url.setQuery("access_token=" + accessTokenVariant.toString());

View file

@ -22,6 +22,7 @@
#include <LimitedNodeList.h>
#include <NetworkAccessManager.h>
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
#include <udt/PacketHeaders.h>
#include <SharedUtil.h>
@ -209,7 +210,7 @@ void IceServer::requestDomainPublicKey(const QUuid& domainID) {
// send a request to the metaverse API for the public key for this domain
auto& networkAccessManager = NetworkAccessManager::getInstance();
QUrl publicKeyURL { NetworkingConstants::METAVERSE_SERVER_URL() };
QUrl publicKeyURL{ MetaverseAPI::getCurrentMetaverseServerURL() };
QString publicKeyPath = QString("/api/v1/domains/%1/public_key").arg(uuidStringWithoutCurlyBraces(domainID));
publicKeyURL.setPath(publicKeyPath);

View file

@ -111,6 +111,7 @@
#include <ModelEntityItem.h>
#include <NetworkAccessManager.h>
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
#include <ObjectMotionState.h>
#include <OctalCode.h>
#include <OctreeSceneStats.h>
@ -1216,7 +1217,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
// set the account manager's root URL and trigger a login request if we don't have the access token
accountManager->setIsAgent(true);
accountManager->setAuthURL(NetworkingConstants::METAVERSE_SERVER_URL());
accountManager->setAuthURL(MetaverseAPI::getCurrentMetaverseServerURL());
if (!accountManager->hasKeyPair()) {
accountManager->generateNewUserKeypair();
}
@ -8466,7 +8467,7 @@ void Application::loadAddAvatarBookmarkDialog() const {
void Application::loadAvatarBrowser() const {
auto tablet = dynamic_cast<TabletProxy*>(DependencyManager::get<TabletScriptingInterface>()->getTablet("com.highfidelity.interface.tablet.system"));
// construct the url to the marketplace item
QString url = NetworkingConstants::METAVERSE_SERVER_URL().toString() + "/marketplace?category=avatars";
QString url = MetaverseAPI::getCurrentMetaverseServerURL().toString() + "/marketplace?category=avatars";
QString MARKETPLACES_INJECT_SCRIPT_PATH = "file:///" + qApp->applicationDirPath() + "/scripts/system/html/js/marketplacesInject.js";
tablet->gotoWebScreen(url, MARKETPLACES_INJECT_SCRIPT_PATH);

View file

@ -17,6 +17,7 @@
#include <QJsonDocument>
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
#include <AddressManager.h>
#include "Wallet.h"
@ -181,21 +182,28 @@ QString hfcString(const QJsonValue& sentValue, const QJsonValue& receivedValue)
}
return result;
}
static const QString USER_PAGE_BASE_URL = NetworkingConstants::METAVERSE_SERVER_URL().toString() + "/users/";
static const QString PLACE_PAGE_BASE_URL = NetworkingConstants::METAVERSE_SERVER_URL().toString() + "/places/";
QString getUserPageBaseUrl() {
return MetaverseAPI::getCurrentMetaverseServerURL().toString() + "/users/";
}
QString getPlacePageBaseUrl() {
return MetaverseAPI::getCurrentMetaverseServerURL().toString() + "/places/";
}
static const QStringList KNOWN_USERS(QStringList() << "highfidelity" << "marketplace");
QString userLink(const QString& username, const QString& placename) {
if (username.isEmpty()) {
if (placename.isEmpty()) {
return QString("someone");
} else {
return QString("someone <a href=\"%1%2\">nearby</a>").arg(PLACE_PAGE_BASE_URL, placename);
return QString("someone <a href=\"%1%2\">nearby</a>").arg(getPlacePageBaseUrl(), placename);
}
}
if (KNOWN_USERS.contains(username)) {
return username;
}
return QString("<a href=\"%1%2\">%2</a>").arg(USER_PAGE_BASE_URL, username);
return QString("<a href=\"%1%2\">%2</a>").arg(getUserPageBaseUrl(), username);
}
QString transactionString(const QJsonObject& valueObject) {

View file

@ -72,11 +72,11 @@ void QmlCommerce::openSystemApp(const QString& appName) {
else if (appPathIter->contains(".html", Qt::CaseInsensitive)) {
QMap<QString, QString>::const_iterator injectIter = systemInject.find(appName);
if (appPathIter == systemInject.end()) {
tablet->gotoWebScreen(NetworkingConstants::METAVERSE_SERVER_URL().toString() + *appPathIter);
tablet->gotoWebScreen(MetaverseAPI::getCurrentMetaverseServerURL().toString() + *appPathIter);
}
else {
QString inject = "file:///" + qApp->applicationDirPath() + *injectIter;
tablet->gotoWebScreen(NetworkingConstants::METAVERSE_SERVER_URL().toString() + *appPathIter, inject);
tablet->gotoWebScreen(MetaverseAPI::getCurrentMetaverseServerURL().toString() + *appPathIter, inject);
}
}
else {

View file

@ -20,6 +20,7 @@
#include <AccountManager.h>
#include <NetworkAccessManager.h>
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
#include <NetworkLogging.h>
#include <UserActivityLogger.h>
#include <UUID.h>
@ -28,7 +29,7 @@ QNetworkRequest createNetworkRequest() {
QNetworkRequest request;
QUrl requestURL = NetworkingConstants::METAVERSE_SERVER_URL();
QUrl requestURL = MetaverseAPI::getCurrentMetaverseServerURL();
requestURL.setPath(USER_ACTIVITY_URL);
request.setUrl(requestURL);

View file

@ -15,6 +15,7 @@
#include <OffscreenQmlDialog.h>
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
class AddressBarDialog : public OffscreenQmlDialog {
Q_OBJECT
@ -30,7 +31,7 @@ public:
bool forwardEnabled() { return _forwardEnabled; }
bool useFeed() { return _useFeed; }
void setUseFeed(bool useFeed) { if (_useFeed != useFeed) { _useFeed = useFeed; emit useFeedChanged(); } }
QString metaverseServerUrl() { return NetworkingConstants::METAVERSE_SERVER_URL().toString(); }
QString metaverseServerUrl() { return MetaverseAPI::getCurrentMetaverseServerURL().toString(); }
signals:
void backEnabledChanged();

View file

@ -14,6 +14,7 @@
#include <EntityTreeRenderer.h>
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
#include <NetworkAccessManager.h>
#include <QtNetwork/QNetworkRequest>
#include <QtNetwork/QNetworkReply>
@ -305,7 +306,7 @@ void ContextOverlayInterface::requestOwnershipVerification(const QUuid& entityID
QNetworkRequest networkRequest;
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QUrl requestURL = NetworkingConstants::METAVERSE_SERVER_URL();
QUrl requestURL = MetaverseAPI::getCurrentMetaverseServerURL();
requestURL.setPath("/api/v1/commerce/proof_of_purchase_status/transfer");
QJsonObject request;
request["certificate_id"] = entityProperties.getCertificateID();

View file

@ -28,6 +28,7 @@
#include "EntitiesRendererLogging.h"
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
using namespace render;
using namespace render::entities;

View file

@ -15,6 +15,7 @@
#include <QtEndian>
#include <QJsonDocument>
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
#include <NetworkAccessManager.h>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
@ -3207,7 +3208,7 @@ void EntityItem::retrieveMarketplacePublicKey() {
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
QNetworkRequest networkRequest;
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
QUrl requestURL = NetworkingConstants::METAVERSE_SERVER_URL();
QUrl requestURL = MetaverseAPI::getCurrentMetaverseServerURL();
requestURL.setPath("/api/v1/commerce/marketplace_key");
QJsonObject request;
networkRequest.setUrl(requestURL);

View file

@ -16,6 +16,7 @@
#include <openssl/pem.h>
#include <openssl/x509.h>
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
#include "AccountManager.h"
#include <QJsonObject>
#include <QJsonDocument>
@ -1464,7 +1465,7 @@ void EntityTree::startDynamicDomainVerificationOnServer(float minimumAgeToRemove
QNetworkRequest networkRequest;
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QUrl requestURL = NetworkingConstants::METAVERSE_SERVER_URL();
QUrl requestURL = MetaverseAPI::getCurrentMetaverseServerURL();
requestURL.setPath("/api/v1/commerce/proof_of_purchase_status/location");
QJsonObject request;
request["certificate_id"] = certificateID;
@ -1687,7 +1688,7 @@ void EntityTree::validatePop(const QString& certID, const EntityItemID& entityIt
QNetworkRequest networkRequest;
networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
networkRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
QUrl requestURL = NetworkingConstants::METAVERSE_SERVER_URL();
QUrl requestURL = MetaverseAPI::getCurrentMetaverseServerURL();
requestURL.setPath("/api/v1/commerce/proof_of_purchase_status/transfer");
QJsonObject request;
request["certificate_id"] = certID;

View file

@ -43,9 +43,10 @@
#include <Finally.h>
#include <Profile.h>
#include "NetworkLogging.h"
#include <NetworkLogging.h>
#include "MaterialNetworkingLogging.h"
#include "NetworkingConstants.h"
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
#include <Trace.h>
#include <StatTracker.h>

View file

@ -24,8 +24,9 @@
#include "AccountSettings.h"
#include "DataServerAccountInfo.h"
#include "NetworkingConstants.h"
#include "MetaverseAPI.h"
#include "NetworkAccessManager.h"
#include "SharedUtil.h"
#include <SharedUtil.h>
class JSONCallbackParameters {
public:
@ -97,7 +98,7 @@ public:
void setTemporaryDomain(const QUuid& domainID, const QString& key);
const QString& getTemporaryDomainKey(const QUuid& domainID) { return _accountInfo.getTemporaryDomainKey(domainID); }
QUrl getMetaverseServerURL() { return NetworkingConstants::METAVERSE_SERVER_URL(); }
QUrl getMetaverseServerURL() { return MetaverseAPI::getCurrentMetaverseServerURL(); }
void removeAccountFromFile();

View file

@ -21,6 +21,7 @@
#include "NetworkAccessManager.h"
#include "NetworkLogging.h"
#include "NetworkingConstants.h"
#include "MetaverseAPI.h"
#include "ResourceManager.h"

View file

@ -29,6 +29,7 @@
#include "Node.h"
#include "ReceivedMessage.h"
#include "NetworkingConstants.h"
#include "MetaverseAPI.h"
const unsigned short DEFAULT_DOMAIN_SERVER_PORT = 40102;
const unsigned short DEFAULT_DOMAIN_SERVER_DTLS_PORT = 40103;

View file

@ -22,6 +22,7 @@
#include "NetworkLogging.h"
#include "ResourceManager.h"
#include "NetworkingConstants.h"
#include "MetaverseAPI.h"
void FileResourceRequest::doSend() {
auto statTracker = DependencyManager::get<StatTracker>();

View file

@ -0,0 +1,38 @@
//
// MetaverseAPI.cpp
// libraries/networking/src
//
// Created by Kalila (kasenvr) on 2019-12-16.
// Copyright 2019 Project Athena
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "MetaverseAPI.h"
#include <QUrl>
#include <QDebug>
#include "NetworkingConstants.h"
#include <SettingHandle.h>
namespace MetaverseAPI {
// You can change the return of this function if you want to use a custom metaverse URL at compile time
// or you can pass a custom URL via the env variable
QUrl getCurrentMetaverseServerURL() {
QUrl selectedMetaverseURL;
Setting::Handle<QUrl> selectedMetaverseURLSetting("private/selectedMetaverseURL",
NetworkingConstants::METAVERSE_SERVER_URL_STABLE);
selectedMetaverseURL = selectedMetaverseURLSetting.get();
const QString HIFI_METAVERSE_URL_ENV = "HIFI_METAVERSE_URL";
if (QProcessEnvironment::systemEnvironment().contains(HIFI_METAVERSE_URL_ENV)) {
return QUrl(QProcessEnvironment::systemEnvironment().value(HIFI_METAVERSE_URL_ENV));
}
return selectedMetaverseURL;
};
}

View file

@ -0,0 +1,22 @@
//
// MetaverseAPI.h
// libraries/networking/src
//
// Created by Kalila (kasenvr) on 2019-12-16.
// Copyright 2019 Project Athena
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef athena_MetaverseAPI_h
#define athena_MetaverseAPI_h
#include <QtCore/QProcessEnvironment>
#include <QtCore/QUrl>
namespace MetaverseAPI {
QUrl getCurrentMetaverseServerURL();
}
#endif // athena_MetaverseAPI_h

View file

@ -1,24 +0,0 @@
//
// NetworkingConstants.cpp
// libraries/networking/src
//
// Created by Seth Alves on 2018-2-28.
// Copyright 2018 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "NetworkingConstants.h"
namespace NetworkingConstants {
// You can change the return of this function if you want to use a custom metaverse URL at compile time
// or you can pass a custom URL via the env variable
QUrl METAVERSE_SERVER_URL() {
const QString HIFI_METAVERSE_URL_ENV = "HIFI_METAVERSE_URL";
const QUrl serverURL = QProcessEnvironment::systemEnvironment().contains(HIFI_METAVERSE_URL_ENV)
? QUrl(QProcessEnvironment::systemEnvironment().value(HIFI_METAVERSE_URL_ENV))
: METAVERSE_SERVER_URL_STABLE;
return serverURL;
};
}

View file

@ -25,9 +25,8 @@ namespace NetworkingConstants {
// if you manually generate a personal access token for the domains scope
// at https://staging.highfidelity.com/user/tokens/new?for_domain_server=true
const QUrl METAVERSE_SERVER_URL_STABLE { "https://metaverse.highfidelity.com" };
const QUrl METAVERSE_SERVER_URL_STAGING { "https://staging.highfidelity.com" };
QUrl METAVERSE_SERVER_URL();
const QUrl METAVERSE_SERVER_URL_STABLE { "https://metaverse.projectathena.io" };
const QUrl METAVERSE_SERVER_URL_STAGING { "https://staging.projectathena.io" };
}
const QString HIFI_URL_SCHEME_ABOUT = "about";

View file

@ -18,6 +18,7 @@
#include "AccountManager.h"
#include "LimitedNodeList.h"
#include "NetworkingConstants.h"
#include "MetaverseAPI.h"
#include "SharedUtil.h"
QThreadStorage<OAuthNetworkAccessManager*> oauthNetworkAccessManagers;
@ -35,7 +36,7 @@ QNetworkReply* OAuthNetworkAccessManager::createRequest(QNetworkAccessManager::O
auto accountManager = DependencyManager::get<AccountManager>();
if (accountManager->hasValidAccessToken()
&& req.url().host() == NetworkingConstants::METAVERSE_SERVER_URL().host()) {
&& req.url().host() == MetaverseAPI::getCurrentMetaverseServerURL().host()) {
QNetworkRequest authenticatedRequest(req);
authenticatedRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
authenticatedRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);

View file

@ -20,6 +20,7 @@
#include <NumericalConstants.h>
#include <GLMHelpers.h>
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
#include <shaders/Shaders.h>
#include "ShaderConstants.h"

View file

@ -24,6 +24,7 @@
#include <gl/OffscreenGLCanvas.h>
#include <shared/ReadWriteLockable.h>
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
#include "Logging.h"
#include "impl/SharedObject.h"

View file

@ -20,12 +20,11 @@
#include <AccountManager.h>
#include <NetworkAccessManager.h>
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
#include "ResourceRequestObserver.h"
#include "ScriptEngine.h"
const QString METAVERSE_API_URL = NetworkingConstants::METAVERSE_SERVER_URL().toString() + "/api/";
Q_DECLARE_METATYPE(QByteArray*)
XMLHttpRequestClass::XMLHttpRequestClass(QScriptEngine* engine) :
@ -126,6 +125,8 @@ void XMLHttpRequestClass::open(const QString& method, const QString& url, bool a
_url.setUrl(url);
_async = async;
const QString METAVERSE_API_URL = MetaverseAPI::getCurrentMetaverseServerURL().toString() + "/api/";
if (url.toLower().left(METAVERSE_API_URL.length()) == METAVERSE_API_URL) {
auto accountManager = DependencyManager::get<AccountManager>();

View file

@ -16,6 +16,7 @@
#include <SettingHandle.h>
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
#include <AccountManager.h>
#include "ContextAwareProfile.h"
@ -25,7 +26,7 @@
namespace {
bool isAuthableHighFidelityURL(const QUrl& url) {
auto metaverseServerURL = NetworkingConstants::METAVERSE_SERVER_URL();
auto metaverseServerURL = MetaverseAPI::getCurrentMetaverseServerURL();
static const QStringList HF_HOSTS = {
"highfidelity.com", "highfidelity.io",
metaverseServerURL.toString(), "metaverse.highfidelity.io"

View file

@ -18,6 +18,7 @@
#include <NetworkLogging.h>
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
#include <SharedLogging.h>
#include <AddressManager.h>
#include <DependencyManager.h>
@ -106,7 +107,7 @@ ACClientApp::ACClientApp(int argc, char* argv[]) :
auto accountManager = DependencyManager::get<AccountManager>();
accountManager->setIsAgent(true);
accountManager->setAuthURL(NetworkingConstants::METAVERSE_SERVER_URL());
accountManager->setAuthURL(MetaverseAPI::getCurrentMetaverseServerURL());
auto nodeList = DependencyManager::get<NodeList>();

View file

@ -20,6 +20,7 @@
#include <NetworkLogging.h>
#include <NetworkingConstants.h>
#include <MetaverseAPI.h>
#include <SharedLogging.h>
#include <AddressManager.h>
#include <DependencyManager.h>
@ -144,7 +145,7 @@ ATPClientApp::ATPClientApp(int argc, char* argv[]) :
auto accountManager = DependencyManager::get<AccountManager>();
accountManager->setIsAgent(true);
accountManager->setAuthURL(NetworkingConstants::METAVERSE_SERVER_URL());
accountManager->setAuthURL(MetaverseAPI::getCurrentMetaverseServerURL());
auto nodeList = DependencyManager::get<NodeList>();