Skip to content

Latest commit

 

History

History
333 lines (255 loc) · 26.1 KB

README.md

File metadata and controls

333 lines (255 loc) · 26.1 KB

Consumers

(Vault.Consumers)

Overview

Available Operations

Create

Create a consumer

Example Usage

package main

import(
	"context"
	"os"
	sdkgo "github.com/apideck-libraries/sdk-go"
	"github.com/apideck-libraries/sdk-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := sdkgo.New(
        sdkgo.WithSecurity(os.Getenv("APIDECK_API_KEY")),
        sdkgo.WithConsumerID("test-consumer"),
        sdkgo.WithAppID("dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX"),
    )

    res, err := s.Vault.Consumers.Create(ctx, "test_consumer_id", &components.ConsumerMetadata{
        AccountName: sdkgo.String("SpaceX"),
        UserName: sdkgo.String("Elon Musk"),
        Email: sdkgo.String("[email protected]"),
        Image: sdkgo.String("https://www.spacex.com/static/images/share.jpg"),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.CreateConsumerResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description Example
ctx context.Context ✔️ The context to use for the request.
consumerID string ✔️ Unique consumer identifier. You can freely choose a consumer ID yourself. Most of the time, this is an ID of your internal data model that represents a user or account in your system (for example account:12345). If the consumer doesn't exist yet, Vault will upsert a consumer based on your ID. test_consumer_id
metadata *components.ConsumerMetadata The metadata of the consumer. This is used to display the consumer in the sidebar. This is optional, but recommended.
opts []operations.Option The options for this request.

Response

*operations.VaultConsumersAddResponse, error

Errors

Error Type Status Code Content Type
apierrors.BadRequestResponse 400 application/json
apierrors.UnauthorizedResponse 401 application/json
apierrors.PaymentRequiredResponse 402 application/json
apierrors.NotFoundResponse 404 application/json
apierrors.UnprocessableResponse 422 application/json
apierrors.APIError 4XX, 5XX */*

List

This endpoint includes all application consumers, along with an aggregated count of requests made.

Example Usage

package main

import(
	"context"
	"os"
	sdkgo "github.com/apideck-libraries/sdk-go"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := sdkgo.New(
        sdkgo.WithSecurity(os.Getenv("APIDECK_API_KEY")),
        sdkgo.WithConsumerID("test-consumer"),
        sdkgo.WithAppID("dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX"),
    )

    res, err := s.Vault.Consumers.List(ctx, nil, nil)
    if err != nil {
        log.Fatal(err)
    }
    if res.GetConsumersResponse != nil {
        for {
            // handle items

            res, err = res.Next()

            if err != nil {
                // handle error
            }

            if res == nil {
                break
            }
        }
    }
}

Parameters

Parameter Type Required Description
ctx context.Context ✔️ The context to use for the request.
cursor *string Cursor to start from. You can find cursors for next/previous pages in the meta.cursors property of the response.
limit *int64 Number of results to return. Minimum 1, Maximum 200, Default 20
opts []operations.Option The options for this request.

Response

*operations.VaultConsumersAllResponse, error

Errors

Error Type Status Code Content Type
apierrors.BadRequestResponse 400 application/json
apierrors.UnauthorizedResponse 401 application/json
apierrors.PaymentRequiredResponse 402 application/json
apierrors.NotFoundResponse 404 application/json
apierrors.UnprocessableResponse 422 application/json
apierrors.APIError 4XX, 5XX */*

Get

Consumer detail including their aggregated counts with the connections they have authorized.

Example Usage

package main

import(
	"context"
	"os"
	sdkgo "github.com/apideck-libraries/sdk-go"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := sdkgo.New(
        sdkgo.WithSecurity(os.Getenv("APIDECK_API_KEY")),
        sdkgo.WithConsumerID("test-consumer"),
        sdkgo.WithAppID("dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX"),
    )

    res, err := s.Vault.Consumers.Get(ctx, "test_user_id")
    if err != nil {
        log.Fatal(err)
    }
    if res.GetConsumerResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description Example
ctx context.Context ✔️ The context to use for the request.
consumerID string ✔️ ID of the consumer to return test_user_id
opts []operations.Option The options for this request.

Response

*operations.VaultConsumersOneResponse, error

Errors

Error Type Status Code Content Type
apierrors.BadRequestResponse 400 application/json
apierrors.UnauthorizedResponse 401 application/json
apierrors.PaymentRequiredResponse 402 application/json
apierrors.NotFoundResponse 404 application/json
apierrors.UnprocessableResponse 422 application/json
apierrors.APIError 4XX, 5XX */*

Update

Update consumer metadata such as name and email.

Example Usage

package main

import(
	"context"
	"os"
	sdkgo "github.com/apideck-libraries/sdk-go"
	"github.com/apideck-libraries/sdk-go/models/components"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := sdkgo.New(
        sdkgo.WithSecurity(os.Getenv("APIDECK_API_KEY")),
        sdkgo.WithConsumerID("test-consumer"),
        sdkgo.WithAppID("dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX"),
    )

    res, err := s.Vault.Consumers.Update(ctx, "test_user_id", components.UpdateConsumerRequest{
        Metadata: &components.ConsumerMetadata{
            AccountName: sdkgo.String("SpaceX"),
            UserName: sdkgo.String("Elon Musk"),
            Email: sdkgo.String("[email protected]"),
            Image: sdkgo.String("https://www.spacex.com/static/images/share.jpg"),
        },
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.UpdateConsumerResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description Example
ctx context.Context ✔️ The context to use for the request.
consumerID string ✔️ ID of the consumer to return test_user_id
updateConsumerRequest components.UpdateConsumerRequest ✔️ N/A
opts []operations.Option The options for this request.

Response

*operations.VaultConsumersUpdateResponse, error

Errors

Error Type Status Code Content Type
apierrors.BadRequestResponse 400 application/json
apierrors.UnauthorizedResponse 401 application/json
apierrors.PaymentRequiredResponse 402 application/json
apierrors.NotFoundResponse 404 application/json
apierrors.UnprocessableResponse 422 application/json
apierrors.APIError 4XX, 5XX */*

Delete

Delete consumer and all their connections, including credentials.

Example Usage

package main

import(
	"context"
	"os"
	sdkgo "github.com/apideck-libraries/sdk-go"
	"log"
)

func main() {
    ctx := context.Background()
    
    s := sdkgo.New(
        sdkgo.WithSecurity(os.Getenv("APIDECK_API_KEY")),
        sdkgo.WithConsumerID("test-consumer"),
        sdkgo.WithAppID("dSBdXd2H6Mqwfg0atXHXYcysLJE9qyn1VwBtXHX"),
    )

    res, err := s.Vault.Consumers.Delete(ctx, "test_user_id")
    if err != nil {
        log.Fatal(err)
    }
    if res.DeleteConsumerResponse != nil {
        // handle response
    }
}

Parameters

Parameter Type Required Description Example
ctx context.Context ✔️ The context to use for the request.
consumerID string ✔️ ID of the consumer to return test_user_id
opts []operations.Option The options for this request.

Response

*operations.VaultConsumersDeleteResponse, error

Errors

Error Type Status Code Content Type
apierrors.BadRequestResponse 400 application/json
apierrors.UnauthorizedResponse 401 application/json
apierrors.PaymentRequiredResponse 402 application/json
apierrors.NotFoundResponse 404 application/json
apierrors.UnprocessableResponse 422 application/json
apierrors.APIError 4XX, 5XX */*