Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4792833
actions.rs
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
actions.rs
View Options
// -------------------------------------------------------------
// Alkane :: Actions
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Project: Nasqueron
// License: BSD-2-Clause
// -------------------------------------------------------------
use
crate
::
command
::
ServerArgs
;
use
crate
::
config
::
AlkaneConfig
;
use
crate
::
db
::
Database
;
use
crate
::
deploy
::
AlkaneDeployError
;
use
crate
::
deploy
::
DeployError
;
use
crate
::
runner
::
store
::
RecipesStore
;
use
crate
::
runner
::
RecipeStatus
;
use
crate
::
server
::
kernel
::
run
;
// -------------------------------------------------------------
// Actions only available in CLI
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
pub
fn
serve
(
args
:
ServerArgs
,
config
:
AlkaneConfig
)
{
run
(
config
,
&
args
.
mounting_point
);
}
// -------------------------------------------------------------
// Actions available both for CLI and HTTP
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
fn
run_deployment_action
(
site_name
:
&
str
,
context
:
Option
<
String
>
,
config
:
&
AlkaneConfig
,
action
:
&
str
,
)
->
Result
<
RecipeStatus
,
DeployError
>
{
let
db
=
Database
::
from_config
(
config
).
ok_or_else
(
||
{
let
error
=
AlkaneDeployError
::
new
(
"Can't initialize database"
,
site_name
,
action
);
DeployError
::
Alkane
(
error
)
})
?
;
let
recipes
=
RecipesStore
::
from_config
(
config
).
ok_or_else
(
||
{
let
error
=
AlkaneDeployError
::
new
(
"Can't initialize recipes store"
,
site_name
,
action
);
DeployError
::
Alkane
(
error
)
})
?
;
let
site
=
config
.
get_site
(
site_name
,
context
)
.
ok_or_else
(
||
{
let
error
=
AlkaneDeployError
::
new
(
"Can't resolve site path"
,
site_name
,
action
);
DeployError
::
Alkane
(
error
)
})
?
;
let
status
=
recipes
.
run_recipe
(
&
site
,
action
);
if
action
==
"init"
&&
status
==
RecipeStatus
::
Success
{
db
.
set_initialized
(
&
site
.
name
);
}
Ok
(
status
)
}
pub
fn
initialize
(
site_name
:
&
str
,
context
:
Option
<
String
>
,
config
:
&
AlkaneConfig
,
)
->
Result
<
RecipeStatus
,
DeployError
>
{
run_deployment_action
(
site_name
,
context
,
config
,
"init"
)
}
pub
fn
update
(
site_name
:
&
str
,
context
:
Option
<
String
>
,
config
:
&
AlkaneConfig
,
)
->
Result
<
RecipeStatus
,
DeployError
>
{
run_deployment_action
(
site_name
,
context
,
config
,
"update"
)
}
pub
fn
deploy
(
site_name
:
&
str
,
context
:
Option
<
String
>
,
config
:
&
AlkaneConfig
,
)
->
Result
<
RecipeStatus
,
DeployError
>
{
if
is_present
(
site_name
,
config
)
{
run_deployment_action
(
site_name
,
context
,
config
,
"update"
)
}
else
{
run_deployment_action
(
site_name
,
context
,
config
,
"init"
)
}
}
pub
fn
is_present
(
site_name
:
&
str
,
config
:
&
AlkaneConfig
)
->
bool
{
match
Database
::
from_config
(
&
config
)
{
None
=>
false
,
Some
(
db
)
=>
db
.
is_initialized
(
site_name
),
}
}
// -------------------------------------------------------------
// Tests
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#[cfg(test)]
mod
tests
{
use
super
::
*
;
#[test]
pub
fn
test_is_present
()
{
let
config
=
AlkaneConfig
::
load
().
unwrap
();
assert_eq
!
(
true
,
is_present
(
"foo.acme.tld"
,
&
config
));
assert_eq
!
(
false
,
is_present
(
"notexisting.acme.tld"
,
&
config
));
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Feb 28, 21:22 (1 d, 1 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2447447
Default Alt Text
actions.rs (3 KB)
Attached To
Mode
rALK Alkane
Attached
Detach File
Event Timeline
Log In to Comment