Skip to content

Commit

Permalink
A build
Browse files Browse the repository at this point in the history
  • Loading branch information
Boggin committed Aug 21, 2019
1 parent c4fd5db commit 4aebf3c
Show file tree
Hide file tree
Showing 21 changed files with 104 additions and 81 deletions.
6 changes: 6 additions & 0 deletions FeatureFlagger.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 25,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeatureFlagger.Tests", "tes
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FeatureFlagger.ConfigurationWriters", "src\FeatureFlagger.ConfigurationWriters\FeatureFlagger.ConfigurationWriters.csproj", "{46131F8A-055F-4CD4-8A47-405DF4103C68}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureFlagger.Authorisation", "src\FeatureFlagger.Authorisation\FeatureFlagger.Authorisation.csproj", "{1B510588-5AF7-48AD-AED6-A7F04452799D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -59,6 61,10 @@ Global
{46131F8A-055F-4CD4-8A47-405DF4103C68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{46131F8A-055F-4CD4-8A47-405DF4103C68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{46131F8A-055F-4CD4-8A47-405DF4103C68}.Release|Any CPU.Build.0 = Release|Any CPU
{1B510588-5AF7-48AD-AED6-A7F04452799D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1B510588-5AF7-48AD-AED6-A7F04452799D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1B510588-5AF7-48AD-AED6-A7F04452799D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1B510588-5AF7-48AD-AED6-A7F04452799D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
11 changes: 11 additions & 0 deletions src/FeatureFlagger.Authorisation/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 1,11 @@
namespace FeatureFlagger.Authorisation
{
public static class Constants
{
public const string Feature = "FEATURE";
public const string Lookup = "LOOKUP";
public const string Name = "NAME";
public const string User = "USER";
public const string Users = "USERS";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.7" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
namespace FeatureFlagger.Behaviours
namespace FeatureFlagger.Authorisation
{
using System;
using System.Collections.Generic;
Expand Down
16 changes: 7 additions & 9 deletions src/FeatureFlagger.Behaviours/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 2,13 @@ namespace FeatureFlagger.Behaviours
{
public static class Constants
{
public const string Config = "CONFIG";
public const string Date = "DATE";
public const string Enabled = "ENABLED";
public const string Feature = "FEATURE";
public const string Lookup = "LOOKUP";
public const string Name = "NAME";
public const string Store = "STORE";
public const string User = "USER";
public const string Users = "USERS";
public const string Config = "CONFIG";
public const string Control = "CONTROL";
public const string Date = "DATE";
public const string Enabled = "ENABLED";
public const string Feature = "FEATURE";
public const string Percentage = "PERCENTAGE";
public const string Store = "STORE";
public const string VariantSeparator = "_";
}
}
15 changes: 9 additions & 6 deletions src/FeatureFlagger.Behaviours/DistributionBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 2,12 @@
{
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Composition;
using System.Security.Cryptography;

[Export(typeof(IBehaviour))]
public class DistributionBehaviour : IBehaviour
{
private static readonly Random Random = new Random();
private static readonly object Synclock = new object();
private readonly IUser user;
private readonly IBucket bucket;
Expand All @@ -30,7 29,7 @@ public Func<Dictionary<string, string>, bool> Behaviour()
return x =>
{
var featureName = x[Constants.Feature];
var userName = user.UserName;
string userName = user.Username;
// Debug.WriteLine($"UserName: {userName}, FeatureName: {featureName}");
Expand Down Expand Up @@ -126,10 125,14 @@ private static bool RollDice(decimal percentage)
{
lock (Synclock)
{
int diceRoll;
var randomNumber = new byte[1];
var crytoService = new RNGCryptoServiceProvider();
crytoService.GetBytes(randomNumber);
var diceRoll = (randomNumber[0] % 100) 1;

using (RNGCryptoServiceProvider crytoService = new RNGCryptoServiceProvider())
{
crytoService.GetBytes(randomNumber);
diceRoll = (randomNumber[0] % 100) 1;
}

return diceRoll <= percentage * 100;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.7" />
<PackageReference Include="System.Composition.AttributedModel" Version="1.2.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/FeatureFlagger.Behaviours/IUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,7 @@ namespace FeatureFlagger.Behaviours
{
public interface IUser
{
string Username();
string Username { get; set; }

bool UserHasFeature(string userName, string featureName);
}
Expand Down
18 changes: 9 additions & 9 deletions src/FeatureFlagger.Behaviours/RolloutBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 22,22 @@ public string Basis(string basis)
{
if (basis.ToLowerInvariant().Equals("user"))
{
return this.Username();
return this.Username;
}

throw new ArgumentException("'basis' was not understood.", "basis");
}

public string Username()
public string Username
{
var r = new Random();
var rand = r.Next().ToString(CultureInfo.InvariantCulture);
return "username" rand;
}
get
{
var r = new Random();
var rand = r.Next().ToString(CultureInfo.InvariantCulture);
return "username" rand;
}

public string UserName()
{
throw new NotImplementedException();
set { throw new NotImplementedException(); }
}

public bool UserHasFeature(string userName, string featureName)
Expand Down
9 changes: 3 additions & 6 deletions src/FeatureFlagger.Behaviours/User.cs
Original file line number Diff line number Diff line change
@@ -1,13 1,15 @@
namespace FeatureFlagger.Behaviours
{
using System;
using System.ComponentModel.Composition;
using System.Composition;
using System.Configuration;
using System.Data.SqlClient;

[Export(typeof(IUser))]
public class User : IUser
{
public string Username { get => ""; set => throw new NotImplementedException(); }

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities", Justification = "SQL parameters don't come from user input.")]
public bool UserHasFeature(string userName, string featureName)
{
Expand Down Expand Up @@ -37,10 39,5 @@ public bool UserHasFeature(string userName, string featureName)

return Convert.ToBoolean(hasFeature);
}

string IUser.Username()
{
throw new NotImplementedException();
}
}
}
4 changes: 2 additions & 2 deletions src/FeatureFlagger.Behaviours/UserBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,7 @@
{
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Composition;
using System.Linq;

[Export(typeof(IBehaviour))]
Expand All @@ -21,7 21,7 @@ public Func<Dictionary<string, string>, bool> Behaviour()
{
return x =>
{
string username = x.TryGetValue("name", out username) ? username : user.Username();
string username = x.TryGetValue("name", out username) ? username : user.Username;
string lookup = x.TryGetValue("lookup", out lookup) ? lookup : "store";
if (string.IsNullOrEmpty(lookup) || lookup.Equals("store"))
Expand Down
7 changes: 4 additions & 3 deletions src/FeatureFlagger.ConfigurationReaders/ConfigReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 3,8 @@
using System;
using System.Collections.Generic;
using System.Composition;

using System.Configuration;
using System.Linq;
using FeatureFlagger.Domain;

[Export(typeof(IConfigurationReader))]
Expand All @@ -16,10 17,10 @@ private ConfigReader()

public string Name { get; }

public Feature Read(string featureName)
public Feature Read(string featureName, IEnumerable<Feature> features)
{
return
FeatureFlagger.Features.ToList()
features.ToList()
.Find(
f =>
f.Name.Equals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Composition.AttributedModel" Version="1.2.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 15,9 @@ public interface IConfigurationReader
/// Read a feature from the configuration.
/// </summary>
/// <param name="featureName">The name of the feature.</param>
/// <param name="features">The list of features.</param>
/// <returns>A Feature.</returns>
Feature Read(string featureName);
Feature Read(string featureName, IEnumerable<Feature> features);

/// <summary>
/// Read the configuration.
Expand Down
4 changes: 2 additions & 2 deletions src/FeatureFlagger.ConfigurationReaders/StoreReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 19,10 @@ private StoreReader()

public string Name { get; }

public Feature Read(string featureName)
public Feature Read(string featureName, IEnumerable<Feature> features)
{
return
FeatureFlagger.Features.ToList()
features.ToList()
.Find(
f =>
f.Name.Equals(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 5,7 @@
<ItemGroup>
<PackageReference Include="System.Composition.AttributedModel" Version="1.2.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FeatureFlagger.Domain\FeatureFlagger.Domain.csproj" />
Expand Down
28 changes: 12 additions & 16 deletions src/FeatureFlagger.ConfigurationWriters/StoreWriter.cs
Original file line number Diff line number Diff line change
@@ -1,11 1,9 @@
namespace FeatureFlagger.ConfigurationWriters
{
using System;
using System.Composition;
using System.Configuration;
using System.Data.SqlClient;
using System.Text;
using FeatureFlagger;

using Feature = Domain.Feature;

Expand All @@ -27,14 25,16 @@ public void Create(Feature feature)
{
this.CreateFeature(feature);

FeatureFlagger.SetFeatures();
// TODO: cyclic dependency?
// FeatureFlagger.SetFeatures();
}

public void Delete(string featureName)
{
this.DeleteFeature(featureName);

FeatureFlagger.SetFeatures();
// TODO: cyclic dependency?
// FeatureFlagger.SetFeatures();
}

public void Update(Feature feature)
Expand All @@ -50,7 50,8 @@ public void Update(Feature feature)
this.DeleteFeature(feature.Name);
this.CreateFeature(feature);

FeatureFlagger.SetFeatures();
// TODO: cyclic dependency?
// FeatureFlagger.SetFeatures();
}

private void CreateFeature(Feature feature)
Expand Down Expand Up @@ -87,17 88,12 @@ private void DeleteFeature(string featureName)

private void ExecuteSql(string queryString)
{
// ToDo Code changes required to resolve the Veracode issue below...
//Avoid dynamically constructing SQL queries.Instead, use parameterized prepared statements to prevent the
// database from interpreting the contents of bind variables as part of the query.Always validate untrusted input to
// ensure that it conforms to the expected format, using centralized data validation routines when possible.
//
//using (var connection = new SqlConnection(this.connectionString))
//using (var command = new SqlCommand(queryString, connection))
//{
// connection.Open();
// command.ExecuteNonQuery();
//}
using (var connection = new SqlConnection(this.connectionString))
using (var command = new SqlCommand(queryString, connection))
{
connection.Open();
command.ExecuteNonQuery();
}
}
}
}
2 changes: 1 addition & 1 deletion src/FeatureFlagger/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,7 @@ namespace FeatureFlagger
{
public static class Constants
{
public const string Config = "CONFIG";
public const string Config = "CONFIG";
public const string Feature = "FEATURE";
}
}
2 changes: 1 addition & 1 deletion src/FeatureFlagger/FeatureFlagExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 30,7 @@ private static IEnumerable<Flag> GetFlags(IFeatureFlagger featureFlagger)
featureFlagger.GetType().Name
.Replace("FeatureFlagger", string.Empty);

var feature = FeatureFlagger.Reader.Read(featureName);
var feature = FeatureFlagger.Reader.Read(featureName, FeatureFlagger.Features);

// add the feature name to each flag as a property
// (as long as it's not been added already).
Expand Down
Loading

0 comments on commit 4aebf3c

Please sign in to comment.