The Reva SDK (located under
/pkg/sdk/) is a simple software development kit to work with Reva through the CS3API. It’s goal is to make working with Reva as easy as possible by providing a high-level API which hides all the details of the underlying CS3API.
The main design goal of the SDK is simplicity. This means that the code is extremely easy to use instead of being particularly fancy or feature-rich.
There are two central kinds of objects you’ll be using: a session and various actions. The session represents the connection to the Reva server through its gRPC gateway client; the actions are then used to perform operations like up- and downloading or enumerating all files located at a specific remote path.
The first step when using the SDK is to create a session and establish a connection to Reva (which actually results in a token-creation and not a permanent connection, but this should not bother you in any way):
session := sdk.MustNewSession() // Panics if this fails (should usually not happen) session.Initiate("reva.host.com:443", false) session.BasicLogin("my-login", "my-pass")
Note that error checking is omitted here for brevity, but nearly all methods in the SDK return an error which should be checked upon.
If the session has been created successfully - which can also be verified by calling
session.IsValid() -, you can use one of the various actions to perform the actual operations.
An overview of all currently supported operations can be found below; here is an example of how to upload a file using the
act := action.MustNewUploadAction(session) info, err := act.UploadBytes(byte("HELLO WORLD!\n"), "/home/mytest/hello.txt") // Check error... fmt.Printf("Uploaded file: %s [%db] -- %s", info.Path, info.Size, info.Type)
As you can see, you first need to create an instance of the desired action by either calling its corresponding
MustNew...Action function; these creators always require you to pass the previously created session object. The actual operations are then performed by using the appropriate methods offered by the action object.
A more extensive example of how to use the SDK can also be found in
An action object often bundles various operations; the
FileOperationsAction, for example, allows you to create directories, check if a file exists or remove an entire path. Below is an alphabetically sorted table of the available actions and their supported operations:
|Downloads a specific resource identified by a |
|Downloads a specific file|
|Lists all files and directories in a given path|
|Lists all files and directories in a given path that fulfill a given predicate|
|Lists all directories in a given path|
|Lists all files in a given path|
|Checks whether the specified directory exists|
|Checks whether the specified file exists|
|Creates the entire directory tree specified by a path|
|Moves a specified resource to a new target|
|Moves a specified resource to a new directory, creating it if necessary|
|Deletes the specified resource|
|Checks whether the specified resource exists|
|Queries information of a resource|
|Uploads data from a reader to a target file|
|Uploads byte data to a target file|
|Uploads a file to a target file|
|Uploads a file to a target directory|
UploadActioncreates the target directory automatically if necessary.
Note that not all features of the CS3API are currently implemented.