Xuanwo commented on code in PR #4029:
URL: https://github.com/apache/opendal/pull/4029#discussion_r1461290416
##########
core/src/services/icloud/core.rs:
##########
@@ -110,81 +109,96 @@ impl Debug for IcloudSigner {
}
impl IcloudSigner {
- /// Get the session data from signer.
- pub fn session_data(&self) -> &SessionData {
- &self.data
+ /// Get the drivews_url from signer session data.
+ /// Async await init finish.
+ pub async fn drivews_url(&mut self) -> Result<String> {
+ self.init().await?;
+ Ok(self.data.drivews_url.clone())
+ }
+
+ /// Get the docws_url from signer session data.
+ /// Async await init finish.
+ pub async fn docws_url(&mut self) -> Result<String> {
+ self.init().await?;
+ Ok(self.data.docws_url.clone())
}
/// iCloud will use our oauth state as client id.
- pub fn client_id(&self) -> &str {
+ pub fn client_id(&mut self) -> &str {
&self.data.oauth_state
}
async fn init(&mut self) -> Result<()> {
// Sign the auth endpoint first.
- let uri = format!("{}/signin?isRememberMeEnable=true", AUTH_ENDPOINT);
- let body = serde_json::to_vec(&json!({
- "accountName" : self.apple_id,
- "password" : self.password,
- "rememberMe": true,
- "trustTokens": [self.trust_token.clone().unwrap()],
- }))
- .map_err(new_json_serialize_error)?;
-
- let mut req = Request::post(uri)
- .header(header::CONTENT_TYPE, "application/json")
- .body(AsyncBody::Bytes(Bytes::from(body)))
- .map_err(new_request_build_error)?;
- self.sign(&mut req)?;
-
- let resp = self.client.send(req).await?;
- if resp.status() != StatusCode::OK {
- return Err(parse_error(resp).await?);
- }
- if let Some(rscd) = resp.headers().get(APPLE_RESPONSE_HEADER) {
- let status_code = StatusCode::from_bytes(rscd.as_bytes()).unwrap();
- if status_code != StatusCode::CONFLICT {
+ if !self.initiated {
Review Comment:
Please don't wrap logic in large block. We can write like the following:
```rust
if self.initiated {
return Ok(())
}
// Logic here
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]