Skip to content
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

docs: add service doc for oss #2409

Merged
merged 3 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 1 addition & 72 deletions core/src/services/oss/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,78 +40,7 @@ use crate::*;

const DEFAULT_WRITE_MIN_SIZE: usize = 8 * 1024 * 1024;
/// Aliyun Object Storage Service (OSS) support
///
/// # Capabilities
///
/// This service can be used to:
///
/// - [x] stat
/// - [x] read
/// - [x] write
/// - [x] append
/// - [x] create_dir
/// - [x] delete
/// - [x] copy
/// - [ ] rename
/// - [x] list
/// - [x] scan
/// - [x] presign
/// - [ ] blocking
///
/// # Configuration
///
/// - `root`: Set the work dir for backend.
/// - `bucket`: Set the container name for backend.
/// - `endpoint`: Set the endpoint for backend.
/// - `presign_endpoint`: Set the endpoint for presign.
/// - `access_key_id`: Set the access_key_id for backend.
/// - `access_key_secret`: Set the access_key_secret for backend.
/// - `role_arn`: Set the role of backend.
/// - `oidc_token`: Set the oidc_token for backend.
/// - `allow_anonymous`: Set the backend access OSS in anonymous way.
///
/// Refer to [`OssBuilder`]'s public API docs for more information.
///
/// # Example
///
/// ## Via Builder
///
/// ```no_run
/// use std::sync::Arc;
///
/// use anyhow::Result;
/// use opendal::services::Oss;
/// use opendal::Operator;
///
/// #[tokio::main]
/// async fn main() -> Result<()> {
/// // Create OSS backend builder.
/// let mut builder = Oss::default();
/// // Set the root for oss, all operations will happen under this root.
/// //
/// // NOTE: the root must be absolute path.
/// builder.root("/path/to/dir");
/// // Set the bucket name, this is required.
/// builder.bucket("test");
/// // Set the endpoint.
/// //
/// // For example:
/// // - "https://oss-ap-northeast-1.aliyuncs.com"
/// // - "https://oss-hangzhou.aliyuncs.com"
/// builder.endpoint("https://oss-cn-beijing.aliyuncs.com");
/// // Set the access_key_id and access_key_secret.
/// //
/// // OpenDAL will try load credential from the env.
/// // If credential not set and no valid credential in env, OpenDAL will
/// // send request without signing like anonymous user.
/// builder.access_key_id("access_key_id");
/// builder.access_key_secret("access_key_secret");
///
/// let op: Operator = Operator::new(builder)?.finish();
///
/// Ok(())
/// }
/// ```
#[doc = include_str!("docs.md")]
#[derive(Default)]
pub struct OssBuilder {
root: Option<String>,
Expand Down
73 changes: 73 additions & 0 deletions core/src/services/oss/docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@


Xuanwo marked this conversation as resolved.
Show resolved Hide resolved
# Capabilities

This service can be used to:

- [x] stat
- [x] read
- [x] write
- [x] append
- [x] create_dir
- [x] delete
- [x] copy
- [ ] rename
- [x] list
- [x] scan
- [x] presign
- [ ] blocking

# Configuration

- `root`: Set the work dir for backend.
- `bucket`: Set the container name for backend.
- `endpoint`: Set the endpoint for backend.
- `presign_endpoint`: Set the endpoint for presign.
- `access_key_id`: Set the access_key_id for backend.
- `access_key_secret`: Set the access_key_secret for backend.
- `role_arn`: Set the role of backend.
- `oidc_token`: Set the oidc_token for backend.
- `allow_anonymous`: Set the backend access OSS in anonymous way.

Refer to [`OssBuilder`]'s public API docs for more information.

# Example

## Via Builder

```rust
use std::sync::Arc;

use anyhow::Result;
use opendal::services::Oss;
use opendal::Operator;

#[tokio::main]
async fn main() -> Result<()> {
// Create OSS backend builder.
let mut builder = Oss::default();
// Set the root for oss, all operations will happen under this root.
//
// NOTE: the root must be absolute path.
builder.root("/path/to/dir");
// Set the bucket name, this is required.
builder.bucket("test");
// Set the endpoint.
//
// For example:
// - "https://oss-ap-northeast-1.aliyuncs.com"
// - "https://oss-hangzhou.aliyuncs.com"
builder.endpoint("https://oss-cn-beijing.aliyuncs.com");
// Set the access_key_id and access_key_secret.
//
// OpenDAL will try load credential from the env.
// If credential not set and no valid credential in env, OpenDAL will
// send request without signing like anonymous user.
builder.access_key_id("access_key_id");
builder.access_key_secret("access_key_secret");

let op: Operator = Operator::new(builder)?.finish();

Ok(())
}
```
75 changes: 75 additions & 0 deletions website/docs/services/oss.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
title: OSS
---

Aliyun Object Storage Service (OSS) support.

import Docs from '../../../core/src/services/oss/docs.md'

<Docs components={props.components} />


### Via Config

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<Tabs>
<TabItem value="rust" label="Rust" default>

```rust
use std::sync::Arc;

use anyhow::Result;
use opendal::Scheme;
use opendal::Operator;

#[tokio::main]
async fn main() -> Result<()> {
let mut map = HashMap::new();
map.insert("root".to_string(), "/path/to/dir".to_string());
map.insert("bucket".to_string(), "test".to_string());
map.insert("endpoint".to_string(), "https://oss-cn-beijing.aliyuncs.com".to_string());
map.insert("access_key_id".to_string(), "access_key_id".to_string());
map.insert("access_key_secret".to_string(), "access_key_secret".to_string());

let op: Operator = Operator::via_map(Scheme::Oss, map)?;
Ok(())
}
```

</TabItem>
<TabItem value="node.js" label="Node.js">

```javascript
import { Operator } from "opendal";

async function main() {
const op = new Operator("oss", {
root: "/path/to/dir",
bucket: "test",
endpoint: "https://oss-cn-beijing.aliyuncs.com",
access_key_id: "access_key_id",
access_key_secret: "access_key_secret",
});
}
```

</TabItem>
<TabItem value="python" label="Python">

```python
import opendal

op = opendal.Operator("oss",
root:"/path/to/dir",
bucket="test",
endpoint="https://oss-cn-beijing.aliyuncs.com",
access_key_id="access_key_id",
access_key_secret="access_key_secret",
)
```

</TabItem>
</Tabs>