-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial rust part of oauth2 cloud login * wip * minor updates * Added default parameter support * Fix lint * Bump beta version of package * Removed unneeded constants * Verified other flow tests
- Loading branch information
Showing
11 changed files
with
1,808 additions
and
37 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,13 @@ | ||
from ._fluvio_python import Cloud | ||
|
||
DEFAULT_REMOTE = "https://infinyon.cloud" | ||
|
||
|
||
def login( | ||
useOauth2=True, | ||
remote=DEFAULT_REMOTE, | ||
profile=None, | ||
email=None, | ||
password=None, | ||
): | ||
Cloud.login(useOauth2, remote, profile, email, password) |
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,11 @@ | ||
import unittest | ||
from fluvio.cloud import login | ||
|
||
|
||
class TestFluvioCloudLogin(unittest.TestCase): | ||
def test_login(self): | ||
login() | ||
# Comment/uncomment these as needed. | ||
#login(profile='test-profile') | ||
#login(useOauth2=False, email='youremail@gmail.com', password='PUT_YOURPASSWORD_HERE') | ||
#login(useOauth2=False) |
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,69 @@ | ||
use fluvio::FluvioError; | ||
use http_types::url::ParseError; | ||
use http_types::StatusCode; | ||
use std::io::Error as IoError; | ||
use std::path::PathBuf; | ||
use thiserror::Error; | ||
use toml::de::Error as TomlError; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum CloudLoginError { | ||
#[error("Unable to access the default Fluvio directory")] | ||
FluvioDirError, | ||
/// Failed to parse request URL | ||
#[error("Failed to parse URL: {url_string}")] | ||
UrlError { | ||
source: ParseError, | ||
url_string: String, | ||
}, | ||
#[error("Failed to make HTTP request to Infinyon cloud")] | ||
HttpError(#[source] HttpError), | ||
#[error("Failed to get token from Auth0")] | ||
FailedToGetAuth0Token, | ||
#[error("Failed to authenticate with Auth0: {0}")] | ||
Auth0LoginError(String), | ||
#[error("Account not found with email provided by third party service, please create account through WEB UI.")] | ||
Auth0AccountNotFound, | ||
#[error("Timeout while waiting for user authentication through third party service.")] | ||
Auth0TimeoutError, | ||
#[error("Unable to url encode the string")] | ||
UrlEncode(#[from] serde_urlencoded::ser::Error), | ||
#[error("Failed to save cloud credentials")] | ||
UnableToSaveCredentials(#[source] IoError), | ||
/// Failed to do some IO. | ||
#[error(transparent)] | ||
IoError(#[from] IoError), | ||
#[error("Failed to create logins dir {path}")] | ||
UnableToCreateLoginsDir { source: IoError, path: PathBuf }, | ||
#[error("Cluster for \"{0}\" does not exist")] | ||
ClusterDoesNotExist(String), | ||
#[error("Profile not available yet, please try again later.")] | ||
ProfileNotAvailable, | ||
#[error("Failed to parse login token from file")] | ||
UnableToParseCredentials(#[from] TomlError), | ||
#[error("Failed to load cloud credentials")] | ||
UnableToLoadCredentials(#[source] IoError), | ||
#[error("Failed to download cloud profile: Status code {0}: {1}")] | ||
ProfileDownloadError(StatusCode, &'static str), | ||
/// Failed to open Infinyon Cloud login file | ||
#[error("Not logged in")] | ||
NotLoggedIn, | ||
#[error("Fluvio client error")] | ||
FluvioError(#[from] FluvioError), | ||
#[error("Failed to authenticate with username: {0}")] | ||
AuthenticationError(String), | ||
#[error("Account not active. Please validate email address.")] | ||
AccountNotActive, | ||
} | ||
|
||
#[derive(Error, Debug)] | ||
#[error("An HTTP error occurred: {inner}")] | ||
pub struct HttpError { | ||
inner: http_types::Error, | ||
} | ||
|
||
impl From<http_types::Error> for CloudLoginError { | ||
fn from(inner: http_types::Error) -> Self { | ||
Self::HttpError(HttpError { inner }) | ||
} | ||
} |
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,42 @@ | ||
use async_h1::client; | ||
use http_types::{headers::USER_AGENT, Error, Request, Response, StatusCode}; | ||
use tracing::debug; | ||
|
||
pub const FLUVIO_CLI_USER_AGENT: &str = "Fluvio Python Client"; | ||
|
||
pub async fn execute(req: Request) -> Result<Response, Error> { | ||
debug!(?req, "executing request"); | ||
let mut req = req; | ||
let host = req | ||
.url() | ||
.host_str() | ||
.ok_or_else(|| Error::from_str(StatusCode::BadRequest, "missing hostname"))? | ||
.to_string(); | ||
|
||
let is_https = req.url().scheme() == "https"; | ||
|
||
let addr = req | ||
.url() | ||
.socket_addrs(|| if is_https { Some(443) } else { Some(80) })? | ||
.into_iter() | ||
.next() | ||
.ok_or_else(|| Error::from_str(StatusCode::BadRequest, "missing valid address"))?; | ||
|
||
let tcp_stream = fluvio_future::net::TcpStream::connect(addr).await?; | ||
|
||
req.append_header( | ||
USER_AGENT, | ||
format!("{}/{}", FLUVIO_CLI_USER_AGENT, env!("CARGO_PKG_VERSION")), | ||
); | ||
|
||
let result = if is_https { | ||
let tls_connector = fluvio_future::native_tls::TlsConnector::default(); | ||
let tls_stream = tls_connector.connect(host, tcp_stream).await?; | ||
client::connect(tls_stream, req).await | ||
} else { | ||
client::connect(tcp_stream, req).await | ||
}; | ||
|
||
debug!(?result, "http result"); | ||
result | ||
} |
Oops, something went wrong.