Skip to content

Commit

Permalink
Merge pull request #28 from nitrictech/feature/new-api-changes
Browse files Browse the repository at this point in the history
refactor: API Updates
  • Loading branch information
tjholm authored Jul 15, 2021
2 parents 7ee0a10 + 46145b9 commit 9a5d0d1
Show file tree
Hide file tree
Showing 36 changed files with 746 additions and 1,093 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/dotnet-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.x

- name: Find and Replace Version templates
run: |
sed -i.bak 's/${VERSION}/0.0.1/g' Nitric.Sdk/Nitric.Sdk.csproj
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand All @@ -37,7 +39,8 @@ jobs:
dotnet tool install --global dotnet-project-licenses
echo "['MIT','Apache-2.0','BSD-3-Clause']" > licenses.json
echo "['Google.Protobuf']" > filter.json
dotnet-project-licenses -i Nitric.Sdk --allowed-license-types licenses.json --packages-filter filter.json
echo "['Nitric.Sdk.csproj']" > packageFilter.json
dotnet-project-licenses -i Nitric.Sdk --allowed-license-types licenses.json --projects-filter packageFilter.json --packages-filter filter.json
rm licenses.json
rm filter.json
dotnet tool uninstall --global dotnet-project-licenses
Expand Down
32 changes: 8 additions & 24 deletions .github/workflows/draft-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:

jobs:
version:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout
Expand All @@ -20,37 +21,20 @@ jobs:
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Install Versionize
run: dotnet tool install --global Versionize --version 1.6.2

- name: Install Dependencies
run: dotnet restore

- name: Version Bump and tag
run: |
versionize
shell: bash

- name: Push version bump & tags
run: |
git fetch
git checkout main
git push origin main --follow-tags
- name: Get latest tag
run: |
echo "::set-output name=TAG_REF::`git describe --abbrev=0`"
id: latest_tag

- name: Create Draft Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.latest_tag.outputs.TAG_REF }}
release_name: Release ${{ steps.latest_tag.outputs.TAG_REF }}
tag_name: ${{ steps.tag_version.outputs.new_tag }}
release_name: Release ${{ steps.tag_version.outputs.new_tag }}
body: See CHANGELOG.md for changes
draft: true
prerelease: false
13 changes: 10 additions & 3 deletions .github/workflows/publish-on-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ jobs:
dotnet-version: 5.0.x
env:
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_TOKEN }}
- name: Install Dependencies
run: dotnet restore
- name: Normalize version string
run: |
version="${{ github.event.release.tag_name }}"
echo "::set-output name=VERSION::`echo ${version:1}`"
id: normalize_version
- name: Find and Replace Version templates
run: |
sed -i.bak 's/${VERSION}/${{ steps.normalize_version.outputs.VERSION }}/g' Nitric.Sdk/Nitric.Sdk.csproj
rm Nitric.Sdk/Nitric.Sdk.csproj.bak
- name: Exclude Test Project
run: dotnet sln remove Nitric.Test/**
run: dotnet sln remove Nitric.Test
- name: Restore Dependencies
run: dotnet restore
- name: Publish
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "contracts"]
path = Nitric.Proto/contracts
path = Nitric.Sdk/contracts
url = [email protected]:nitrictech/contracts.git
20 changes: 0 additions & 20 deletions Nitric.Proto/Nitric.Proto.csproj

This file was deleted.

25 changes: 0 additions & 25 deletions Nitric.Proto/Nitric.Proto.sln

This file was deleted.

1 change: 0 additions & 1 deletion Nitric.Proto/contracts
Submodule contracts deleted from 19a3cf
5 changes: 5 additions & 0 deletions Nitric.Sdk/Common/AbstractClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace Nitric.Api.Common
{
public abstract class AbstractClient
{
string DefaultHostName = "127.0.0.1:50051";
public AbstractClient()
{
GetChannel();
Expand All @@ -26,6 +27,10 @@ protected Channel GetChannel()
{
// TODO: Pull from settings
string serviceBind = Util.GetEnvVar("SERVICE_BIND");
if (string.IsNullOrEmpty(serviceBind))
{
serviceBind = DefaultHostName;
}
return new Channel(serviceBind, ChannelCredentials.Insecure); ;
}
}
Expand Down
69 changes: 42 additions & 27 deletions Nitric.Sdk/Event/EventClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,68 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
using System;
using System.Collections.Generic;
using Nitric.Api.Common;
using NitricEvent = Nitric.Proto.Event.v1.NitricEvent;
using Nitric.Proto.Event.v1;
using ProtoClient = Nitric.Proto.Event.v1.Event.EventClient;
using GrpcClient = Nitric.Proto.Event.v1.EventService.EventServiceClient;
using TopicClient = Nitric.Proto.Event.v1.TopicService.TopicServiceClient;

namespace Nitric.Api.Event
{
public class EventClient : AbstractClient
public class Events : AbstractClient
{
protected ProtoClient client;
internal GrpcClient EventClient;
internal TopicClient TopicClient;

private EventClient(ProtoClient client = null)
public Events(GrpcClient client = null, TopicClient topic = null)
{
this.client = (client == null) ? new ProtoClient(this.GetChannel()) : client;
this.EventClient = (client == null) ? new GrpcClient(this.GetChannel()) : client;
this.TopicClient = (topic == null) ? new TopicClient(this.GetChannel()) : topic;
}

public string Publish(string topic, Event evt)
public Topic Topic(string topicName)
{
var payloadStruct = Util.ObjToStruct(evt.Payload);
var nEvt = new NitricEvent { Id = evt.Id, PayloadType = evt.PayloadType, Payload = payloadStruct };
var request = new EventPublishRequest { Topic = topic, Event = nEvt };
if (string.IsNullOrEmpty(topicName))
{
throw new ArgumentNullException(topicName);
}
return new Topic(this, topicName);
}
public List<Topic> List()
{
var request = new TopicListRequest { };

var response = this.client.Publish(request);
var response = TopicClient.List(request);

return response.Id;
List<Topic> topics = new List<Topic>();
foreach (NitricTopic topic in response.Topics)
{
topics.Add(new Topic(this, topic.Name));
}
return topics;
}
}
public class Topic : AbstractClient
{
internal Events Events;
public string Name { get; private set; }

public static Builder NewBuilder()
internal Topic(Events events, string name, TopicClient topic = null)
{
return new Builder();
this.Events = events;
this.Name = name;
}
public class Builder
public string Publish(Event evt)
{
private ProtoClient client;
//Forces the builder design pattern
public Builder()
{ }
public Builder Client(ProtoClient client)
{
this.client = client;
return this;
}
public EventClient Build()
{
return new EventClient(this.client);
}
var payloadStruct = Util.ObjToStruct(evt.Payload);
var nEvt = new NitricEvent { Id = evt.Id, PayloadType = evt.PayloadType, Payload = payloadStruct };
var request = new EventPublishRequest { Topic = this.Name, Event = nEvt };

var response = this.Events.EventClient.Publish(request);

return response.Id;
}
}
}
56 changes: 0 additions & 56 deletions Nitric.Sdk/Event/Topic.cs

This file was deleted.

67 changes: 0 additions & 67 deletions Nitric.Sdk/Event/TopicClient.cs

This file was deleted.

Loading

0 comments on commit 9a5d0d1

Please sign in to comment.