Skip to content

Commit 946a7fc

Browse files
committed
Added README file;
Change order of repos to order by updated date desc; Moved project to src folder;
1 parent e268b1d commit 946a7fc

File tree

82 files changed

+104
-59
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+104
-59
lines changed

README.md

+38

Services/GitHubService.cs

-50
This file was deleted.
47.7 KB
47.2 KB

images/sample.png

88 KB

.dockerignore src/.dockerignore

File renamed without changes.

.gitignore src/.gitignore

File renamed without changes.

Dockerfile src/Dockerfile

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
2-
31
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
42
USER app
53
WORKDIR /app
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Program.cs src/Program.cs

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
using System.Security.Claims;
2-
using Microsoft.AspNetCore.Authentication.Cookies;
3-
using Microsoft.AspNetCore.Authentication;
41
using GitHubRepoSecrets.Services;
2+
using Microsoft.AspNetCore.Authentication;
3+
using Microsoft.AspNetCore.Authentication.Cookies;
54
using Microsoft.AspNetCore.HttpOverrides;
5+
using System.Security.Claims;
66

77
var builder = WebApplication.CreateBuilder(args);
88

9+
var githubClientId = builder.Configuration["github:clientId"];
10+
if (string.IsNullOrEmpty(githubClientId))
11+
{
12+
throw new ArgumentException("GITHUB__CLIENTID is required");
13+
}
14+
15+
var githubClientSecret = builder.Configuration["github:clientSecret"];
16+
if (string.IsNullOrEmpty(githubClientSecret))
17+
{
18+
throw new ArgumentException("GITHUB__CLIENTSECRET is required");
19+
}
20+
921
builder.Services
1022
.AddAuthentication(o =>
1123
{
@@ -18,18 +30,16 @@
1830
})
1931
.AddGitHub(options =>
2032
{
21-
options.ClientSecret = builder.Configuration["github:clientSecret"];
22-
options.ClientId = builder.Configuration["github:clientId"];
33+
options.ClientSecret = githubClientSecret;
34+
options.ClientId = githubClientId;
2335
options.CallbackPath = "/signin-github";
2436
options.Scope.Add("repo");
2537
options.Events.OnCreatingTicket += context =>
2638
{
2739
if (context.AccessToken is { })
2840
{
2941
context.Identity?.AddClaim(new Claim("access_token", context.AccessToken));
30-
3142
}
32-
3343
return Task.CompletedTask;
3444
};
3545
});
File renamed without changes.

src/Services/GitHubService.cs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using Octokit;
2+
3+
namespace GitHubRepoSecrets.Services;
4+
5+
public class GitHubService
6+
{
7+
private readonly GitHubClient _client;
8+
9+
public GitHubService(IHttpContextAccessor httpContextAccessor)
10+
{
11+
var accessToken = httpContextAccessor.HttpContext.User.FindFirst("access_token")?.Value;
12+
13+
if (accessToken is not null)
14+
{
15+
_client = new GitHubClient(new ProductHeaderValue("test"))
16+
{
17+
Credentials = new Credentials(accessToken)
18+
};
19+
}
20+
}
21+
22+
public async Task<IReadOnlyList<Repository>> GetRepositoriesAsync()
23+
{
24+
return await _client.Repository.GetAllForCurrent(new RepositoryRequest { Sort = RepositorySort.Updated, Direction = SortDirection.Descending});
25+
}
26+
27+
public async Task<RepositorySecretsCollection> GetSecretsAsync(string owner, string repo)
28+
{
29+
return await _client.Repository.Actions.Secrets.GetAll(owner, repo);
30+
}
31+
32+
public async Task<RepositorySecret> GetSecretAsync(string owner, string repo, string secretName)
33+
{
34+
return await _client.Repository.Actions.Secrets.Get(owner, repo, secretName);
35+
}
36+
37+
public async Task DeleteSecretAsync(string owner, string repo, string secretName)
38+
{
39+
await _client.Repository.Actions.Secrets.Delete(owner, repo, secretName);
40+
}
41+
42+
public async Task CreateOrUpdateSecretAsync(string owner, string repo, string secretName, string secretValue)
43+
{
44+
SecretsPublicKey secretsPublicKey = await _client.Repository.Actions.Secrets.GetPublicKey(owner, repo);
45+
var secretsPublicKeyBytes = Convert.FromBase64String(secretsPublicKey.Key);
46+
var encryptedValue = Convert.ToBase64String(Sodium.SealedPublicKeyBox.Create(secretValue, secretsPublicKeyBytes));
47+
await _client.Repository.Actions.Secrets.CreateOrUpdate(owner, repo, secretName, new UpsertRepositorySecret { KeyId = secretsPublicKey.KeyId, EncryptedValue = encryptedValue });
48+
}
49+
}
File renamed without changes.
File renamed without changes.

libman.json src/libman.json

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)