diff --git a/README.md b/README.md index 247bb44..32f87b4 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,8 @@ PR's are Welcome, if it's something bigger / fundamental: Please make a Issue an # Examples ## Login First you will need to Create a Client, and then Login on the Server using the Client -``` + +```go package main import ( @@ -65,7 +66,8 @@ You can do this using the `client.CheckSession()` function. ## Create a Resource Creating a Resource using the helper package is simple, first add `"github.com/speatzle/go-passbolt/helper"` to your imports. Then you can simply: -``` + +```go resourceID, err := helper.CreateResource( ctx, // Context client, // API Client @@ -77,8 +79,10 @@ resourceID, err := helper.CreateResource( "This is a Account for the example test portal", // Description ) ``` + Creating a (Legacy) Resource Without the helper package would look like this: -``` + +```go enc, err := client.EncryptMessage("securePassword123") if err != nil { panic(err) @@ -99,6 +103,7 @@ if err != nil { panic(err) } ``` + Note: Since Passbolt v3 There are Resource Types, this Manual Example just creates a "password-string" Type Password where the Description is Unencrypted, Read More [Here](https://help.passbolt.com/api/resource-types). ## Getting @@ -106,14 +111,17 @@ Generally API Get Calls will have options (opts) that allow for specifing filter Filters just filter by whatever is given, contains on the otherhand specify what to include in the response. Many Filters And Contains are undocumented in the Passbolt Docs. Here We Specify that we want to Filter by Favorites and that the Response Should Contain the Permissions for each Resource: -``` + +```go favorites, err := client.GetResources(ctx, &api.GetResourcesOptions{ FilterIsFavorite: true, ContainPermissions: true, }) ``` + We Can do the Same for Users: -``` + +```go users, err := client.GetUsers(ctx, &api.GetUsersOptions{ FilterSearch: "Samuel", ContainLastLoggedIn: true, @@ -121,7 +129,8 @@ users, err := client.GetUsers(ctx, &api.GetUsersOptions{ ``` Groups: -``` + +```go groups, err := client.GetGroups(ctx, &api.GetGroupsOptions{ FilterHasUsers: []string{"id of user", "id of other user"}, ContainUser: true, @@ -129,7 +138,8 @@ groups, err := client.GetGroups(ctx, &api.GetGroupsOptions{ ``` And also for Folders (PRO Only): -``` + +```go folders, err := client.GetFolders(ctx, &api.GetFolderOptions{ FilterSearch: "Test Folder", ContainChildrenResources: true, @@ -137,25 +147,29 @@ folders, err := client.GetFolders(ctx, &api.GetFolderOptions{ ``` Getting by ID is also Supported Using the Singular Form: -``` + +```go resource, err := client.GetResource(ctx, "resource ID") ``` Since the Password is Encrypted (and sometimes the description too) the helper package has a function to decrypt all encrypted fields Automatically: -``` + +```go folderParentID, name, username, uri, password, description, err := helper.GetResource(ctx, client, "resource id") ``` ## Updating The Helper Package has a function to save you needing to deal with Resource Types When Updating a Resource: -``` + +```go err := helper.UpdateResource(ctx, client,"resource id", "name", "username", "https://test.example.com", "pass123", "very descriptive") ``` Note: As Groups are also Complicated to Update there will be a helper function for them in the future. For other less Complicated Updates you can Simply use the Client directly: -``` + +```go client.UpdateUser(ctx, "user id", api.User{ Profile: &api.Profile{ FirstName: "Test", @@ -170,13 +184,16 @@ As Sharing Resources is very Complicated there are multipe helper Functions. Dur The permissionType can be 1 for Read only, 7 for Can Update, 15 for Owner or -1 if you want to delete Existing Permissions. The ShareResourceWithUsersAndGroups function Shares the Resource With all Provided Users and Groups with the Given permissionType. -``` + +```go err := helper.ShareResourceWithUsersAndGroups(ctx, client, "resource id", []string{"user 1 id"}, []string{"group 1 id"}, 7) ``` + Note: Existing Permission of Users and Groups will be adjusted to be of the Provided permissionType. If you need to do something more Complicated like setting Users/Groups to different Type then you can Use ShareResource directly: -``` + +```go changes := []helper.ShareOperation{} // Make this User Owner @@ -209,11 +226,13 @@ changes = append(changes, ShareOperation{ err := helper.ShareResource(ctx, c, resourceID, changes) ``` + Note: These Functions are Also Availabe for Folders (PRO) ## Full Example This Example Creates a Resource, Searches for a User Named Test User, Checks that its Not itself and Shares the Password with the Test User if Nessesary: -``` + +```go package main import ( @@ -302,4 +321,4 @@ func main() { - get a Passbolt Instance to Work in Github Actions - write Integration Tests - add ability to verify Server -- add helper functions for updating Groups \ No newline at end of file +- add helper functions for updating Groups