Skip to content

Commit

Permalink
Merge branch 'release/0.9.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelmathot committed Jun 14, 2021
2 parents 937d287 + 18e1d8a commit f5526ed
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Stars.Console/Terradue.Stars.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<Version>0.9.3</Version>
<Version>0.9.4</Version>
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)-$(VersionSuffix)</Version>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<AssemblyName>Stars</AssemblyName>
Expand Down
6 changes: 4 additions & 2 deletions src/Stars.Services/Model/Stac/StacAssetAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ namespace Terradue.Stars.Services.Model.Stac
public class StacAssetAsset : IAsset
{
private StacAsset asset;
private readonly ICredentials credentials;
private readonly Uri uri;

public StacAssetAsset(StacAsset asset, StacItemNode parent)
public StacAssetAsset(StacAsset asset, StacItemNode parent, ICredentials credentials = null)
{
this.asset = asset;
this.credentials = credentials;
if (asset.Uri.IsAbsoluteUri)
this.uri = asset.Uri;
else
Expand Down Expand Up @@ -92,7 +94,7 @@ public IStreamable GetStreamable()
if (asset is IStreamable)
return asset as IStreamable;

return WebRoute.Create(uri);
return WebRoute.Create(uri, credentials: credentials);

}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Stars.Services/Model/Stac/StacCatalogNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Terradue.Stars.Services.Model.Stac
{
public class StacCatalogNode : StacNode, ICatalog
{
public StacCatalogNode(IStacCatalog stacCatalog, Uri uri) : base(stacCatalog, uri)
public StacCatalogNode(IStacCatalog stacCatalog, Uri uri, ICredentials credentials = null) : base(stacCatalog, uri, credentials)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/Stars.Services/Model/Stac/StacItemNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Terradue.Stars.Services.Model.Stac
{
public class StacItemNode : StacNode, IItem
{
public StacItemNode(StacItem stacItem, Uri uri) : base(stacItem, uri)
public StacItemNode(StacItem stacItem, Uri uri, ICredentials credentials = null) : base(stacItem, uri, credentials)
{
}

Expand All @@ -26,7 +26,7 @@ public static StacItemNode CreateUnlocatedNode(StacItem stacItem){

public IDictionary<string, object> Properties => StacItem.Properties;

public IReadOnlyDictionary<string, IAsset> Assets => StacItem.Assets.ToDictionary(asset => asset.Key, asset => (IAsset)new StacAssetAsset(asset.Value, this));
public IReadOnlyDictionary<string, IAsset> Assets => StacItem.Assets.ToDictionary(asset => asset.Key, asset => (IAsset)new StacAssetAsset(asset.Value, this, credentials));

public override IReadOnlyList<IResource> GetRoutes(ICredentials credentials)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Stars.Services/Model/Stac/StacNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ namespace Terradue.Stars.Services.Model.Stac
public abstract class StacNode : IResource, IStreamable, ILocatable
{
protected IStacObject stacObject;
protected readonly ICredentials credentials;
private Uri uri;

protected StacNode(IStacObject stacObject, Uri uri = null)
protected StacNode(IStacObject stacObject, Uri uri = null, ICredentials credentials = null)
{
if (stacObject == null)
throw new ArgumentNullException("stacObject");
this.stacObject = stacObject;
this.credentials = credentials;
this.uri = uri == null ? new Uri(Id + ".json", UriKind.Relative) : uri;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Stars.Services/Model/Stac/StacRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public async Task<IResource> Route(IResource route)
{
IStacObject stacObject = StacConvert.Deserialize<IStacObject>(await (routeFound as IStreamable).ReadAsString());
if ( stacObject is IStacCatalog )
return new StacCatalogNode(stacObject as IStacCatalog, routeFound.Uri);
return new StacCatalogNode(stacObject as IStacCatalog, routeFound.Uri, credentials);
else
return new StacItemNode(stacObject as StacItem, routeFound.Uri);
return new StacItemNode(stacObject as StacItem, routeFound.Uri, credentials);
}
throw new NotSupportedException(routeFound.ContentType.ToString());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Stars.Services/Terradue.Stars.Services.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<Title>Terradue.Stars</Title>
<Description>Stars is a set of services for working with Spatio Temporal Catalog such as STAC but not only</Description>
<Version>0.9.3</Version>
<Version>0.9.4</Version>
<!-- <VersionSuffix>beta.1</VersionSuffix> -->
<AssemblyName>Terradue.Stars.Services</AssemblyName>
<PackageId>Terradue.Stars</PackageId>
Expand Down
9 changes: 6 additions & 3 deletions src/Stars.Services/Translator/DefaultStacTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@
using Terradue.Stars.Interface;
using Terradue.Stars.Services.Plugins;
using Stac.Extensions.File;
using System.Net;

namespace Terradue.Stars.Services.Translator
{
[PluginPriority(10)]
public class DefaultStacTranslator : ITranslator
{
private ILogger logger;
private readonly ICredentials credentials;

public int Priority { get; set; }
public string Key { get => "DefaultStacTranslator"; set { } }

public DefaultStacTranslator(ILogger<DefaultStacTranslator> logger)
public DefaultStacTranslator(ILogger<DefaultStacTranslator> logger, ICredentials credentials)
{
this.logger = logger;
this.credentials = credentials;
}

public Task<T> Translate<T>(IResource route) where T : IResource
Expand All @@ -42,7 +45,7 @@ public Task<T> Translate<T>(IResource route) where T : IResource
private IResource CreateStacCatalogNode(ICatalog node)
{
StacCatalog catalog = new StacCatalog(node.Id, node.Label, CreateStacLinks(node));
return new StacCatalogNode(catalog, node.Uri);
return new StacCatalogNode(catalog, node.Uri, credentials);
}

private IEnumerable<StacLink> CreateStacLinks(ICatalog node)
Expand All @@ -61,7 +64,7 @@ private IItem CreateStacItemNode(IItem node)
relativeUri = node.Uri.MakeRelativeUri(asset.Value.Uri);
stacItem.Assets.Add(asset.Key, CreateStacAsset(asset.Value, stacItem, relativeUri));
}
return new StacItemNode(stacItem, node.Uri);
return new StacItemNode(stacItem, node.Uri, credentials);
}

private StacAsset CreateStacAsset(IAsset asset, StacItem stacItem, Uri uri)
Expand Down

0 comments on commit f5526ed

Please sign in to comment.