Skip to content

Commit 2bf16fa

Browse files
committed
v0.13.0
1 parent 81c5df5 commit 2bf16fa

File tree

284 files changed

+11402
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+11402
-0
lines changed

.circleci/config.json.testing

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"database": {
3+
"host": "localhost",
4+
"name": "openhub_api_test",
5+
"user": "postgres",
6+
"port": 5432,
7+
"password": ""
8+
},
9+
"auth": {
10+
"encryption_key": "FDj1j322fDFJ2ivbrajhw",
11+
"jwt": {
12+
"secret_key": "GQDsD21j8s2zdm12F1f1k12",
13+
"token_life_days": 7
14+
}
15+
},
16+
"Logging": {
17+
"LogLevel": {
18+
"Default": "Debug",
19+
"System": "Information",
20+
"Microsoft": "Information"
21+
}
22+
}
23+
}

.circleci/config.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
version: 2
2+
jobs:
3+
build:
4+
working_directory: ~/repo
5+
docker:
6+
- image: centos:7
7+
8+
steps:
9+
- checkout
10+
11+
- run:
12+
name: ls
13+
command: ls
14+
15+
- run:
16+
name: install git & postgres & sudo
17+
command: yum install -y git postgresql postgresql-server sudo
18+
19+
- run:
20+
name: Install initscripts to be able to work with services
21+
command: yum install -y initscripts && yum clean all
22+
23+
- run:
24+
name: Add .net core repo
25+
command: rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
26+
27+
- run:
28+
name: yum update
29+
command: yum update -y
30+
31+
- run:
32+
name: install php deps
33+
command: yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm && yum -y install epel-release yum-utils && yum-config-manager --disable remi-php54 && yum-config-manager --enable remi-php73
34+
35+
- run:
36+
name: install php
37+
command: yum -y install php php-cli php-zip wget unzip php-pgsql
38+
39+
- run:
40+
name: php version
41+
command: php -v
42+
43+
- run:
44+
name: install composer
45+
command: curl -sS https://getcomposer.org/installer -o composer-setup.php && php composer-setup.php --install-dir=/usr/local/bin --filename=composer
46+
47+
- run:
48+
name: composer version
49+
command: composer --version
50+
51+
- run:
52+
name: copy phinx config
53+
command: cp .circleci/phinx.yml.testing migrations/phinx.yml
54+
55+
- run:
56+
name: set up postgres
57+
command: sudo -u postgres /usr/bin/initdb /var/lib/pgsql/data/ && sudo -u postgres /usr/bin/pg_ctl start -D /var/lib/pgsql/data -s -o "-p 5432" -w -t 300
58+
59+
- run:
60+
name: create database
61+
command: sudo -u postgres psql -c 'create database openhub_api_test;'
62+
63+
- run:
64+
name: composer install & migrate
65+
command: (cd migrations && composer install) && (cd migrations && php vendor/bin/phinx migrate -e testing)
66+
67+
- run:
68+
name: copy app config
69+
command: mkdir -p Tests/bin/Debug/netcoreapp2.2/config && cp .circleci/config.json.testing Tests/bin/Debug/netcoreapp2.2/config/config.json
70+
71+
- run:
72+
name: yum install dotnet core sdk 2.2
73+
command: yum install -y dotnet-sdk-2.2
74+
75+
- run:
76+
name: build
77+
command: dotnet build
78+
79+
- run:
80+
name: run tests
81+
command: dotnet test

.circleci/phinx.yml.testing

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
paths:
2+
migrations: '%%PHINX_CONFIG_DIR%%/db/migrations'
3+
seeds: '%%PHINX_CONFIG_DIR%%/db/seeds'
4+
5+
environments:
6+
default_migration_table: phinxlog
7+
default_database: testing
8+
testing:
9+
adapter: pgsql
10+
host: localhost
11+
name: openhub_api_test
12+
user: postgres
13+
pass: ''
14+
port: 5432
15+
charset: utf8
16+
17+
version_order: creation

