Skip to content

Commit

Permalink
feat(commands): create config from URL
Browse files Browse the repository at this point in the history
  • Loading branch information
ozoder committed Jul 8, 2024
1 parent 425b3d3 commit f875ae5
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
9 changes: 6 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
- Add `config parse-from-url` command for parsing configuration from a URL

# v0.28.0
- Add general fields to `create datasets`

Expand All @@ -14,10 +17,10 @@

# v0.25.0
- Fixes issue when getting streams that have multiple filters on single user property
- Fixes issue where upper case file names would not be matched in `parse`
- Fixes issue where upper case file names would not be matched in `parse`
- Reduce batch size when deleting comment batches
- Support attachment type filters
- support getting stats for `get buckets`
- support getting stats for `get buckets`
- Show usage on `get quotas`

# v0.24.0
Expand All @@ -29,7 +32,7 @@

- Add `get emails`
- Added support for `--auto-increase-up-to` when creating quotas.
- Support spans format for entities
- Support spans format for entities

# v0.22.2

Expand Down
61 changes: 61 additions & 0 deletions cli/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ pub enum ConfigArgs {
#[structopt(name = "is-required", parse(try_from_str))]
is_required: bool,
},

#[structopt(name = "parse-from-url")]
/// Parse config from a URL
ParseFromUrl {
/// The URL to be parsed
#[structopt(long = "url", short = "u")]
url: Option<Url>,
/// The reinfer API token that will be used for this context
#[structopt(long = "token", short = "t")]
token: Option<String>,
},
}

pub fn run(
Expand Down Expand Up @@ -206,10 +217,60 @@ pub fn run(
}
}
}
ConfigArgs::ParseFromUrl { url, token } => {
parse_context_from_url(url, token, config.clone(), config_path)?;
}
}
Ok(config)
}

fn parse_context_from_url(
url: &Option<Url>,
token: &Option<String>,
config: ReinferConfig,
config_path: impl AsRef<Path>,
) -> Result<()> {
let mut url: Url = match url {
None => loop {
match Url::parse(&utils::read_from_stdin("URL", None)?) {
Ok(url) => break url,
Err(error) => {
error!("Invalid URL: {}", error);
}
}
},
Some(url) => url.clone(),
};
let path_segments: Vec<&str> = match url.path_segments() {
None => {
return Err(anyhow!(
"Invalid URL path, needs to contain <ORG NAME>/<TENANT NAME>/reinfer_/"
))
}
Some(segments) => segments.collect(),
};
if path_segments.len() < 3 || path_segments[2] != "reinfer_" {
return {
Err(anyhow!(
"Invalid URL path, needs to contain <ORG NAME>/<TENANT NAME>/reinfer_/"
))
};
}
let name: String = format!("{}/{}", path_segments[0], path_segments[1]);
// Remove the path to use the rest as the endpoint
url.set_path("");

add_or_edit_context(
&Some(name),
token,
&Some(url),
false,
&None,
config,
config_path,
)
}

fn add_or_edit_context(
name: &Option<String>,
token: &Option<String>,
Expand Down

0 comments on commit f875ae5

Please sign in to comment.