-
Notifications
You must be signed in to change notification settings - Fork 289
Allow parcel ref in component source #456
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use bindle::client::{ | ||
| tokens::{HttpBasic, NoToken, TokenManager}, | ||
| Client, ClientBuilder, | ||
| }; | ||
|
|
||
| /// BindleConnectionInfo holds the details of a connection to a | ||
| /// Bindle server, including url, insecure configuration and an | ||
| /// auth token manager | ||
| #[derive(Clone)] | ||
| pub struct BindleConnectionInfo { | ||
| base_url: String, | ||
| allow_insecure: bool, | ||
| token_manager: AnyAuth, | ||
| } | ||
|
|
||
| impl BindleConnectionInfo { | ||
| /// Generates a new BindleConnectionInfo instance using the provided | ||
| /// base_url, allow_insecure setting and optional username and password | ||
| /// for basic http auth | ||
| pub fn new<I: Into<String>>( | ||
| base_url: I, | ||
| allow_insecure: bool, | ||
| username: Option<String>, | ||
| password: Option<String>, | ||
| ) -> Self { | ||
| let token_manager: Box<dyn TokenManager + Send + Sync> = match (username, password) { | ||
| (Some(u), Some(p)) => Box::new(HttpBasic::new(&u, &p)), | ||
| _ => Box::new(NoToken::default()), | ||
| }; | ||
|
|
||
| Self { | ||
| base_url: base_url.into(), | ||
| allow_insecure, | ||
| token_manager: AnyAuth { | ||
| token_manager: Arc::new(token_manager), | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| /// Returns a client based on this instance's configuration | ||
| pub fn client(&self) -> bindle::client::Result<Client<AnyAuth>> { | ||
| let builder = ClientBuilder::default() | ||
| .http2_prior_knowledge(false) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This appears to be the default...
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think when this code was written it was not the default (in fact I think I had to add the option so I could set it to false), so this is historical I guess... but unless the default is contractual (that is, it would be documented as a breaking change if they changed it), I'm inclined to set this explicitly. (Ultimately it should be under config control.) |
||
| .danger_accept_invalid_certs(self.allow_insecure); | ||
| builder.build(&self.base_url, self.token_manager.clone()) | ||
| } | ||
| } | ||
|
|
||
| /// AnyAuth wraps an authentication token manager which applies | ||
| /// the appropriate auth header per its configuration | ||
| #[derive(Clone)] | ||
| pub struct AnyAuth { | ||
| token_manager: Arc<Box<dyn TokenManager + Send + Sync>>, | ||
| } | ||
|
|
||
| #[async_trait::async_trait] | ||
| impl TokenManager for AnyAuth { | ||
| async fn apply_auth_header( | ||
| &self, | ||
| builder: reqwest::RequestBuilder, | ||
| ) -> bindle::client::Result<reqwest::RequestBuilder> { | ||
| self.token_manager.apply_auth_header(builder).await | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| spin_version = "1" | ||
| authors = ["Fermyon Engineering <[email protected]>"] | ||
| description = "A simple application that returns hello and goodbye." | ||
| name = "spin-hello-from-parcel" | ||
| trigger = {type = "http", base = "/test"} | ||
| version = "1.0.0" | ||
|
|
||
| [config] | ||
| object = { default = "teapot" } | ||
|
|
||
| [[component]] | ||
| id = "hello" | ||
| source = { reference = "spin-hello-world/1.0.0", parcel = "AWAITING_PARCEL_SHA" } | ||
| files = [ { source = "assets", destination = "/" } ] | ||
| [component.trigger] | ||
| route = "/hello/..." | ||
| [component.config] | ||
| message = "I'm a {{object}}" |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about something like this, to allow easier extension to other auth types:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see this is copied from
publish, so this doesn't need to be in scope for this PR.