Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AasxOpenidClient/AasxOpenidClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<PackageReference Include="IdentityModel" Version="6.0.0" />
<PackageReference Include="jose-jwt" Version="4.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.1.2" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.2" />
<PackageReference Include="System.IO.Packaging" Version="7.0.0" />
<PackageReference Include="System.Text.Json" Version="9.0.2" />
</ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/AasxPackageExplorer/options-debug.MIHO.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
"AccessInfo": {
"Method": "None" // None, Ask, Basic, CertificateStore, File, InteractiveEntry, Secret
}
},
{
"BaseAddress": "https://leo-discovery.admin-shell-io.com/api/v2/",
"AccessInfo": {
"Method": "None" // None, Ask, Basic, CertificateStore, File, InteractiveEntry, Secret
}
},
{
"BaseAddress": "https://aasx-server-pcf.dev.pxcio.net/",
Expand Down
2 changes: 1 addition & 1 deletion src/AasxPackageLogic/AasxPackageLogic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<PackageReference Include="SSharp.Net" Version="1.0.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
<PackageReference Include="System.Formats.Asn1" Version="9.0.2" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.1.2" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.1.2" />
<PackageReference Include="System.Text.Json" Version="9.0.2" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions src/AasxPackageLogic/DispEditHelperEntities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1557,6 +1557,7 @@ public static async Task<bool> ExecuteUiForFetchOfElements(
"Error building location from fetch selection. Aborting.");
return false;
}
Options.Curr.AutoAuthenticateAsk = fetchContext.Record.AutoAuthenticate;

// more details into container options
var containerOptions = new PackageContainerHttpRepoSubset.
Expand Down
218 changes: 151 additions & 67 deletions src/AasxPackageLogic/PackageCentral/PackageContainerHttpRepoSubset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This source code may use other Open Source software components (see LICENSE.txt)

using AasxIntegrationBase;
using AdminShellNS;
using AdminShellNS.Extensions;
using AngleSharp.Dom;
using AnyUi;
using Extensions;
Expand Down Expand Up @@ -303,14 +304,14 @@ public static bool IsValidUriForRegistryAasByAssetIds(string location)

