-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: install extensions using the catalog (#3868)
Look up extension.json url from /catalog.json in https://github.com/dfinity/dfx-extensions Fixes https://dfinity.atlassian.net/browse/SDK-1796
- Loading branch information
1 parent
7d4dd48
commit 967bef1
Showing
13 changed files
with
192 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "ExtensionCatalog", | ||
"type": "object", | ||
"additionalProperties": { | ||
"type": "string" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::error::extension::FetchCatalogError; | ||
use crate::extension::url::ExtensionJsonUrl; | ||
use crate::http::get::get_with_retries; | ||
use crate::json::structure::UrlWithJsonSchema; | ||
use backoff::exponential::ExponentialBackoff; | ||
use schemars::JsonSchema; | ||
use serde::Deserialize; | ||
use std::collections::HashMap; | ||
use std::time::Duration; | ||
use url::Url; | ||
|
||
const DEFAULT_CATALOG_URL: &str = | ||
"https://raw.githubusercontent.com/dfinity/dfx-extensions/main/catalog.json"; | ||
|
||
#[derive(Deserialize, Debug, JsonSchema)] | ||
pub struct ExtensionCatalog(pub HashMap<String, UrlWithJsonSchema>); | ||
|
||
impl ExtensionCatalog { | ||
pub async fn fetch(url: Option<&Url>) -> Result<Self, FetchCatalogError> { | ||
let url: Option<Url> = url.cloned(); | ||
let url = url.unwrap_or_else(|| Url::parse(DEFAULT_CATALOG_URL).unwrap()); | ||
let retry_policy = ExponentialBackoff { | ||
max_elapsed_time: Some(Duration::from_secs(60)), | ||
..Default::default() | ||
}; | ||
let resp = get_with_retries(url, retry_policy) | ||
.await | ||
.map_err(FetchCatalogError::Get)?; | ||
|
||
resp.json().await.map_err(FetchCatalogError::ParseJson) | ||
} | ||
|
||
pub fn lookup(&self, name: &str) -> Option<ExtensionJsonUrl> { | ||
self.0 | ||
.get(name) | ||
.map(|url| ExtensionJsonUrl::new(url.0.clone())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod catalog; | ||
pub mod manager; | ||
pub mod manifest; | ||
pub mod url; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters