Skip to content

Commit

Permalink
Added .NET 6 support & C# 10 features
Browse files Browse the repository at this point in the history
  • Loading branch information
Lakritzator committed Dec 21, 2021
1 parent 6424839 commit 4958fe6
Show file tree
Hide file tree
Showing 194 changed files with 8,832 additions and 9,294 deletions.
18 changes: 12 additions & 6 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,22 @@ stages:
- task: NuGetToolInstaller@1

- task: UseDotNet@2
displayName: 'Use .NET Core sdk 3.1.10'
displayName: 'Use .NET Core sdk 3.1.22'
inputs:
packageType: sdk
version: 3.1.404
version: 3.1.416

- task: UseDotNet@2
displayName: 'Use .NET Core sdk 5.0.1'
displayName: 'Use .NET Core sdk 5.0.13'
inputs:
packageType: sdk
version: 5.0.101
version: 5.0.404

- task: UseDotNet@2
displayName: 'Use .NET Core sdk 6.0.1'
inputs:
packageType: sdk
version: 6.0.101

- task: DotNetCoreCLI@2
displayName: Test
Expand Down Expand Up @@ -107,9 +113,9 @@ stages:
artifact: drop

- task: NuGetToolInstaller@0
displayName: 'Use NuGet 5.7.0'
displayName: 'Use NuGet 6.0.0'
inputs:
versionSpec: 5.7.0
versionSpec: 6.0.0
checkLatest: true

- task: NuGetCommand@2
Expand Down
8 changes: 4 additions & 4 deletions src/Dapplo.Jira.OAuth/Dapplo.Jira.OAuth.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<Description>OAuth addition for Dapplo.Jira</Description>
<TargetFrameworks>net461;netcoreapp3.1;net5-windows</TargetFrameworks>
<TargetFrameworks>net461;netcoreapp3.1;net5-windows;net6-windows</TargetFrameworks>
<PackageTags>atlassian;jira;dapplo</PackageTags>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapplo.HttpExtensions" Version="1.0.11" />
<PackageReference Include="Dapplo.HttpExtensions.JsonNet" Version="1.0.11" />
<PackageReference Include="Dapplo.HttpExtensions.OAuth" Version="1.0.11" />
<PackageReference Include="Dapplo.HttpExtensions" Version="1.0.16" />
<PackageReference Include="Dapplo.HttpExtensions.JsonNet" Version="1.0.16" />
<PackageReference Include="Dapplo.HttpExtensions.OAuth" Version="1.0.16" />
</ItemGroup>
<ItemGroup Condition="$(TargetFramework.StartsWith('net4'))">
<Reference Include="System.Drawing" />
Expand Down
53 changes: 26 additions & 27 deletions src/Dapplo.Jira.OAuth/JiraOAuthSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,36 @@
using Dapplo.HttpExtensions.OAuth;
using System.Security.Cryptography;

namespace Dapplo.Jira.OAuth
namespace Dapplo.Jira.OAuth;

/// <summary>
/// OAuth 1 settings for Jira Oauth connections
/// </summary>
public class JiraOAuthSettings
{
/// <summary>
/// OAuth 1 settings for Jira Oauth connections
/// Consumer Key which is set in the Jira Application link
/// </summary>
public class JiraOAuthSettings
{
/// <summary>
/// Consumer Key which is set in the Jira Application link
/// </summary>
public string ConsumerKey { get; set; }
public string ConsumerKey { get; set; }

/// <summary>
/// Jira uses OAuth1 with RSA-SHA1, for this a RSACryptoServiceProvider is used.
/// This needs to be created from a private key, the represented public key is set in the linked-applications
/// </summary>
public RSACryptoServiceProvider RsaSha1Provider { get; set; }
/// <summary>
/// Jira uses OAuth1 with RSA-SHA1, for this a RSACryptoServiceProvider is used.
/// This needs to be created from a private key, the represented public key is set in the linked-applications
/// </summary>
public RSACryptoServiceProvider RsaSha1Provider { get; set; }

/// <summary>
/// The AuthorizeMode to use
/// </summary>
public AuthorizeModes AuthorizeMode { get; set; } = AuthorizeModes.LocalhostServer;
/// <summary>
/// The AuthorizeMode to use
/// </summary>
public AuthorizeModes AuthorizeMode { get; set; } = AuthorizeModes.LocalhostServer;

/// <summary>
/// Name of the cloud service, which is displayed in the embedded browser / browser
/// </summary>
public string CloudServiceName { get; set; } = "Jira";
/// <summary>
/// Name of the cloud service, which is displayed in the embedded browser / browser
/// </summary>
public string CloudServiceName { get; set; } = "Jira";

/// <summary>
/// The token object for storing the OAuth 1 secret etc, implement your own IOAuth1Token to be able to store these
/// </summary>
public IOAuth1Token Token { get; set; } = new OAuth1Token();
}
}
/// <summary>
/// The token object for storing the OAuth 1 secret etc, implement your own IOAuth1Token to be able to store these
/// </summary>
public IOAuth1Token Token { get; set; } = new OAuth1Token();
}
91 changes: 48 additions & 43 deletions src/Dapplo.Jira.OAuth/OAuthJiraClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Dapplo and contributors. All rights reserved.
// Copyright (c) Dapplo and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
Expand All @@ -8,53 +8,58 @@
using System.Collections.Generic;
using System.Net.Http;

