Skip to content

Commit

Permalink
Update to match recently-changed CloudMQTT API (#2)
Browse files Browse the repository at this point in the history
* Update to match recently-changed CloudMQTT API

* Handle breaking changes in Cake.Docker

Update DockerRunSettings class name to DockerContainerRunSettings.

* We don't actually need a dictionary for this...
  • Loading branch information
cuevaskoch authored and thzinc committed Dec 22, 2017
1 parent e880794 commit 521947b
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 14 deletions.
6 changes: 4 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

void RunTargetInContainer(string target, string arguments, params string[] includeEnvironmentVariables) {
var cwd = MakeAbsolute(Directory("./"));
var env = includeEnvironmentVariables.ToDictionary(key => key, key => EnvironmentVariable(key));
var env = includeEnvironmentVariables
.Select(key => new { Key = key, Value = EnvironmentVariable(key) })
.ToArray();

var missingEnv = env.Where(x => string.IsNullOrEmpty(x.Value)).ToList();
if (missingEnv.Any()) {
throw new Exception($"The following environment variables are required to be set: {string.Join(", ", missingEnv.Select(x => x.Key))}");
}

var settings = new DockerRunSettings
var settings = new DockerContainerRunSettings
{
Volume = new string[] { $"{cwd}:/artifacts"},
Workdir = "/artifacts",
Expand Down
5 changes: 3 additions & 2 deletions src/CloudMQTT.Client.Tests/WhenGettingUsers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ public async Task ItShouldCreateAndDeleteUserSuccessfully()

var expectedRule = new Rule
{
RuleType = RuleType.Topic,
Read = true,
Topic = "test",
Username = expectedUser.Username,
Pattern = "test",
User = expectedUser.Username,
Write = true,
};

Expand Down
2 changes: 1 addition & 1 deletion src/CloudMQTT.Client/ICloudMqttApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public interface ICloudMqttApi
Task<HttpResponseMessage> DeleteUser([Path]string username);

[Get("acl")]
Task<List<Rule>> GetRules();
Task<RulesResponse> GetRules();

[Post("acl")]
[Header("Content-Type", "application/json")]
Expand Down
9 changes: 6 additions & 3 deletions src/CloudMQTT.Client/Rule.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
using Newtonsoft.Json;

namespace CloudMQTT.Client
{
public class Rule
{
public string Username { get; set; }
public string Topic { get; set; }
[JsonProperty("type")]
public RuleType RuleType { get; set; }
public string User { get; set; }
public string Pattern { get; set; }
public bool Read { get; set; }
public bool Write { get; set; }

}
}
13 changes: 9 additions & 4 deletions src/CloudMQTT.Client/RuleReference.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
using Newtonsoft.Json;

namespace CloudMQTT.Client
{
public class RuleReference
{
public string Username { get; set; }
public string Topic { get; set; }
[JsonProperty("type")]
public RuleType RuleType { get; set; }
public string User { get; set; }
public string Pattern { get; set; }

public static implicit operator RuleReference(Rule rule) => new RuleReference()
{
Topic = rule.Topic,
Username = rule.Username,
RuleType = rule.RuleType,
Pattern = rule.Pattern,
User = rule.User,
};
}
}
16 changes: 16 additions & 0 deletions src/CloudMQTT.Client/RuleType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Runtime.Serialization;

namespace CloudMQTT.Client
{
[JsonConverter(typeof(StringEnumConverter))]
public enum RuleType
{
[EnumMember(Value = "topic")]
Topic,

[EnumMember(Value = "pattern")]
Pattern
}
}
9 changes: 9 additions & 0 deletions src/CloudMQTT.Client/RulesResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace CloudMQTT.Client
{
public class RulesResponse
{
public List<Rule> Items { get; set; }
}
}
7 changes: 5 additions & 2 deletions src/CloudMQTT.Client/UserRule.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using Newtonsoft.Json;

namespace CloudMQTT.Client
{
public class UserRule
{
public string Topic { get; set; }
[JsonProperty("topic")]
public string Pattern { get; set; }
public bool Read { get; set; }
public bool Write { get; set; }

public static implicit operator UserRule(Rule rule) => new UserRule
{
Topic = rule.Topic,
Pattern = rule.Pattern,
Read = rule.Read,
Write = rule.Write,
};
Expand Down

0 comments on commit 521947b

Please sign in to comment.