Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F5525955
InstancesBootstrapWorkflow.php
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
amckinley
Apr 17 2018, 8:56 PM
2018-04-17 20:56:23 (UTC+0)
Size
4 KB
Referenced Files
None
Subscribers
None
InstancesBootstrapWorkflow.php
View Options
<?php
final
class
InstancesBootstrapWorkflow
extends
InstancesWorkflow
{
protected
function
didConstruct
()
{
$this
->
setName
(
'bootstrap'
)
->
setSynopsis
(
pht
(
'Bootstrap Phacility instances application.'
))
->
setArguments
(
array
(
array
(
'name'
=>
'user'
,
'param'
=>
'user'
,
'help'
=>
pht
(
'User to give cluster management permissions to.'
),
),
));
}
public
function
execute
(
PhutilArgumentParser
$args
)
{
// Grant user "Can Manage Cluster Devices"
$this
->
updateManageClusterDevicesPolicy
(
$args
->
getArg
(
'user'
));
// Create network
$network
=
id
(
new
AlmanacNetworkQuery
())
->
setViewer
(
PhabricatorUser
::
getOmnipotentUser
())
->
withNames
(
array
(
'Internet'
))
->
execute
();
if
(!
$network
)
{
$network
=
id
(
AlmanacNetwork
::
initializeNewNetwork
())
->
setName
(
'Internet'
);
$network
->
save
();
}
else
{
$network
=
head
(
$network
);
}
// Create localhost device with interfaces for ssh and mysql
$device
=
id
(
new
AlmanacDeviceQuery
())
->
setViewer
(
PhabricatorUser
::
getOmnipotentUser
())
->
withNames
(
array
(
'localhost'
))
->
execute
();
if
(!
$device
)
{
$device
=
id
(
AlmanacDevice
::
initializeNewDevice
())
->
setName
(
'localhost'
)
->
setIsBoundToClusterService
(
true
);
$device
->
save
();
$ssh_interface
=
id
(
AlmanacInterface
::
initializeNewInterface
())
->
attachNetwork
(
$network
)
->
setNetworkPHID
(
$network
->
getPHID
())
->
attachDevice
(
$device
)
->
setDevicePHID
(
$device
->
getPHID
())
->
setAddress
(
'127.0.0.1'
)
->
setPort
(
'22'
);
$ssh_interface
->
save
();
$sql_interface
=
id
(
AlmanacInterface
::
initializeNewInterface
())
->
attachNetwork
(
$network
)
->
setNetworkPHID
(
$network
->
getPHID
())
->
attachDevice
(
$device
)
->
setDevicePHID
(
$device
->
getPHID
())
->
setAddress
(
'127.0.0.1'
)
->
setPort
(
'3306'
);
$sql_interface
->
save
();
}
else
{
$device
=
head
(
$device
);
}
// create services.phacility.net service
// create db.phacility.net service with "instances.open" = true
// create repo.phacility.net service with "instances.open" = true
// setup bindings
// create Phortune merchant account named "Phacility"
}
private
function
updateManageClusterDevicesPolicy
(
$user_name
)
{
$user
=
id
(
new
PhabricatorPeopleQuery
())
->
setViewer
(
PhabricatorUser
::
getOmnipotentUser
())
->
withUsernames
(
array
(
$user_name
))
->
needUserSettings
(
true
)
->
executeOne
();
if
(!
$user
)
{
throw
new
Exception
(
pht
(
'Invalid username ("%s"). There is no user with this username.'
,
$user_name
));
}
$application
=
id
(
new
PhabricatorApplicationQuery
())
->
setViewer
(
$user
)
->
withClasses
(
array
(
'PhabricatorAlmanacApplication'
))
->
requireCapabilities
(
array
(
PhabricatorPolicyCapability
::
CAN_VIEW
,
PhabricatorPolicyCapability
::
CAN_EDIT
,
))
->
executeOne
();
if
(!
$application
)
{
throw
new
Exception
(
pht
(
'Almanac application is not installed.'
));
}
$policies
=
id
(
new
PhabricatorPolicyQuery
())
->
setViewer
(
$user
)
->
setObject
(
$application
)
->
execute
();
$xactions
=
array
();
$template
=
$application
->
getApplicationTransactionTemplate
();
foreach
(
$application
->
getCapabilities
()
as
$capability
)
{
if
(
$capability
!==
'almanac.cluster'
)
{
continue
;
}
$old
=
$application
->
getPolicy
(
$capability
);
$new
=
$user
->
getPHID
();
if
(
$old
==
$new
)
{
// No change to the setting.
return
;
}
$xactions
[]
=
id
(
clone
$template
)
->
setTransactionType
(
PhabricatorApplicationPolicyChangeTransaction
::
TRANSACTIONTYPE
)
->
setMetadataValue
(
PhabricatorApplicationPolicyChangeTransaction
::
METADATA_ATTRIBUTE
,
$capability
)
->
setNewValue
(
$new
);
$editor
=
id
(
new
PhabricatorApplicationEditor
())
->
setActor
(
$user
)
->
setContentSource
(
PhabricatorContentSource
::
newForSource
(
PhabricatorDaemonContentSource
::
SOURCECONST
))
->
setContinueOnNoEffect
(
true
)
->
setContinueOnMissingFields
(
true
);
$editor
->
applyTransactions
(
$application
,
$xactions
);
return
;
}
}
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
1005302
Default Alt Text
InstancesBootstrapWorkflow.php (4 KB)
Attached To
Mode
P2096 InstancesBootstrapWorkflow.php
Attached
Detach File
Event Timeline
Log In to Comment