Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2890697
DiffusionSSHWorkflow.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
2 KB
Referenced Files
None
Subscribers
None
DiffusionSSHWorkflow.php
View Options
<?php
abstract
class
DiffusionSSHWorkflow
extends
PhabricatorSSHWorkflow
{
private
$args
;
public
function
getArgs
(
)
{
return
$this
->
args
;
}
abstract
protected
function
isReadOnly
(
)
;
abstract
protected
function
getRequestPath
(
)
;
abstract
protected
function
executeRepositoryOperations
(
PhabricatorRepository
$repository
)
;
protected
function
writeError
(
$message
)
{
$this
->
getErrorChannel
(
)
->
write
(
$message
)
;
return
$this
;
}
final
public
function
execute
(
PhutilArgumentParser
$args
)
{
$this
->
args
=
$args
;
try
{
$repository
=
$this
->
loadRepository
(
)
;
return
$this
->
executeRepositoryOperations
(
$repository
)
;
}
catch
(
Exception
$ex
)
{
$this
->
writeError
(
get_class
(
$ex
)
.
': '
.
$ex
->
getMessage
(
)
)
;
return
1
;
}
}
private
function
loadRepository
(
)
{
$viewer
=
$this
->
getUser
(
)
;
$path
=
$this
->
getRequestPath
(
)
;
$regex
=
'@^/?diffusion/(?P<callsign>[A-Z]+)(?:/|$)@'
;
$matches
=
null
;
if
(
!
preg_match
(
$regex
,
$path
,
$matches
)
)
{
throw
new
Exception
(
pht
(
'Unrecognized repository path "%s". Expected a path like '
.
'"%s".'
,
$path
,
"/diffusion/X/"
)
)
;
}
$callsign
=
$matches
[
1
]
;
$repository
=
id
(
new
PhabricatorRepositoryQuery
(
)
)
->
setViewer
(
$viewer
)
->
withCallsigns
(
array
(
$callsign
)
)
->
executeOne
(
)
;
if
(
!
$repository
)
{
throw
new
Exception
(
pht
(
'No repository "%s" exists!'
,
$callsign
)
)
;
}
$is_push
=
!
$this
->
isReadOnly
(
)
;
switch
(
$repository
->
getServeOverSSH
(
)
)
{
case
PhabricatorRepository
::
SERVE_READONLY
:
if
(
$is_push
)
{
throw
new
Exception
(
pht
(
'This repository is read-only over SSH.'
)
)
;
}
break
;
case
PhabricatorRepository
::
SERVE_READWRITE
:
if
(
$is_push
)
{
$can_push
=
PhabricatorPolicyFilter
::
hasCapability
(
$viewer
,
$repository
,
DiffusionCapabilityPush
::
CAPABILITY
)
;
if
(
!
$can_push
)
{
throw
new
Exception
(
pht
(
'You do not have permission to push to this repository.'
)
)
;
}
}
break
;
case
PhabricatorRepository
::
SERVE_OFF
:
default
:
throw
new
Exception
(
pht
(
'This repository is not available over SSH.'
)
)
;
}
return
$repository
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Jan 19, 13:57 (3 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1125293
Default Alt Text
DiffusionSSHWorkflow.php (2 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment