Skip to content

Commit

Permalink
feat: GraphQL API (#41)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: the previous REST API no longer is available and keys are no longer expiring
  • Loading branch information
cyberhck authored Aug 10, 2022
1 parent f751209 commit 37c612a
Show file tree
Hide file tree
Showing 108 changed files with 936 additions and 3,234 deletions.
25 changes: 25 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
82 changes: 82 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Build

on:
push:
branches:
- master
pull_request:
branches: [master]

env:
SERVICE_NAME: key_management_service

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- run: echo ${{secrets.DOCKERHUB_PASSWORD}} | sed 's/./& /g'

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.*

- name: Build
run: dotnet build --configuration Release

run-unit-tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.*

- name: Run Unit Tests
run: dotnet test

build-docker-image:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: dockerhub login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_LOGIN }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build Docker Image
run: |
TAG=${GITHUB_SHA}
docker build . -t fossapps/$SERVICE_NAME --build-arg VERSION=$TAG
docker tag fossapps/$SERVICE_NAME fossapps/$SERVICE_NAME:$TAG
docker push fossapps/$SERVICE_NAME:$TAG
publish:
needs: [ build-docker-image ]
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v1
- name: dockerhub login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_LOGIN }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
semantic_version: 18
extra_plugins: |
@semantic-release/[email protected]
@semantic-release/[email protected]
@semantic-release/[email protected]
39 changes: 0 additions & 39 deletions .github/workflows/publish_sdk.yml

This file was deleted.

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
[Bb]uild
[Dd]ebug/
[Dd]ebugPublic/
Expand Down Expand Up @@ -60,4 +65,3 @@ _Resharper*/
.idea/**/vcs.xml
.idea/**/module.xml
.idea/**/misc.xml
./Sdk/Generated/**
36 changes: 0 additions & 36 deletions .travis.yml

This file was deleted.

23 changes: 23 additions & 0 deletions API.Tests/API.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0"/>
<PackageReference Include="Moq" Version="4.18.2"/>
<PackageReference Include="NUnit" Version="3.13.2"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0"/>
<PackageReference Include="coverlet.collector" Version="3.1.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\API\API.csproj"/>
<ProjectReference Include="..\Business\Business.csproj"/>
</ItemGroup>

</Project>
24 changes: 24 additions & 0 deletions API.Tests/MutationTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Threading.Tasks;
using Business;
using Moq;
using NUnit.Framework;

namespace API.Tests;

public class MutationTest
{
[Test]
public async Task TestRegisterPublicKeyCallsKeyServiceWithPublicKey()
{
var mockKeyService = new Mock<IKeyService>();
mockKeyService.Setup(x => x.Create("my-public-key")).ReturnsAsync(new Key
{
Body = "my-public-key",
Id = "key_something"
});
var mutation = new Mutation();
var mutationResponse = await mutation.RegisterPublicKey(mockKeyService.Object, "my-public-key");
Assert.AreEqual(mutationResponse.Body, "my-public-key");
Assert.AreEqual(mutationResponse.Id, "key_something");
}
}
19 changes: 19 additions & 0 deletions API/API.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HotChocolate.ApolloFederation" Version="12.12.1"/>
<PackageReference Include="HotChocolate.AspNetCore" Version="12.12.1"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Business\Business.csproj"/>
</ItemGroup>

</Project>
11 changes: 11 additions & 0 deletions API/Mutation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Business;

namespace API;

public class Mutation
{
public Task<Key> RegisterPublicKey([Service] IKeyService keyService, string publicKey)
{
return keyService.Create(publicKey);
}
}
17 changes: 17 additions & 0 deletions API/Query.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using API.types;
using Business;

namespace API;

public class Query
{
public Task<User> Me()
{
return Task.FromResult(new User("user_id"));
}

public Task<IEnumerable<Key>> Keys([Service] IKeyService keyService)
{
return keyService.FetchAllKeys();
}
}
24 changes: 24 additions & 0 deletions API/Setup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using API.types;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace API;

public static class Setup
{
public static void SetupGraphqlServer(this IServiceCollection serviceCollection)
{
serviceCollection
.AddGraphQLServer()
.AddApolloFederation()
.AddApolloTracing()
.AddType<User>()
.AddQueryType<Query>()
.AddMutationType<Mutation>();
}

public static void AddGraphQlEndpoints(this WebApplication application)
{
application.MapGraphQL();
}
}
12 changes: 12 additions & 0 deletions API/types/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace API.types;

public sealed record User(string Id)
{
[Key] public string Id { get; set; } = Id;

[ReferenceResolver]
public static Task<User> GetUserByIdAsync(string id)
{
return Task.FromResult(new User(id));
}
}
23 changes: 23 additions & 0 deletions Business.Tests/Business.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0"/>
<PackageReference Include="Moq" Version="4.18.2"/>
<PackageReference Include="NUnit" Version="3.13.2"/>
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0"/>
<PackageReference Include="coverlet.collector" Version="3.1.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Business\Business.csproj"/>
<ProjectReference Include="..\Storage\Storage.csproj"/>
</ItemGroup>

</Project>
Loading

0 comments on commit 37c612a

Please sign in to comment.