Skip to content

Latest commit

 

History

History
65 lines (47 loc) · 1.91 KB

README.md

File metadata and controls

65 lines (47 loc) · 1.91 KB

Library for PX-Backup APIs

This repo contains the definition for the gRPC and REST APIs to communicate with PX-Backup.

The proto definition for gRPC and REST gateway can be found here.

The generated client code is present under github.com/portworx/px-backup-api/pkg/apis/v1.

Building

After updating the proto definitions, run make docker-build-proto to regenerate the client libraries and swagger definitions.

Run make start-build-container to exec into the docker container and run any make commands

Usage

Authentication

All APIs to PX-Backup need to be authenticated using a token from an OIDC provider. You can use the oauth2 package to fetch the token. Some examples to fetch the token can be found here.

Example to fetch a list of Clusters configured with PX-Backup

package cluster

import (
    "context"
    "fmt"

    "github.com/libopenstorage/openstorage/pkg/grpcserver"
    api "github.com/portworx/px-backup-api/pkg/apis/v1"
    "google.golang.org/grpc/metadata"
)

func getClusterList(addr string, token string, orgID string) (*api.ClusterEnumerateResponse, error) {

    // Connect to the PX-Backup server
    conn, err := grpcserver.Connect(addr, nil)
    if err != nil {
        return nil, fmt.Errorf("failed to connect to gRPC handler: %v", err)
    }
    
    // Create a context with the token
    md := metadata.New(map[string]string{
        "authorization": "bearer " + token,
    })
    ctx := metadata.NewOutgoingContext(context.Background(), md)
    
    // Create a client and make the gRPC API call
    cluster := api.NewClusterClient(conn)
    return cluster.Enumerate(
        ctx,
        &api.ClusterEnumerateRequest{
            OrgId: orgID,
        },
    )
}