Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: do not require name top-level config #50

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ sudo mv novops /usr/local/bin/novops
Create `.novops.yml` and commit it safely - it does not contain any secret:

```yaml
name: aws-creds-and-hashicorp-vault-secrets-example

environments:
dev:

Expand Down
10 changes: 6 additions & 4 deletions docs/schema/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"description": "Main Novops config file",
"type": "object",
"required": [
"environments",
"name"
"environments"
],
"properties": {
"config": {
Expand All @@ -27,8 +26,11 @@
}
},
"name": {
"description": "Unique application name.\n\nLoading Novops from distinct files with the same name may have unexpected results",
"type": "string"
"description": "Application name. Informational only.\n\nIf not specified, use current directory name",
"type": [
"string",
"null"
]
}
},
"definitions": {
Expand Down
2 changes: 1 addition & 1 deletion docs/schema/index.html

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions docs/src/advanced/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ For instance:
```rust
#[derive(/* ... */ JsonSchema)]
pub struct NovopsConfigFile {
pub name: String,
pub environments: HashMap<String, NovopsEnvironmentInput>,
pub config: Option<NovopsConfig>
}
Expand All @@ -105,8 +104,6 @@ pub struct NovopsConfigFile {
Define top-level Novops config schema:

```yaml
name: my-app

environments:
dev: # ...
prod: # ...
Expand Down
2 changes: 0 additions & 2 deletions docs/src/config/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ See [full `.novops.yml` schema](https://pierrebeucher.github.io/novops/config/sc
Example: environments `dev` and `prod` with inputs `files`, `variables` and `hvault_kv2`.

```yaml
name: some-app

environments:

# Environment name
Expand Down
2 changes: 0 additions & 2 deletions docs/src/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ Consider a typical workflow: run build and deployment with **secrets from Hashic
Create `.novops.yml` and commit it safely - it does not contain any secret:

```yaml
name: aws-creds-and-hashicorp-vault-secrets-example

environments:
dev:

Expand Down
6 changes: 3 additions & 3 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ type NovopsEnvironments = HashMap<String, NovopsEnvironmentInput>;
///
#[derive(Debug, Deserialize, Clone, PartialEq, JsonSchema)]
pub struct NovopsConfigFile {
/// Unique application name.
/// Application name. Informational only.
///
/// Loading Novops from distinct files with the same name may have unexpected results
pub name: String,
/// If not specified, use current directory name
pub name: Option<String>,

/// Source of truth defining files and variables loaded by Novops
///
Expand Down
30 changes: 23 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,28 @@ pub async fn make_context(args: &NovopsLoadArgs) -> Result<NovopsContext, anyhow
let config = read_config_file(&args.config)
.with_context(|| format!("Error reading config file '{:}'", &args.config))?;

let app_name = &config.name.clone();
// app name may be specififed by user
// if not, use current directory name
let app_name = match &config.name {
Some(n) => n.clone(),
None => {
let curdir = env::current_dir()
.with_context(|| "Couldn't read current directory.")?;

let default_app_name = curdir.file_name()
.and_then(|n| n.to_str())
.unwrap_or("root");

String::from(default_app_name)
// may not yield exact folder name as some non-UTF8 char may be replaced
// but it's acceptable for our purpose
}
};

// Env name is either specified as arg, as default or prompt user
let env_name = read_environment_name(&config, &args.env)?;

// working directory under which to save files
// working directory under which to save files (if any)
let workdir = prepare_working_directory(&args, &app_name, &env_name)?;
info!("Using workdir: {:?}", &workdir);

Expand Down Expand Up @@ -289,11 +305,11 @@ fn prepare_working_directory(args: &NovopsLoadArgs, app_name: &String, env_name:
let workdir = match &args.working_directory {
Some(wd) => PathBuf::from(wd),
None => match prepare_working_directory_xdg(app_name, env_name) {
Ok(s) => s,
Err(e) => {
info!("Using /tmp as XDG did not seem available: {:?}", e);
prepare_working_directory_tmp(app_name, env_name)?
},
Ok(s) => s,
Err(e) => {
info!("Using /tmp as XDG did not seem available: {:?}", e);
prepare_working_directory_tmp(app_name, env_name)?
},
}
};

Expand Down
2 changes: 0 additions & 2 deletions tests/.novops.all-modules.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Show simple example for all modules
name: test-all

environments:
dev:
variables:
Expand Down
2 changes: 0 additions & 2 deletions tests/.novops.aws_assumerole.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# AWS Assume role
name: aws-assumerole

environments:
dev:

Expand Down
2 changes: 0 additions & 2 deletions tests/.novops.aws_secretsmanager.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# AWS Secrets Managers
name: aws-ssm

environments:
dev:
variables:
Expand Down
2 changes: 0 additions & 2 deletions tests/.novops.aws_secretsmanager_var_nonutf8.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Novops config used to test AWS modules with LocalStack
name: test-aws

environments:
dev:
variables:
Expand Down
2 changes: 0 additions & 2 deletions tests/.novops.aws_ssm.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# AWS Systems Manager (SSM)
name: aws-ssm

environments:
dev:
variables:
Expand Down
2 changes: 0 additions & 2 deletions tests/.novops.azure_keyvault.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Azure Key Vault
name: test-azure-keyvault

environments:
dev:
variables:
Expand Down
2 changes: 0 additions & 2 deletions tests/.novops.gcloud_secretmanager.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# GCloud Secret Manager test
name: test-gcloud-secret-manager

environments:
dev:
variables:
Expand Down
2 changes: 0 additions & 2 deletions tests/.novops.hvault_aws.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# The unique application name
name: test-app

environments:
dev:
# Generate AWS creds
Expand Down
2 changes: 0 additions & 2 deletions tests/.novops.hvault_kv1.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Hashicorp Vault Key Value v1
name: hashivault-kv1

environments:
dev:
variables:
Expand Down
2 changes: 0 additions & 2 deletions tests/.novops.hvault_kv2.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# The unique application name
name: test-app

environments:
dev:
variables:
Expand Down
2 changes: 0 additions & 2 deletions tests/.novops.plain-strings.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Simple standalone config without requiring external access
# i.e. only plain variable and file content
# Useful to test basic loading and flags such as
name: test-plain-strings

environments:
dev:
# Variable can use plain string and any modules
Expand Down
2 changes: 0 additions & 2 deletions tests/manual/.novops-before.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Internal Novops config for Novops testing
name: novops-manual-google-test

environments:
dev:

Expand Down
2 changes: 0 additions & 2 deletions tests/nix/.novops.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
name: my-awesome-app

environments:

dev:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ mod tests {
app_name: String::from("test-empty"),
workdir: workdir.clone(),
config_file_data: NovopsConfigFile{
name: String::from("test-empty"),
name: Some(String::from("test-empty")),
environments: HashMap::from([
(String::from("dev"), NovopsEnvironmentInput {
variables: None,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub fn create_dummy_context() -> NovopsContext{
app_name: String::from("test-empty"),
workdir: PathBuf::from("/tmp"),
config_file_data: NovopsConfigFile{
name: String::from("test-empty"),
name: Some(String::from("test-empty")),
environments: HashMap::new(),
config: Some(NovopsConfig {
default: Some(NovopsConfigDefault {
Expand Down