Skip to content

Commit

Permalink
Merge branch 'release/0.8.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelmathot committed Jun 2, 2021
2 parents 42e4607 + 6e626dc commit bffc0f9
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 15 deletions.
34 changes: 32 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pipeline {
VERSION_TOOL = getVersionFromCsProj('src/Stars.Console/Terradue.Stars.Console.csproj')
VERSION_TYPE = getTypeOfVersion(env.BRANCH_NAME)
CONFIGURATION = getConfiguration(env.BRANCH_NAME)
GITHUB_ORGANIZATION = 'Terradue'
GITHUB_REPO = 'Stars'
}
stages {
stage('.Net Core') {
Expand All @@ -29,7 +31,7 @@ pipeline {
script {
def sdf = sh(returnStdout: true, script: 'date -u +%Y%m%dT%H%M%S').trim()
if (env.BRANCH_NAME == 'master')
env.RELEASE = env.BUILD_NUMBER
env.RELEASE = ""
else
env.RELEASE = "SNAPSHOT" + sdf
}
Expand Down Expand Up @@ -98,7 +100,35 @@ pipeline {
}
}
}
}
}
stage('Create Release') {
agent {
docker {
image 'golang'
}
}
stages{
stage('Github release') {
when {
tag 'v*'
}
steps {
withCredentials([string(credentialsId: '11f06c51-2f47-43be-aef4-3e4449be5cf0', variable: 'GITHUB_TOKEN')]) {
unstash name: 'stars-exe'
sh "go get github.com/github-release/github-release"
echo "Deleting release from github before creating new one"
sh "github-release delete --user ${env.GITHUB_ORGANIZATION} --repo ${env.GITHUB_REPO} --tag v${env.VERSION_TOOL}"

echo "Creating a new release in github"
sh "github-release release --user ${env.GITHUB_ORGANIZATION} --repo ${env.GITHUB_REPO} --tag v${env.VERSION_TOOL} --name v${env.VERSION_TOOL}"

echo "Uploading the artifacts into github"
sh "github-release upload --user ${env.GITHUB_ORGANIZATION} --repo ${env.GITHUB_REPO} --tag v${env.VERSION_TOOL} --name Stars-linux-x64 --file src/Stars.Console/bin/Release/net5.0/linux-x64/publish/Stars"
}
}
}
}
}
}
}

Expand Down
38 changes: 37 additions & 1 deletion src/Stars.Console/Operations/CopyOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Terradue.Stars.Services.Store;
using System.Net;
using Newtonsoft.Json;
using System.Text.RegularExpressions;