App/AL/AppBoot.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using App.DL.Module.Cache;
3+
4+
namespace App.AL {
5+
public static class AppBoot {
6+
public static void Boot() {
7+
Console.WriteLine("Booting...");
8+
9+
ModelCache.StartAutoResetTask();
10+
11+
Console.WriteLine("Boot finished.");
12+
}
13+
}
14+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using App.AL.Utils.Funding;
4+
using App.DL.Enum;
5+
using App.DL.Model.Funding;
6+
using App.DL.Repository.User;
7+
using App.PL.Transformer.Funding;
8+
using App.PL.Transformer.User;
9+
using Micron.AL.Config.CLI;
10+
using Micron.DL.Module.CLI;
11+
using Newtonsoft.Json.Linq;
12+
13+
namespace App.AL.CLI.Finding {
14+
public class ApproveInvoice : BaseCommand, ICliCommand {
15+
public override string Signature { get; } = "approve-invoice";
16+
17+
public ApproveInvoice() {
18+
StrOutput = new List<string>();
19+
}
20+
21+
public CliResult Execute() {
22+
Output("Approving invoice");
23+
Output("Type invoice id:");
24+
25+
var id = Convert.ToInt32(Console.ReadLine());
26+
var invoice = Invoice.Find(id);
27+
if (invoice == null) {
28+
Output($"Invoice with id {id} not found");
29+
return new CliResult(CliExitCode.NotFound, StrOutput);
30+
}
31+
32+
Output("Invoice:");
33+
Output(JObject.FromObject(invoice).ToString());
34+
Output("Transformed invoice:");
35+
Output(new InvoiceTransformer().Transform(invoice).ToString());
36+
Output("Invoice user:");
37+
Output(JObject.FromObject(invoice.User()).ToString());
38+
39+
if (invoice.status != InvoiceStatus.RequiresConfirmation) {
40+
Output("Invoice has invalid status - allowed only: " + InvoiceStatus.RequiresConfirmation);
41+
return new CliResult(CliExitCode.UnknownError, StrOutput);
42+
}
43+
44+
var isApproving = Ask("Approve that invoice?");
45+
46+
if (!isApproving) {
47+
Output("Aborted.");
48+
return new CliResult(CliExitCode.Ok, StrOutput);
49+
}
50+
51+
Output("Approving invoice...");
52+
53+
invoice = InvoiceUtils.ConfirmInvoice(invoice);
54+
55+
var isProcessing = Ask("Process confirmed invoice?");
56+
57+
if (!isProcessing) {
58+
return new CliResult(CliExitCode.Ok, StrOutput);
59+
}
60+
61+
var balance = UserBalanceRepository.Find(invoice.User());
62+
63+
Output("Balance before:");
64+
Output(new UserBalanceTransformer().Transform(balance).ToString());
65+
66+
Output("Processing invoice...");
67+
invoice = InvoiceUtils.ProcessConfirmedInvoice(invoice);
68+
Output("Invoice processing finished...");
69+
70+
Output("Balance after:");
71+
Output(new UserBalanceTransformer().Transform(balance.Refresh()).ToString());
72+
73+
Output("Transformed invoice:");
74+
Output(new InvoiceTransformer().Transform(invoice).ToString());
75+
76+
return new CliResult(CliExitCode.Ok, StrOutput);
77+
}
78+
}
79+
}

App/AL/Config/CLI/CommandsList.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using App.AL.CLI.Finding;
2+
using Micron.AL.CLI.Basic;
3+
using Micron.DL.Module.CLI;
4+
5+
namespace App.AL.Config.CLI {
6+
public static class CommandsList {
7+
public static ICliCommand[] Get()
8+
=> new ICliCommand[] {
9+
new PrintFrameworkVersion(),
10+
new ApproveInvoice()
11+
};
12+
}
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace App.AL.Config.Funding {
2+
public static class InvoiceConfig {
3+
public const int UserActiveInvoicesLimit = 10;
4+
}
5+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Collections.Generic;
2+
3+
namespace App.AL.Config.UserSetting {
4+
public static class AllowedValues {
5+
// equal null means that all values are allowed
6+
public static Dictionary<string, string[]> GetAllowed()
7+
=> new Dictionary<string, string[]> {
8+
["subscription_currency"] = new[] {
9+
"Usd", "BitCoin", "Ethereum", "Erc20Token", "Waves", "WavesToken", "LiteCoin"
10+
},
11+
["subscription_amount"] = null
12+
};
13+
}
14+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using App.DL.Repository.Alias;
2+
using App.PL.Transformer.Project;
3+
using Micron.AL.Validation.Basic;
4+
using Micron.DL.Middleware;
5+
using Micron.DL.Module.Controller;
6+
using Micron.DL.Module.Http;
7+
using Micron.DL.Module.Validator;
8+
using Nancy;
9+
10+
namespace App.AL.Controller.Alias.Project {
11+
public class ProjectAliasController : BaseController {
12+
protected override IMiddleware[] Middleware() => new IMiddleware[] { };
13+
14+
public ProjectAliasController() {
15+
Get("/api/v1/alias/project/get", _ => {
16+
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
17+
new ShouldHaveParameters(new[] {"owner", "alias"})
18+
});
19+
if (errors.Count > 0) {
20+
return HttpResponse.Errors(errors);
21+
}
22+
23+
var alias = ProjectAliasRepository.FindByAlias(
24+
GetRequestStr("owner"), GetRequestStr("alias")
25+
);
26+
27+
if (alias == null) {
28+
return HttpResponse.Error(HttpStatusCode.NotFound, "Project not found");
29+
}
30+
31+
return HttpResponse.Item("project", new ProjectTransformer().Transform(alias.Project()));
32+
});
33+
}
34+
}
35+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System.Net.Http;
2+
using App.DL.Enum;
3+
using App.DL.Repository.Auth;
4+
using App.DL.Repository.User;
5+
using Micron.AL.Validation.Basic;
6+
using Micron.DL.Middleware;
7+
using Micron.DL.Module.Auth;
8+
using Micron.DL.Module.Controller;
9+
using Micron.DL.Module.Http;
10+
using Micron.DL.Module.Validator;
11+
using Nancy;
12+
using Newtonsoft.Json.Linq;
13+
14+
namespace App.AL.Controller.Auth.External.Facebook {
15+
public class FacebookAuthController : BaseController {
16+
private const string ApiUrl = "https://graph.facebook.com/v2.3/";
17+
18+
protected override IMiddleware[] Middleware() => new IMiddleware[] { };
19+
20+
public FacebookAuthController() {
21+
Get("/api/v1/auth/facebook/my_token/get", _ => {
22+
var errors = ValidationProcessor.Process(Request, new IValidatorRule[] {
23+
new ShouldHaveParameters(new[] {"facebook_token"}),
24+
});
25+
if (errors.Count > 0) {
26+
return HttpResponse.Errors(errors);
27+
}
28+
29+
var facebookToken = GetRequestStr("facebook_token");
30+
31+
var response = new HttpClient().GetAsync(
32+
ApiUrl + $"me?access_token={facebookToken}&fields=name,email"
33+
).Result;
34+
if (!response.IsSuccessStatusCode) {
35+
return HttpResponse.Error(HttpStatusCode.BadRequest, "Invalid facebook token");
36+
}
37+
var json = JObject.Parse(response.Content.ReadAsStringAsync().Result);
38+
39+
var email = json.Value<string>("email");
40+
var login = email.Split("@")[0];
41+
42+
var user = UserRepository.FindByEmail(email) ?? UserRepository.FindOrCreateByEmailAndLogin(email, login);
43+
44+
var accessToken = ServiceAccessTokenRepository.FindOrUpdateAccessToken(user, facebookToken, ServiceType.Facebook);
45+
accessToken.UpdateCol("origin_user_id", json.Value<string>("id"));
46+
47+
return HttpResponse.Data(new JObject() {
48+
["token"] = Jwt.FromUserId(user.id)
49+
});
50+
});
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)