public static bool IsValidUriForRegOfRegAasByAssetId(string location)
{
var m = Regex.Match(location, @"^(http(|s))://(.*?)/registry-descriptors/([-A-Za-z0-9_]{1,999})$",
var m = Regex.Match(location, @"^(http(|s))://(.*?)/(?:registry-descriptors/|companies\?asset_id=)([-A-Za-z0-9_]{1,999})$",
RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
return m.Success;
}

public static string IsValidAndDecodeUriForRegOfRegAasByAssetId(string location)
{
var m = Regex.Match(location, @"^(http(|s))://(.*?)/registry-descriptors/([-A-Za-z0-9_]{1,999})$",
var m = Regex.Match(location, @"^(http(|s))://(.*?)/(?:registry-descriptors/|companies\?asset_id=)([-A-Za-z0-9_]{1,999})$",
RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
if (!m.Success)
return null;
Expand Down Expand Up @@ -353,7 +354,7 @@ public static Uri GetBaseUri(string location)
// try an explicit search for known parts of ressources
// (preserves scheme, host and leading pathes)
var m = Regex.Match(location, @"^(.*?)(/shells|/submodel|/concept-description|/lookup|/description"
+ "|/shell-descriptor|/submodel-descriptor|/bulk|/serialization|/package)");
+ "|/shell-descriptor|/submodel-descriptor|/bulk|/serialization|/package|/registry-descriptors|/companies)");
if (m.Success)
return new Uri(m.Groups[1].ToString() + "/");

Expand All @@ -366,6 +367,10 @@ public static Uri GetBaseUri(string location)
{
return new Uri(location.Substring(0, p) + "/");
}
else
{
return new Uri(location);
}
}

// go to error
Expand Down Expand Up @@ -732,10 +737,17 @@ public static Uri BuildUriForRegOfRegAasByAssetId(Uri baseUri, string id, bool e
// access
if (id?.HasContent() != true)
return null;
var route = "registry-descriptors/";

// try combine
var assenc = encryptIds ? AdminShellUtil.Base64UrlEncode(id) : id;
return CombineUri(baseUri, $"registry-descriptors/{assenc}");

if (baseUri.Host.Contains("leo-discovery"))
{
route = "companies";
assenc = $"?asset_id={assenc}";
}

return CombineUri(baseUri, $"{route}{assenc}");
}

//
Expand Down Expand Up @@ -819,7 +831,10 @@ private static async Task<bool> FromRegistryGetAasAndSubmodels(
{
// strictly check IFC
var aasIfc = "" + ep["interface"];
if (aasIfc != "AAS-1.0")
if (!(aasIfc == "AAS-1.0"
|| aasIfc == "AAS-2.0"
|| aasIfc == "AAS-3.0"
|| aasIfc == "AAS-3.1"))
continue;

// direct access HREF
Expand All @@ -843,8 +858,11 @@ private static async Task<bool> FromRegistryGetAasAndSubmodels(
{
// strictly check IFC
var smIfc = "" + smep["interface"];
if (smIfc != "SUBMODEL-1.0")
continue;
if (!(aasIfc == "SUBMODEL-1.0"
|| aasIfc == "SUBMODEL-2.0"
|| aasIfc == "SUBMODEL-3.0"
|| aasIfc == "SUBMODEL-3.1"))
continue;

// ok
string href = smep.protocolInformation.href;
Expand Down Expand Up @@ -969,7 +987,7 @@ private static async Task<bool> FromRegistryGetAasAndSubmodels(
return true;
}

private static async Task<bool> FromRegOfRegGetAasAndSubmodels(
private static async Task FromRegOfRegGetAasAndSubmodels(
OnDemandListIdentifiable<IAssetAdministrationShell> prepAas,
OnDemandListIdentifiable<ISubmodel> prepSM,
ConnectExtendedRecord record,
Expand All @@ -980,82 +998,141 @@ private static async Task<bool> FromRegOfRegGetAasAndSubmodels(
List<Aas.IIdentifiable> trackNewIdentifiables = null,
List<Aas.IIdentifiable> trackLoadedIdentifiables = null,
Action<int, int, int, int> lambdaReportProgress = null,
bool compatOldAasxServer = false)
bool compatOldAasxServer = false,
bool isLeoDiscoveryServer = false)
{
// access
if (record == null || regDescriptor == null || assetId?.HasContent() != true)
return false;
return;

// The format is:
// {
// "Url": "http://example.com/6789",
// "Security": "",
// "Match": "LIKE",
// "Pattern": "%6789%",
// "Domain": "example.com",
// "Id": "xxx",
// "Info": "xxx"
// }
// However, only Url and Id are currently useful

string regUrl = "" + regDescriptor["url"];
string regInfo = "" + regDescriptor["info"];
if (regInfo == "")
regInfo = "<Unknown>";

// valid url?
if (regUrl == "")
return false;

var basicUri = GetBaseUri(regUrl);
if (basicUri == null)
return false;
List<string> regUrls = new List<string>();

// build again a set of baseUris, but only one pattern set
var baseUris = new BaseUriDict(key: "AAS-REG", value: basicUri.ToString());
if (isLeoDiscoveryServer)
{
//See: https://leo-discovery.admin-shell-io.com/

// translate to a list of AAS-Ids ..
var uriGetListOfAids = BuildUriForRegistryAasByAssetId(baseUris.GetBaseUriForAasReg(), assetId);
if (compatOldAasxServer)
uriGetListOfAids = BuildUriForRegistryAasByAssetLinkDeprecated(baseUris.GetBaseUriForAasReg(), assetId);
var listOfAids = await PackageHttpDownloadUtil.DownloadEntityToDynamicObject(
uriGetListOfAids, runtimeOptions, allowFakeResponses);
var endpoints = regDescriptor?.endpoints;

if (listOfAids == null || !(listOfAids is JArray) || (listOfAids as JArray).Count < 1)
if (endpoints != null)
{
foreach (var endpoint in endpoints)
{
if (endpoint["interface"] == "AAS-REGISTRY-3.1"
|| endpoint["interface"] == "AAS-REGISTRY-3.0")
{
var regUrl = endpoint.protocolInformation["href"];
regUrls.Add("" + regUrl);
}
}
}
}
else
{
// The format is:
// {
// "Url": "http://example.com/6789",
// "Security": "",
// "Match": "LIKE",
// "Pattern": "%6789%",
// "Domain": "example.com",
// "Id": "xxx",
// "Info": "xxx"
// }
// However, only Url and Id are currently useful

regUrls.Add("" + regDescriptor["url"]);
}


// valid url?
if (regUrls.IsNullOrEmpty())
return;

List<Uri> basicUris = new List<Uri>();

foreach (var regUrl in regUrls)
{
runtimeOptions?.Log?.Info("Registry {0} did not translate glopbalAssetId={1} to any AAS Ids. " +
"Aborting! URi was: {2}",
basicUri, assetId, uriGetListOfAids);
return false;
var basicUri = GetBaseUri(regUrl);
if (basicUri != null)
{
basicUris.Add(basicUri);
}
}

if(basicUris.IsNullOrEmpty())
{
return;
}

// take the individual AAS ids
foreach (var aid in listOfAids)
foreach (var basicUri in basicUris)
{
// prepare receiving the descriptor
var uriGetAasDescr = BuildUriForRegistrySingleAAS(baseUris.GetBaseUriForAasReg(), aid.ToString());
var resAasDescr = await PackageHttpDownloadUtil.DownloadEntityToDynamicObject(
uriGetAasDescr, runtimeOptions, allowFakeResponses);
// build again a set of baseUris, but only one pattern set
var baseUris = new BaseUriDict(key: "AAS-REG", value: basicUri.ToString());

// have directly a single descriptor?!
if (!(resAasDescr is JObject))
// translate to a list of AAS-Ids ..
var uriGetListOfAids = BuildUriForRegistryAasByAssetId(baseUris.GetBaseUriForAasReg(), assetId);
if (compatOldAasxServer)
uriGetListOfAids = BuildUriForRegistryAasByAssetLinkDeprecated(baseUris.GetBaseUriForAasReg(), assetId);

try
{
runtimeOptions?.Log?.Info("Registry did not return a single AAS descriptor! Aborting. URI was: {0}",
uriGetAasDescr);
return false;
}
var listOfAids = await PackageHttpDownloadUtil.DownloadEntityToDynamicObject(
uriGetListOfAids, runtimeOptions, allowFakeResponses);

lambdaReportProgress?.Invoke(0, 0, 0, 1);
if (listOfAids == null || !(listOfAids is JArray) || (listOfAids as JArray).Count < 1)
{
runtimeOptions?.Log?.Info("Registry {0} did not translate globalAssetId={1} to any AAS Ids. " +
"Aborting! URi was: {2}",
basicUri, assetId, uriGetListOfAids);
}
else
{
// take the individual AAS ids
foreach (var aid in listOfAids)
{
// prepare receiving the descriptor
var uriGetAasDescr = BuildUriForRegistrySingleAAS(baseUris.GetBaseUriForAasReg(), aid.ToString());
var resAasDescr = await PackageHttpDownloadUtil.DownloadEntityToDynamicObject(
uriGetAasDescr, runtimeOptions, allowFakeResponses);

// have directly a single descriptor?!
if (!(resAasDescr is JObject))
{
runtimeOptions?.Log?.Info("Registry did not return a single AAS descriptor! Aborting. URI was: {0}",
uriGetAasDescr);
}

// refer to dedicated function
await FromRegistryGetAasAndSubmodels(
prepAas, prepSM, record, runtimeOptions, allowFakeResponses, resAasDescr,
trackNewIdentifiables, trackLoadedIdentifiables,
lambdaReportProgress: lambdaReportProgress);
lambdaReportProgress?.Invoke(0, 0, 0, 1);

try
{
// refer to dedicated function
await FromRegistryGetAasAndSubmodels(
prepAas, prepSM, record, runtimeOptions, allowFakeResponses, resAasDescr,
trackNewIdentifiables, trackLoadedIdentifiables,
lambdaReportProgress: lambdaReportProgress);
}
catch (Exception e)
{
runtimeOptions?.Log?.Info("Download aas and submodels from registry {0} failed globalAssetId={1} to any AAS Ids. " +
"Aborting! AAS id was: {2}, message was {3}",
basicUri, assetId, aid, e.Message);
}

}
}
}
catch (Exception e)
{
runtimeOptions?.Log?.Info("Download descriptors from registry {0} failed globalAssetId={1} to any AAS Ids. " +
"Aborting! URi was: {2}, message was {3}",
basicUri, assetId, uriGetListOfAids, e.Message);
}
}

// OK?
return true;
return;
}

public override async Task<bool> LoadFromSourceAsync(
Expand Down Expand Up @@ -1221,6 +1298,12 @@ protected static async Task<AdminShellPackageEnvBase> LoadFromSourceInternalAsyn
}
else
{
bool isFXLeoDiscoveryServer = fullItemLocation.Contains("leo-discovery");
if (isFXLeoDiscoveryServer)
{
resObj = resObj["data"];
}

foreach (var res in resObj)
{
// refer to dedicated function
Expand All @@ -1230,7 +1313,8 @@ await FromRegOfRegGetAasAndSubmodels(
trackNewIdentifiables, trackLoadedIdentifiables,
lambdaReportProgress: lambdaReportAasSm,
// TODO: check!!
compatOldAasxServer: true);
compatOldAasxServer: isFXLeoDiscoveryServer ? false : true,
isLeoDiscoveryServer : isFXLeoDiscoveryServer);
}
}
}
Expand Down
Loading
Loading