namespace Terradue.Stars.Console.Operations
{
Expand Down Expand Up @@ -72,6 +73,9 @@ internal class CopyOperation : BaseOperation
[Option("-res|--result-file", "Write the copy result in a file", CommandOptionType.SingleValue)]
public string ResultFile { get; set; }

[Option("-af|--asset-filter", "Asset filters to match to be included in the copy (default to all)", CommandOptionType.MultipleValue)]
public string[] AssetsFilters { get; set; }


private RouterService routingService;
private CarrierManager carrierManager;
Expand Down Expand Up @@ -231,7 +235,8 @@ private async Task<object> CopyNode(IResource node, IRouter router, object state

if (!SkippAssets)
{
AssetImportReport deliveryReport = await assetService.ImportAssets(supplierNode as IAssetsContainer, destination, AssetFilters.None);
AssetFilters assetFilters = CreateAssetFiltersFromOptions();
AssetImportReport deliveryReport = await assetService.ImportAssets(supplierNode as IAssetsContainer, destination, assetFilters);
if (StopOnError && deliveryReport.AssetsExceptions.Count > 0)
throw new AggregateException(deliveryReport.AssetsExceptions.Values);

Expand Down Expand Up @@ -264,6 +269,37 @@ private async Task<object> CopyNode(IResource node, IRouter router, object state
return operationState;
}

private AssetFilters CreateAssetFiltersFromOptions()
{
AssetFilters assetFilters = new AssetFilters();
Regex propertyRegex = new Regex(@"^\{(?'key'[\w:]*)\}(?'value'.*)$");
foreach (var assetName in AssetsFilters)
{
Match propertyMatch = propertyRegex.Match(assetName);
if (propertyMatch.Success)
{
if (propertyMatch.Groups["key"].Value == "roles")
{
assetFilters.Add(new RolesAssetFilter(new Regex(propertyMatch.Groups["value"].Value)));
continue;
}
if (propertyMatch.Groups["key"].Value == "uri")
{
assetFilters.Add(new UriAssetFilter(new Regex(propertyMatch.Groups["value"].Value)));
continue;
}
assetFilters.Add(new PropertyAssetFilter(propertyMatch.Groups["key"].Value,
new Regex(propertyMatch.Groups["value"].Value)));
continue;
}
else
{
assetFilters.Add(new KeyAssetFilter(new Regex(assetName)));
}
}
return assetFilters;
}

private IEnumerator<ISupplier> InitSuppliersEnumerator(IResource route, SupplierFilters filters)
{
if (route is IItem)
Expand Down
5 changes: 3 additions & 2 deletions src/Stars.Console/Terradue.Stars.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<Version>0.8.5</Version>
<!-- <VersionSuffix>beta.1</VersionSuffix> -->
<Version>0.8.6</Version>
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)-$(VersionSuffix)</Version>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<AssemblyName>Stars</AssemblyName>
<UserSecretsId>f195eead-6dad-49d2-ad76-d9dbf6662371</UserSecretsId>
<RuntimeIdentifiers>win7-x64;win10-x64;osx-x64;linux-x64;centos.7-x64</RuntimeIdentifiers>
Expand Down
7 changes: 1 addition & 6 deletions src/Stars.Services/FilteredAssetContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ public FilteredAssetContainer(IAssetsContainer assetsContainer, AssetFilters ass
private bool AssetMatch(KeyValuePair<string, IAsset> asset)
{
if (assetFilters == null) return true;
return assetFilters.Values.All(af =>
(af.KeyRegex == null || af.KeyRegex.IsMatch(asset.Key)) &&
(af.RolesRegex == null || asset.Value.Roles.Any(role => af.RolesRegex.IsMatch(role))) &&
(af.UriRegex == null || af.UriRegex.IsMatch(asset.Value.Uri.ToString())) &&
(af.PropertyRegexPattern.Value == null || af.PropertyRegexPattern.Value.IsMatch(asset.Value.Properties[af.PropertyRegexPattern.Key].ToString()))
);
return assetFilters.All(af => af.IsMatch(asset));
}
}
}
69 changes: 66 additions & 3 deletions src/Stars.Services/Supplier/AssetFilters.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,94 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Terradue.Stars.Interface;

namespace Terradue.Stars.Services.Supplier
{
public class AssetFilters : Dictionary<string, AssetFilter>
public class AssetFilters : List<IAssetFilter>
{

public static AssetFilters None => new AssetFilters();

public static AssetFilters SkipRelative
{
get
{
var af = new AssetFilters();
af.Add("absoluteUri", new AssetFilter() { UriRegex = new Regex(@"^(?:[a-z]+:)?//") });
af.Add(new UriAssetFilter(new Regex(@"^(?:[a-z]+:)?//")));
return af;
}
}
}

public class AssetFilter
public interface IAssetFilter
{
bool IsMatch(KeyValuePair<string, IAsset> asset);
}

public class UriAssetFilter : IAssetFilter
{
public UriAssetFilter(Regex uriRegex)
{
UriRegex = uriRegex;
}

public Regex UriRegex { get; set; }

public bool IsMatch(KeyValuePair<string, IAsset> asset)
{
return UriRegex.IsMatch(asset.Value.Uri.ToString());
}
}



public class RolesAssetFilter : IAssetFilter
{

public Regex RolesRegex { get; set; }

public RolesAssetFilter(Regex rolesRegex)
{
RolesRegex = rolesRegex;
}

public bool IsMatch(KeyValuePair<string, IAsset> asset)
{
return asset.Value.Roles.Any(role => RolesRegex.IsMatch(role));
}
}

public class KeyAssetFilter : IAssetFilter
{

public Regex KeyRegex { get; set; }

public KeyAssetFilter(Regex keyRegex)
{
KeyRegex = keyRegex;
}

public bool IsMatch(KeyValuePair<string, IAsset> asset)
{
return KeyRegex.IsMatch(asset.Key);
}
}

public class PropertyAssetFilter : IAssetFilter
{

public KeyValuePair<string, Regex> PropertyRegexPattern { get; set; }

public PropertyAssetFilter(string key, Regex valuePattern)
{
PropertyRegexPattern = new KeyValuePair<string, Regex>(key, valuePattern);
}

public bool IsMatch(KeyValuePair<string, IAsset> asset)
{
return asset.Value.Properties.ContainsKey(PropertyRegexPattern.Key) &&
PropertyRegexPattern.Value.IsMatch(asset.Value.Properties[PropertyRegexPattern.Key].ToString());
}
}
}
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.8.5</Version>
<Version>0.8.6</Version>
<!-- <VersionSuffix>beta.1</VersionSuffix> -->
<AssemblyName>Terradue.Stars.Services</AssemblyName>
<PackageId>Terradue.Stars</PackageId>
Expand Down

0 comments on commit bffc0f9

Please sign in to comment.