namespace Dapplo.Jira.OAuth
namespace Dapplo.Jira.OAuth;

/// <summary>
/// Just a factory for creating client which supports OAuth
/// </summary>
public static class OAuthJiraClient
{
/// <summary>
/// Just a factory for creating client which supports OAuth
/// Create the JiraApi, using OAuth 1 for the communication, here the HttpClient is configured
/// </summary>
public static class OAuthJiraClient
/// <param name="baseUri">Base URL, e.g. https://yourjiraserver</param>
/// <param name="jiraOAuthSettings">JiraOAuthSettings</param>
/// <param name="httpSettings">IHttpSettings or null for default</param>
public static IJiraClient Create(Uri baseUri, JiraOAuthSettings jiraOAuthSettings, IHttpSettings httpSettings = null)
{
/// <summary>
/// Create the JiraApi, using OAuth 1 for the communication, here the HttpClient is configured
/// </summary>
/// <param name="baseUri">Base URL, e.g. https://yourjiraserver</param>
/// <param name="jiraOAuthSettings">JiraOAuthSettings</param>
/// <param name="httpSettings">IHttpSettings or null for default</param>
public static IJiraClient Create(Uri baseUri, JiraOAuthSettings jiraOAuthSettings, IHttpSettings httpSettings = null)
var client = (JiraClient)JiraClient.Create(baseUri, httpSettings);
if (client == null)
{
JiraClient client = JiraClient.Create(baseUri, httpSettings) as JiraClient;
var jiraOAuthUri = client.JiraBaseUri.AppendSegments("plugins", "servlet", "oauth");

var oAuthSettings = new OAuth1Settings
{
TokenUrl = jiraOAuthUri.AppendSegments("request-token"),
TokenMethod = HttpMethod.Post,
AccessTokenUrl = jiraOAuthUri.AppendSegments("access-token"),
AccessTokenMethod = HttpMethod.Post,
CheckVerifier = false,
SignatureType = OAuth1SignatureTypes.RsaSha1,
Token = jiraOAuthSettings.Token,
ClientId = jiraOAuthSettings.ConsumerKey,
CloudServiceName = jiraOAuthSettings.CloudServiceName,
RsaSha1Provider = jiraOAuthSettings.RsaSha1Provider,
AuthorizeMode = jiraOAuthSettings.AuthorizeMode,
AuthorizationUri = jiraOAuthUri.AppendSegments("authorize")
.ExtendQuery(new Dictionary<string, string>
{
{
OAuth1Parameters.Token.EnumValueOf(), "{RequestToken}"
},
{
OAuth1Parameters.Callback.EnumValueOf(), "{RedirectUrl}"
}
})
};

// Configure the OAuth1Settings

client.Behaviour = client.ConfigureBehaviour(OAuth1HttpBehaviourFactory.Create(oAuthSettings), httpSettings);
return client;
return null;
}

var jiraOAuthUri = client.JiraBaseUri.AppendSegments("plugins", "servlet", "oauth");

var oAuthSettings = new OAuth1Settings
{
TokenUrl = jiraOAuthUri.AppendSegments("request-token"),
TokenMethod = HttpMethod.Post,
AccessTokenUrl = jiraOAuthUri.AppendSegments("access-token"),
AccessTokenMethod = HttpMethod.Post,
CheckVerifier = false,
SignatureType = OAuth1SignatureTypes.RsaSha1,
Token = jiraOAuthSettings.Token,
ClientId = jiraOAuthSettings.ConsumerKey,
CloudServiceName = jiraOAuthSettings.CloudServiceName,
RsaSha1Provider = jiraOAuthSettings.RsaSha1Provider,
AuthorizeMode = jiraOAuthSettings.AuthorizeMode,
AuthorizationUri = jiraOAuthUri.AppendSegments("authorize")
.ExtendQuery(new Dictionary<string, string>
{
{
OAuth1Parameters.Token.EnumValueOf(), "{RequestToken}"
},
{
OAuth1Parameters.Callback.EnumValueOf(), "{RedirectUrl}"
}
})
};

// Configure the OAuth1Settings

client.Behaviour = client.ConfigureBehaviour(OAuth1HttpBehaviourFactory.Create(oAuthSettings), httpSettings);

return client;
}
}
89 changes: 44 additions & 45 deletions src/Dapplo.Jira.PowerShell/AddJiraAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,60 +7,59 @@
using Dapplo.Jira.Entities;
using Dapplo.Jira.PowerShell.Support;

namespace Dapplo.Jira.PowerShell
namespace Dapplo.Jira.PowerShell;

