Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
213
Issues
213
List
Boards
Labels
Service Desk
Milestones
Merge Requests
35
Merge Requests
35
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Security & Compliance
Security & Compliance
Dependency List
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Compare Revisions
79b26e405763f61f4c2038324d868b2df50b1ba4...9ecaa517a5a23a7b479cec2654ac59ae2880dc8d
Source
9ecaa517a5a23a7b479cec2654ac59ae2880dc8d
Select Git revision
...
Target
79b26e405763f61f4c2038324d868b2df50b1ba4
Select Git revision
Compare
Commits (3)
(wip): Setup routing engine when updating domain
· d4e1d52e
Emiliano Balbuena
authored
6 hours ago
d4e1d52e
(cs): Lint
· afdf7b0d
Emiliano Balbuena
authored
6 hours ago
afdf7b0d
(feat): Use DynamoDB as Edge Routing
· 9ecaa517
Emiliano Balbuena
authored
10 minutes ago
9ecaa517
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
193 additions
and
13 deletions
+193
-13
InitializeSettingsDelegate.php
Core/Pro/Delegates/InitializeSettingsDelegate.php
+10
-5
SetupRoutingDelegate.php
Core/Pro/Delegates/SetupRoutingDelegate.php
+52
-0
Domain.php
Core/Pro/Domain.php
+1
-1
EdgeRouterInterface.php
Core/Pro/Domain/EdgeRouters/EdgeRouterInterface.php
+15
-0
TraefikDynamoDb.php
Core/Pro/Domain/EdgeRouters/TraefikDynamoDb.php
+95
-0
Manager.php
Core/Pro/Manager.php
+15
-6
settings.example.php
settings.example.php
+5
-1
No files found.
Core/Pro/Delegates/InitializeSettingsDelegate.php
View file @
9ecaa517
...
...
@@ -16,14 +16,20 @@ class InitializeSettingsDelegate
/** @var Repository */
protected
$repository
;
/** @var SetupRoutingDelegate */
protected
$setupRoutingDelegate
;
/**
* InitializeSettingsDelegate constructor.
* @param Repository $repository
* @param SetupRoutingDelegate $setupRoutingDelegate
*/
public
function
__construct
(
$repository
=
null
$repository
=
null
,
$setupRoutingDelegate
=
null
)
{
$this
->
repository
=
$repository
?:
new
Repository
();
$this
->
setupRoutingDelegate
=
$setupRoutingDelegate
?:
new
SetupRoutingDelegate
();
}
/**
...
...
@@ -43,14 +49,13 @@ class InitializeSettingsDelegate
->
setUserGuid
(
$user
->
guid
);
}
if
(
!
$settings
->
getDomain
())
{
$settings
->
setDomain
(
"pro-
{
$user
->
guid
}
.minds.com"
);
}
if
(
!
$settings
->
getTitle
())
{
$settings
->
setTitle
(
$user
->
name
?:
$user
->
username
);
}
$this
->
setupRoutingDelegate
->
onUpdate
(
$settings
);
$this
->
repository
->
add
(
$settings
);
}
...
...
This diff is collapsed.
Click to expand it.
Core/Pro/Delegates/SetupRoutingDelegate.php
0 → 100644
View file @
9ecaa517
<?php
/**
* SetupRoutingDelegate
* @author edgebal
*/
namespace
Minds\Core\Pro\Delegates
;
use
Minds\Core\Config
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Pro\Domain\EdgeRouters\EdgeRouterInterface
;
use
Minds\Core\Pro\Domain\EdgeRouters\TraefikDynamoDb
;
use
Minds\Core\Pro\Settings
;
class
SetupRoutingDelegate
{
/** @var Config */
protected
$config
;
/** @var EdgeRouterInterface */
protected
$edgeRouter
;
/**
* SetupRoutingDelegate constructor.
* @param Config $config
* @param EdgeRouterInterface $edgeRouter
*/
public
function
__construct
(
$config
=
null
,
$edgeRouter
=
null
)
{
$this
->
config
=
$config
?:
Di
::
_
()
->
get
(
'Config'
);
$this
->
edgeRouter
=
$edgeRouter
?:
new
TraefikDynamoDb
();
}
public
function
onUpdate
(
Settings
$settings
)
{
$userGuid
=
$settings
->
getUserGuid
();
if
(
!
$settings
->
getDomain
())
{
$settings
->
setDomain
(
sprintf
(
"pro-%s.%s"
,
$userGuid
,
$this
->
config
->
get
(
'pro'
)[
'subdomain_prefix'
]
??
'minds.com'
));
}
$success
=
$this
->
edgeRouter
->
initialize
()
->
putEndpoint
(
$settings
);
if
(
!
$success
)
{
// TODO: Issue a warning based on $success
}
}
}
This diff is collapsed.
Click to expand it.
Core/Pro/Domain.php
View file @
9ecaa517
...
...
@@ -38,7 +38,7 @@ class Domain
*/
public
function
lookup
(
string
$domain
)
{
$rootDomains
=
$this
->
config
->
get
(
'
root_domains'
)
?:
[];
$rootDomains
=
$this
->
config
->
get
(
'
pro'
)[
'root_domains'
]
??
[];
if
(
in_array
(
strtolower
(
$domain
),
$rootDomains
,
true
))
{
return
null
;
...
...
This diff is collapsed.
Click to expand it.
Core/Pro/Domain/EdgeRouters/EdgeRouterInterface.php
0 → 100644
View file @
9ecaa517
<?php
/**
* EdgeRouterInterface
* @author edgebal
*/
namespace
Minds\Core\Pro\Domain\EdgeRouters
;
use
Minds\Core\Pro\Settings
;
interface
EdgeRouterInterface
{
public
function
initialize
()
:
EdgeRouterInterface
;
public
function
putEndpoint
(
Settings
$settings
)
:
bool
;
}
This diff is collapsed.
Click to expand it.
Core/Pro/Domain/EdgeRouters/TraefikDynamoDb.php
0 → 100644
View file @
9ecaa517
<?php
/**
* TraefikDynamoDb
* @author edgebal
*/
namespace
Minds\Core\Pro\Domain\EdgeRouters
;
use
Aws\DynamoDb\DynamoDbClient
;
use
Aws\DynamoDb\Exception\DynamoDbException
;
use
Aws\DynamoDb\Marshaler
;
use
Minds\Core\Config
;
use
Minds\Core\Di\Di
;
use
Minds\Core\Pro\Settings
;
class
TraefikDynamoDb
implements
EdgeRouterInterface
{
/** @var Config */
protected
$config
;
/** @var DynamoDbClient */
protected
$dynamoDb
;
/**
* TraefikDynamoDb constructor.
* @param Config $config
*/
public
function
__construct
(
$config
=
null
)
{
$this
->
config
=
$config
?:
Di
::
_
()
->
get
(
'Config'
);
}
public
function
initialize
()
:
EdgeRouterInterface
{
$awsConfig
=
$this
->
config
->
get
(
'aws'
);
$opts
=
[
'region'
=>
$awsConfig
[
'region'
]
];
if
(
!
isset
(
$awsConfig
[
'useRoles'
])
||
!
$awsConfig
[
'useRoles'
])
{
$opts
[
'credentials'
]
=
[
'key'
=>
$awsConfig
[
'key'
],
'secret'
=>
$awsConfig
[
'secret'
],
];
}
if
(
isset
(
$awsConfig
[
'dynamoDbEndpoint'
]))
{
$opts
[
'endpoint'
]
=
$awsConfig
[
'dynamoDbEndpoint'
];
}
$this
->
dynamoDb
=
new
DynamoDbClient
(
array_merge
([
'version'
=>
'2012-08-10'
,
],
$opts
));
return
$this
;
}
public
function
putEndpoint
(
Settings
$settings
)
:
bool
{
$domain
=
$settings
->
getDomain
();
if
(
!
$domain
)
{
return
false
;
}
$userGuid
=
$settings
->
getUserGuid
();
$marshaler
=
new
Marshaler
();
$entry
=
$marshaler
->
marshalJson
(
json_encode
([
'id'
=>
"minds-pro-frontend-
{
$userGuid
}
"
,
'name'
=>
"minds-pro-
{
$userGuid
}
"
,
'frontend'
=>
[
'backend'
=>
'minds-pro'
,
'routes'
=>
[
'pro'
=>
[
'rule'
=>
"Host:
{
$domain
}
"
]
]
]
]));
try
{
$this
->
dynamoDb
->
putItem
([
'TableName'
=>
$this
->
config
->
get
(
'pro'
)[
'dynamodb_table_name'
],
'Item'
=>
$entry
,
]);
return
true
;
}
catch
(
DynamoDbException
$e
)
{
error_log
(
$e
);
return
false
;
}
}
}
This diff is collapsed.
Click to expand it.
Core/Pro/Manager.php
View file @
9ecaa517
...
...
@@ -21,41 +21,47 @@ class Manager
/** @var Save */
protected
$saveAction
;
/** @var EntitiesBuilder */
protected
$entitiesBuilder
;
/** @var Delegates\InitializeSettingsDelegate */
protected
$initializeSettingsDelegate
;
/** @var Delegates\HydrateSettingsDelegate */
protected
$hydrateSettingsDelegate
;
/** @var Delegates\SetupRoutingDelegate */
protected
$setupRoutingDelegate
;
/** @var User */
protected
$user
;
/** @var User */
protected
$actor
;
/** @var EntitiesBuilder */
protected
$entitiesBuilder
;
/**
* Manager constructor.
* @param Repository $repository
* @param Save $saveAction
* @param EntitiesBuilder $entitiesBuilder
* @param Delegates\InitializeSettingsDelegate $initializeSettingsDelegate
* @param Delegates\HydrateSettingsDelegate $hydrateSettingsDelegate
* @param
EntitiesBuilder $entitiesBuilder
* @param
Delegates\SetupRoutingDelegate $setupRoutingDelegate
*/
public
function
__construct
(
$repository
=
null
,
$saveAction
=
null
,
$entitiesBuilder
=
null
,
$initializeSettingsDelegate
=
null
,
$hydrateSettingsDelegate
=
null
,
$
entitiesBuilder
=
null
$
setupRoutingDelegate
=
null
)
{
$this
->
repository
=
$repository
?:
new
Repository
();
$this
->
saveAction
=
$saveAction
?:
new
Save
();
$this
->
entitiesBuilder
=
$entitiesBuilder
?:
Di
::
_
()
->
get
(
'EntitiesBuilder'
);
$this
->
initializeSettingsDelegate
=
$initializeSettingsDelegate
?:
new
Delegates\InitializeSettingsDelegate
();
$this
->
hydrateSettingsDelegate
=
$hydrateSettingsDelegate
?:
new
Delegates\HydrateSettingsDelegate
();
$this
->
entitiesBuilder
=
$entitiesBuilder
?:
Di
::
_
()
->
get
(
'EntitiesBuilder'
);
$this
->
setupRoutingDelegate
=
$setupRoutingDelegate
?:
new
Delegates\SetupRoutingDelegate
(
);
}
/**
...
...
@@ -316,6 +322,9 @@ class Manager
->
setCustomHead
(
$values
[
'custom_head'
]);
}
$this
->
setupRoutingDelegate
->
onUpdate
(
$settings
);
return
$this
->
repository
->
update
(
$settings
);
}
}
This diff is collapsed.
Click to expand it.
settings.example.php
View file @
9ecaa517
...
...
@@ -574,4 +574,8 @@ $CONFIG->set('gitlab', [
'private_key'
=>
''
]);
$CONFIG
->
set
(
'root_domains'
,
[
'minds.com'
,
'www.minds.com'
,
'localhost'
]);
$CONFIG
->
set
(
'pro'
,
[
'root_domains'
=>
[
'minds.com'
,
'www.minds.com'
,
'localhost'
],
'subdomain_prefix'
=>
'minds.com'
,
'dynamodb_table_name'
=>
'traefik'
,
]);
This diff is collapsed.
Click to expand it.