49 const nlohmann::json& aJson,
const wxFileName& aSchemaFile, wxString& aError )
51 if( !aSchemaFile.IsFileReadable() )
53 aError = wxString::Format(
_(
"Remote provider metadata schema '%s' is not readable." ),
54 aSchemaFile.GetFullPath() );
60 validator.
Validate( aJson, handler );
64 aError = wxString::Format(
_(
"Remote provider metadata failed schema validation: %s" ),
74 wxString::FromUTF8( aJson.at(
"provider_name" ).get_ref<
const std::string&>().c_str() );
76 wxString::FromUTF8( aJson.at(
"provider_version" ).get_ref<
const std::string&>().c_str() );
78 wxString::FromUTF8( aJson.at(
"api_base_url" ).get_ref<
const std::string&>().c_str() );
87 for(
const nlohmann::json& assetType : aJson.at(
"supported_asset_types" ) )
89 assetType.get_ref<
const std::string&>().c_str() ) );
91 const nlohmann::json&
auth = aJson.at(
"auth" );
94 if( authType.IsSameAs( wxS(
"oauth2" ),
false ) )
100 if(
auth.contains(
"scopes" ) )
102 for(
const nlohmann::json& scope :
auth.at(
"scopes" ) )
104 wxString::FromUTF8( scope.get_ref<
const std::string&>().c_str() ) );
112 const nlohmann::json& capabilities = aJson.at(
"capabilities" );
113 static const std::set<std::string> supportedCapabilities = {
116 "direct_downloads_v1",
120 for(
const auto& [
name, value] : capabilities.items() )
122 if( !supportedCapabilities.count(
name ) )
124 aError = wxString::Format(
_(
"Unsupported provider capability '%s'." ),
125 wxString::FromUTF8(
name.c_str() ) );
129 if(
name ==
"web_ui_v1" )
131 else if(
name ==
"parts_v1" )
132 metadata.
parts_v1 = value.get<
bool>();
133 else if(
name ==
"direct_downloads_v1" )
135 else if(
name ==
"inline_payloads_v1" )
139 if( aJson.contains(
"parts" ) )
141 const nlohmann::json& parts = aJson.at(
"parts" );
145 catch(
const std::exception& e )
147 aError = wxString::Format(
_(
"Unable to parse remote provider metadata: %s" ),
148 wxString::FromUTF8( e.what() ) );
154 aError =
_(
"Remote provider metadata must enable web_ui_v1." );
161 "Remote provider metadata must enable direct_downloads_v1, inline_payloads_v1, or both." );
168 aError =
_(
"Remote provider metadata must define session_bootstrap_url for oauth2." );
173 _(
"api_base_url" ) ) )
185 _(
"session_bootstrap_url" ) ) )
193 aError =
_(
"session_bootstrap_url must share the same origin as panel_url." );
199 aError,
_(
"auth.metadata_url" ) ) )
static wxString GetStockDataPath(bool aRespectRunFromBuildDir=true)
Gets the stock (install) data path, which is the base path for things like scripting,...
wxString RemoteProviderJsonString(const nlohmann::json &aObject, const char *aKey)
Extract an optional string value from a JSON object, returning an empty wxString when the key is abse...
bool ValidateRemoteUrlSecurity(const wxString &aUrl, bool aAllowInsecureLocalhost, wxString &aError, const wxString &aLabel)
Validate that aUrl uses HTTPS, or HTTP on a loopback address when aAllowInsecureLocalhost is true.