Skip to content

Commit

Permalink
Feature/call registration service (microsoft#4)
Browse files Browse the repository at this point in the history
* Fixed error on lost using.

* Added flag for bypassing the registration users service.

* Call to Registration WCF Service from WebBFF API, passing the service address in configuration.

* Same for MobileBFF.

* Service port.

* Added option to select the tag for wcf image.

* The changes...

* Changes suggested in PR.

* Deleted unnecessary variable.
  • Loading branch information
ivilches authored Jul 4, 2019
1 parent 1983bc9 commit 35242ed
Show file tree
Hide file tree
Showing 35 changed files with 543 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ ASALocalRun/
Deploy/helm/__values/*
!Deploy/helm/__values/readme.txt

Source\Services\Tailwind.Traders.Rewards.Registration.Api\Properties\PublishProfiles\*.pubxml
Source/Services/Tailwind.Traders.Cart.Api/.env

/Source/.env
Expand Down
13 changes: 13 additions & 0 deletions Deploy/helm/gvalues.template
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ inf:
stockapiurl: http://stock
imageclassifierapiurl: http://imageclassifier
loginapiurl: http://login
registrationusers:
registerusers: "false"
registrationusersurl: "TODO DEMI"
az:
productvisitsurl: ""

Expand All @@ -97,6 +100,16 @@ sec:
issuer: {{secissuer}}
securityKey: {{seckey}}

B2C:
UseB2C: "false"
B2CIssuer: ""
Authority: ""
tenantID: ""
clientID: ""
policyName: ""
identityMetadata: ""
issuer: ""

# Autoscaling global settings
hpa:
activated: false # set to true to deploy HPA for services
Expand Down
3 changes: 3 additions & 0 deletions Deploy/helm/gvalues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ inf:
stockapiurl: http://stock
imageclassifierapiurl: http://imageclassifier
loginapiurl: http://login
registrationusers:
registerusers: "false"
registrationusersurl: "TODO DEMI"
az:
productvisitsurl: ""

Expand Down
14 changes: 14 additions & 0 deletions Deploy/helm/gvalues_inf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ inf:
stockapiurl: http://stock
imageclassifierapiurl: http://imageclassifier
loginapiurl: http://login
registrationusers:
registerusers: "false"
registrationusersurl: "TODO DEMI"
az:
productvisitsurl: ""

Expand All @@ -100,6 +103,17 @@ ingress:
sec:
issuer: TTFakeLogin
securityKey: nEpLzQJGNSCNL5H6DIQCtTdNxf5VgAGcBbtXLms1YDD01KJBAs0WVawaEjn97uwB

B2C:
UseB2C: "false"
B2CIssuer: ""
Authority: ""
tenantID: ""
clientID: ""
policyName: ""
identityMetadata: ""
issuer: ""

# Autoscaling global settings
hpa:
activated: false # set to true to deploy HPA for services
Expand Down
13 changes: 13 additions & 0 deletions Deploy/helm/gvalues_inf_azds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ inf:
stockapiurl: http://stock
imageclassifierapiurl: http://imageclassifier
loginapiurl: http://login
registrationusers:
registerusers: "false"
registrationusersurl: "TODO DEMI: WCF SERVICE URL"
az:
productvisitsurl: ""

Expand All @@ -97,6 +100,16 @@ sec:
issuer: TTFakeLogin
securityKey: nEpLzQJGNSCNL5H6DIQCtTdNxf5VgAGcBbtXLms1YDD01KJBAs0WVawaEjn97uwB

B2C:
UseB2C: "false"
B2CIssuer: ""
Authority: ""
tenantID: ""
clientID: ""
policyName: ""
identityMetadata: ""
issuer: ""

# Autoscaling global settings
hpa:
activated: false # set to true to deploy HPA for services
Expand Down
2 changes: 2 additions & 0 deletions Deploy/helm/mobilebff/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ data:
ISSUER: {{ .Values.sec.issuer }}
SECURITYKEY: {{ .Values.sec.securityKey }}
LoginApiUrl: {{ .Values.inf.apiurls.loginapiurl }}
RegisterUsers: {{ .Values.inf.registrationusers.registerusers | quote }}
RegistrationUsersEndpoint: {{ .Values.inf.registrationusers.registrationusersurl }}

2 changes: 2 additions & 0 deletions Deploy/helm/mobilebff/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ env:
- name: ISSUER
- name: SECURITYKEY
- name: LoginApiUrl
- name: RegisterUsers
- name: RegistrationUsersEndpoint
values:
- name: ASPNETCORE_ENVIRONMENT
value: Development
3 changes: 2 additions & 1 deletion Deploy/helm/webbff/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ data:
UseB2C: {{ .Values.B2C.UseB2C | quote }}
B2CIssuer: {{ .Values.B2C.B2CIssuer }}
Authority: {{ .Values.B2C.Authority }}

RegisterUsers: {{ .Values.inf.registrationusers.registerusers | quote }}
RegistrationUsersEndpoint: {{ .Values.inf.registrationusers.registrationusersurl }}

2 changes: 2 additions & 0 deletions Deploy/helm/webbff/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ env:
- name: UseB2C
- name: B2CIssuer
- name: Authority
- name: RegisterUsers
- name: RegistrationUsersEndpoint
values:
- name: ASPNETCORE_ENVIRONMENT
value: Development
Expand Down
9 changes: 3 additions & 6 deletions Source/ApiGWs/Tailwind.Traders.Bff/AppSettings.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Tailwind.Traders.MobileBff
namespace Tailwind.Traders.MobileBff
{
public class AppSettings
{
Expand All @@ -14,5 +9,7 @@ public class AppSettings
public string LoginApiUrl { get; set; }
public string ImageClassifierApiUrl { get; set; }
public bool UseMlNetClassifier { get; set; }
public bool RegisterUsers { get; set; }
public string RegistrationUsersEndpoint { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"ProviderId": "Microsoft.VisualStudio.ConnectedService.Wcf",
"Version": "15.0.20628.921",
"ExtendedData": {
"Uri": "http://localhost:51402/UserService.svc",
"Namespace": "RegistrationUserService",
"SelectedAccessLevelForGeneratedClass": "Public",
"GenerateMessageContract": false,
"ReuseTypesinReferencedAssemblies": true,
"ReuseTypesinAllReferencedAssemblies": true,
"CollectionTypeReference": {
"Item1": "System.Array",
"Item2": "System.Runtime.dll"
},
"DictionaryCollectionTypeReference": {
"Item1": "System.Collections.Generic.Dictionary`2",
"Item2": "System.Collections.dll"
},
"CheckedReferencedAssemblies": [],
"InstanceId": null,
"Name": "RegistrationUserService",
"Metadata": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// //
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace RegistrationUserService
{


[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.1")]
[System.ServiceModel.ServiceContractAttribute(ConfigurationName="RegistrationUserService.IUserService")]
public interface IUserService
{

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IUserService/Registration", ReplyAction="http://tempuri.org/IUserService/RegistrationResponse")]
System.Threading.Tasks.Task<bool> RegistrationAsync(string email);
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.1")]
public interface IUserServiceChannel : RegistrationUserService.IUserService, System.ServiceModel.IClientChannel
{
}

[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil", "1.0.0.1")]
public partial class UserServiceClient : System.ServiceModel.ClientBase<RegistrationUserService.IUserService>, RegistrationUserService.IUserService
{

/// <summary>
/// Implement this partial method to configure the service endpoint.
/// </summary>
/// <param name="serviceEndpoint">The endpoint to configure</param>
/// <param name="clientCredentials">The client credentials</param>
static partial void ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint serviceEndpoint, System.ServiceModel.Description.ClientCredentials clientCredentials);

public UserServiceClient() :
base(UserServiceClient.GetDefaultBinding(), UserServiceClient.GetDefaultEndpointAddress())
{
this.Endpoint.Name = EndpointConfiguration.BasicHttpBinding_IUserService.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}

public UserServiceClient(EndpointConfiguration endpointConfiguration) :
base(UserServiceClient.GetBindingForEndpoint(endpointConfiguration), UserServiceClient.GetEndpointAddress(endpointConfiguration))
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}

public UserServiceClient(EndpointConfiguration endpointConfiguration, string remoteAddress) :
base(UserServiceClient.GetBindingForEndpoint(endpointConfiguration), new System.ServiceModel.EndpointAddress(remoteAddress))
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}

public UserServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
base(UserServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
{
this.Endpoint.Name = endpointConfiguration.ToString();
ConfigureEndpoint(this.Endpoint, this.ClientCredentials);
}

public UserServiceClient(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress)
{
}

public System.Threading.Tasks.Task<bool> RegistrationAsync(string email)
{
return base.Channel.RegistrationAsync(email);
}

public virtual System.Threading.Tasks.Task OpenAsync()
{
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndOpen));
}

public virtual System.Threading.Tasks.Task CloseAsync()
{
return System.Threading.Tasks.Task.Factory.FromAsync(((System.ServiceModel.ICommunicationObject)(this)).BeginClose(null, null), new System.Action<System.IAsyncResult>(((System.ServiceModel.ICommunicationObject)(this)).EndClose));
}

private static System.ServiceModel.Channels.Binding GetBindingForEndpoint(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_IUserService))
{
System.ServiceModel.BasicHttpBinding result = new System.ServiceModel.BasicHttpBinding();
result.MaxBufferSize = int.MaxValue;
result.ReaderQuotas = System.Xml.XmlDictionaryReaderQuotas.Max;
result.MaxReceivedMessageSize = int.MaxValue;
result.AllowCookies = true;
return result;
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}

private static System.ServiceModel.EndpointAddress GetEndpointAddress(EndpointConfiguration endpointConfiguration)
{
if ((endpointConfiguration == EndpointConfiguration.BasicHttpBinding_IUserService))
{
return new System.ServiceModel.EndpointAddress("http://localhost:51402/UserService.svc");
}
throw new System.InvalidOperationException(string.Format("Could not find endpoint with name \'{0}\'.", endpointConfiguration));
}

private static System.ServiceModel.Channels.Binding GetDefaultBinding()
{
return UserServiceClient.GetBindingForEndpoint(EndpointConfiguration.BasicHttpBinding_IUserService);
}

private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress()
{
return UserServiceClient.GetEndpointAddress(EndpointConfiguration.BasicHttpBinding_IUserService);
}

public enum EndpointConfiguration
{

BasicHttpBinding_IUserService,
}
}
}
14 changes: 12 additions & 2 deletions Source/ApiGWs/Tailwind.Traders.Bff/Controllers/LoginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Tailwind.Traders.MobileBff.Infrastructure;
using Tailwind.Traders.MobileBff.Models;
using Tailwind.Traders.MobileBff.Services;

namespace Tailwind.Traders.MobileBff.Controllers
{
Expand All @@ -19,15 +20,18 @@ namespace Tailwind.Traders.MobileBff.Controllers
public class LoginController : Controller
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly IRegisterService _registerService;
private readonly AppSettings _settings;
private const string VERSION_API = "v1";

public LoginController(
IHttpClientFactory httpClientFactory,
IOptions<AppSettings> options)
IOptions<AppSettings> options,
IRegisterService registerService)
{
_httpClientFactory = httpClientFactory;
_settings = options.Value;
_registerService = registerService;
}

// POST: v1/login
Expand All @@ -41,10 +45,16 @@ public async Task<IActionResult> Login([FromBody] TokenRequest request)

var response = await client.PostAsync(API.Login.PostLogin(_settings.LoginApiUrl, VERSION_API), stringContent);

if (response.StatusCode == HttpStatusCode.BadRequest) {
if (response.StatusCode == HttpStatusCode.BadRequest)
{
return BadRequest();
}

if (_settings.RegisterUsers)
{
await _registerService.RegisterUserIfNotExists(request.Username);
}

var result = await response.Content.ReadAsStringAsync();
var authResponse = JsonConvert.DeserializeObject<AuthResponse>(result);
return Ok(authResponse);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;

namespace Tailwind.Traders.MobileBff.Services
{
public interface IRegisterService
{
Task<bool> RegisterUserIfNotExists(string email);
}
}
20 changes: 20 additions & 0 deletions Source/ApiGWs/Tailwind.Traders.Bff/Services/RegisterService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using RegistrationUserService;
using System.Threading.Tasks;

namespace Tailwind.Traders.MobileBff.Services
{
public class RegisterService : IRegisterService
{
private readonly IUserService _client;

public RegisterService(IUserService client)
{
_client = client;
}

public async Task<bool> RegisterUserIfNotExists(string email)
{
return await _client.RegistrationAsync(email);
}
}
}
Loading

0 comments on commit 35242ed

Please sign in to comment.