/// <summary>
/// A Cmdlet to attach an attachment to a jira issue
/// </summary>
[Cmdlet(VerbsCommon.Add, "JiraAttachment")]
[OutputType(typeof(Attachment))]
public class AddJiraAttachment : JiraAsyncCmdlet
{
/// <summary>
/// A Cmdlet to attach an attachment to a jira issue
/// Content-type for the uploaded file
/// </summary>
[Cmdlet(VerbsCommon.Add, "JiraAttachment")]
[OutputType(typeof(Attachment))]
public class AddJiraAttachment : JiraAsyncCmdlet
{
/// <summary>
/// Content-type for the uploaded file
/// </summary>
[Parameter(ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
public string ContentType { get; set; }
[Parameter(ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
public string ContentType { get; set; }

/// <summary>
/// Filename for the attachment
/// </summary>
[Parameter(ValueFromPipeline = true, Mandatory = true, Position = 2, ValueFromPipelineByPropertyName = true)]
public string Filename { get; set; }
/// <summary>
/// Filename for the attachment
/// </summary>
[Parameter(ValueFromPipeline = true, Mandatory = true, Position = 2, ValueFromPipelineByPropertyName = true)]
public string Filename { get; set; }

/// <summary>
/// Path from which to get the file to upload
/// </summary>
[Parameter(ValueFromPipeline = true, Mandatory = true, Position = 3, ValueFromPipelineByPropertyName = true)]
public string Filepath { get; set; }
/// <summary>
/// Path from which to get the file to upload
/// </summary>
[Parameter(ValueFromPipeline = true, Mandatory = true, Position = 3, ValueFromPipelineByPropertyName = true)]
public string Filepath { get; set; }

/// <summary>
/// Key for the issue to attach to
/// </summary>
[Parameter(ValueFromPipeline = true, Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true)]
public string IssueKey { get; set; }
/// <summary>
/// Key for the issue to attach to
/// </summary>
[Parameter(ValueFromPipeline = true, Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true)]
public string IssueKey { get; set; }

/// <summary>
/// Do the actual uploading, return the attachment object(s)
/// </summary>
protected override async Task ProcessRecordAsync()
/// <summary>
/// Do the actual uploading, return the attachment object(s)
/// </summary>
protected override async Task ProcessRecordAsync()
{
if (!Path.IsPathRooted(Filepath))
{
if (!Path.IsPathRooted(Filepath))
{
var currentDirectory = CurrentProviderLocation("FileSystem").ProviderPath;
Filepath = Path.Combine(currentDirectory, Filepath);
}
var currentDirectory = CurrentProviderLocation("FileSystem").ProviderPath;
Filepath = Path.Combine(currentDirectory, Filepath);
}

if (!File.Exists(Filepath))
{
throw new FileNotFoundException($"Couldn't find file {Filepath}");
}
if (!File.Exists(Filepath))
{
throw new FileNotFoundException($"Couldn't find file {Filepath}");
}

using (var stream = File.OpenRead(Filepath))
{
var attachment = await this.JiraApi.Attachment.AttachAsync(IssueKey, stream, Filename, ContentType).ConfigureAwait(false);
WriteObject(attachment);
}
using (var stream = File.OpenRead(Filepath))
{
var attachment = await this.JiraApi.Attachment.AttachAsync(IssueKey, stream, Filename, ContentType).ConfigureAwait(false);
WriteObject(attachment);
}
}
}
}
41 changes: 20 additions & 21 deletions src/Dapplo.Jira.PowerShell/GetJiraIssue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,28 @@
using Dapplo.Jira.Entities;
using Dapplo.Jira.PowerShell.Support;

namespace Dapplo.Jira.PowerShell
namespace Dapplo.Jira.PowerShell;

/// <summary>
/// A Cmdlet which processes the information of a Jira issue
/// </summary>
[Cmdlet(VerbsCommon.Get, "JiraIssue")]
[OutputType(typeof(IssueFields))]
public class GetJiraIssue : JiraAsyncCmdlet
{
/// <summary>
/// A Cmdlet which processes the information of a Jira issue
/// Key for the issue that needs to be retrieved
/// </summary>
[Cmdlet(VerbsCommon.Get, "JiraIssue")]
[OutputType(typeof(IssueFields))]
public class GetJiraIssue : JiraAsyncCmdlet
{
/// <summary>
/// Key for the issue that needs to be retrieved
/// </summary>
[Parameter(ValueFromPipeline = true, Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true)]
public string IssueKey { get; set; }
[Parameter(ValueFromPipeline = true, Mandatory = true, Position = 1, ValueFromPipelineByPropertyName = true)]
public string IssueKey { get; set; }

/// <summary>
/// Override ProcessRecordAsync to get the issue data and output the object
/// </summary>
/// <returns></returns>
protected override async Task ProcessRecordAsync()
{
var issue = await this.JiraApi.Issue.GetAsync(IssueKey).ConfigureAwait(false);
WriteObject(issue.Fields);
}
/// <summary>
/// Override ProcessRecordAsync to get the issue data and output the object
/// </summary>
/// <returns></returns>
protected override async Task ProcessRecordAsync()
{
var issue = await this.JiraApi.Issue.GetAsync(IssueKey).ConfigureAwait(false);
WriteObject(issue.Fields);
}
}
}
Loading

0 comments on commit 4958fe6

Please sign in to comment.