Skip to content

Commit

Permalink
add targetAccess environment config field (#109)
Browse files Browse the repository at this point in the history
* add targetNamePrefix environment config field
  • Loading branch information
blake-mealey authored Jan 16, 2022
1 parent 47b52fb commit a13c40f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
3 changes: 1 addition & 2 deletions project-fixtures/light/mantle.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
environments:
- name: staging
branches: [dev, dev/*]
# targetNamePrefix:
# custom: 'Test - '
targetNamePrefix: environmentName
targetAccess: private

target:
experience:
Expand Down
14 changes: 12 additions & 2 deletions src/lib/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ pub struct EnvironmentConfig {
pub overrides: Option<serde_yaml::Value>,

pub target_name_prefix: Option<TargetNamePrefixConfig>,

pub target_access: Option<TargetAccessConfig>,
}

#[derive(Deserialize, Clone)]
Expand All @@ -117,6 +119,14 @@ pub enum TargetNamePrefixConfig {
Custom(String),
}

#[derive(Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub enum TargetAccessConfig {
Public,
Private,
Friends,
}

#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub enum TargetConfig {
Expand Down Expand Up @@ -274,7 +284,7 @@ pub enum AssetTargetConfig {
FileWithAlias { file: String, name: String },
}

#[derive(Serialize, Deserialize, Clone)]
#[derive(Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase")]
pub struct ExperienceTargetConfigurationConfig {
// basic info
Expand Down Expand Up @@ -449,7 +459,7 @@ pub struct PlaceTargetConfig {
pub configuration: Option<PlaceTargetConfigurationConfig>,
}

#[derive(Serialize, Deserialize, Clone)]
#[derive(Serialize, Deserialize, Clone, Default)]
#[serde(rename_all = "camelCase")]
pub struct PlaceTargetConfigurationConfig {
pub name: Option<String>,
Expand Down
27 changes: 25 additions & 2 deletions src/lib/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use yansi::Paint;

use super::{
config::{
Config, EnvironmentConfig, ExperienceTargetConfig, OwnerConfig, PaymentsConfig,
StateConfig, TargetConfig, TargetNamePrefixConfig,
Config, EnvironmentConfig, ExperienceTargetConfig, ExperienceTargetConfigurationConfig,
OwnerConfig, PaymentsConfig, PlaceTargetConfigurationConfig, PlayabilityTargetConfig,
StateConfig, TargetAccessConfig, TargetConfig, TargetNamePrefixConfig,
},
logger,
resource_graph::ResourceGraph,
Expand Down Expand Up @@ -104,11 +105,33 @@ fn get_target_config(
None => DEFAULT_PLACE_NAME.to_owned(),
};
config.name = Some(format!("{}{}", name_prefix, name));
} else {
place.configuration = Some(PlaceTargetConfigurationConfig {
name: Some(format!("{}{}", name_prefix, DEFAULT_PLACE_NAME)),
..Default::default()
})
}
}
}
}

// Apply the access to all places in the experience
if let Some(target_access) = environment.target_access {
let playability = Some(match target_access {
TargetAccessConfig::Public => PlayabilityTargetConfig::Public,
TargetAccessConfig::Private => PlayabilityTargetConfig::Private,
TargetAccessConfig::Friends => PlayabilityTargetConfig::Friends,
});
if let Some(config) = &mut experience.configuration {
config.playability = playability
} else {
experience.configuration = Some(ExperienceTargetConfigurationConfig {
playability,
..Default::default()
});
}
}

// Apply overrides last (they are the final trump)
if let Some(overrides) = environment.overrides {
let mut as_value = serde_yaml::to_value(experience)
Expand Down

0 comments on commit a13c40f

Please sign in to comment.