-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #329 from microsoft/serverapattrs
Allow specifying JSON configuration to netremote-server on command-line
- Loading branch information
Showing
24 changed files
with
464 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
src/common/net/wifi/core/AccessPointAttributesJsonSerialization.cxx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
#include <filesystem> | ||
#include <format> | ||
#include <fstream> | ||
#include <optional> | ||
|
||
#include <microsoft/net/remote/service/NetRemoteServerJsonConfiguration.hxx> | ||
#include <microsoft/net/wifi/AccessPointAttributesJsonSerialization.hxx> | ||
#include <nlohmann/json.hpp> | ||
#include <plog/Log.h> | ||
|
||
using namespace Microsoft::Net::Remote::Service; | ||
|
||
/* static */ | ||
std::optional<nlohmann::json> | ||
NetRemoteServerJsonConfiguration::ParseFromFile(const std::filesystem::path& configurationFilePath) noexcept | ||
{ | ||
std::ifstream configurationFileStream{ configurationFilePath }; | ||
nlohmann::json configurationJson; | ||
|
||
try { | ||
configurationJson = nlohmann::json::parse(configurationFileStream); | ||
} catch (const nlohmann::json::parse_error& parseError) { | ||
LOGE << std::format("Failed to parse JSON configuration file '{}' ({})", configurationFilePath.string(), parseError.what()); | ||
return std::nullopt; | ||
} | ||
|
||
LOGD << std::format("Successfully parsed JSON configuration file '{}'\n{}", configurationFilePath.string(), configurationJson.dump(2)); | ||
|
||
return configurationJson; | ||
} | ||
|
||
/* static */ | ||
std::optional<NetRemoteServerJsonConfiguration> | ||
NetRemoteServerJsonConfiguration::TryParseFromJson(const nlohmann::json& configurationJson) noexcept | ||
{ | ||
using Microsoft::Net::Wifi::AccessPointAttributes; | ||
|
||
NetRemoteServerJsonConfiguration configuration{}; | ||
|
||
// Parse access point attributes, if specified. | ||
if (configurationJson.contains(AccessPointAttributesKey)) { | ||
try { | ||
auto accessPointAttributesJson = configurationJson.at(AccessPointAttributesKey); | ||
if (!accessPointAttributesJson.is_object()) { | ||
LOGE << std::format("JSON configuration '{}' is not an object", AccessPointAttributesKey); | ||
return std::nullopt; | ||
} | ||
|
||
std::unordered_map<std::string, AccessPointAttributes> accessPointAttributes{}; | ||
accessPointAttributesJson.get_to(accessPointAttributes); | ||
configuration.AccessPointAttributes = std::move(accessPointAttributes); | ||
} catch (const nlohmann::json::exception& jsonException) { | ||
LOGE << std::format("Failed to parse JSON configuration for '{}' field: {}", AccessPointAttributesKey, jsonException.what()); | ||
return std::nullopt; | ||
} | ||
} | ||
|
||
return configuration; | ||
} |
Oops, something went wrong.