Documentation
¶
Overview ¶
Package destination provides a client for the SAP BTP Destination Service REST API. It resolves named destinations and returns typed structs containing the connection parameters and auth tokens.
Usage:
import "github.com/bluefunda/btp-go/destination"
client := destination.NewClient(
"https://destination-configuration.cfapps.eu10.hana.ondemand.com",
myTokenSource, // satisfies destination.TokenSource
nil, // use http.DefaultClient
)
dest, err := client.Find(ctx, "MY_SFTP_DEST")
if err != nil {
log.Fatal(err)
}
// dest.Host, dest.Port, dest.Properties["User"] etc.
The package is stdlib-only and has zero third-party dependencies.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthToken ¶
type AuthToken struct {
// Type is the token type, e.g. "Bearer".
Type string `json:"type"`
// Value is the raw token string.
Value string `json:"value"`
// HTTPHeader holds the header key and value that should be sent with
// requests to the target system.
HTTPHeader struct {
Key string `json:"key"`
Value string `json:"value"`
} `json:"http_header"`
// ExpiresIn is the remaining token lifetime in seconds.
ExpiresIn int `json:"expires_in,string"`
// Error is non-empty when the Destination Service could not obtain a
// token for this destination.
Error string `json:"error"`
}
AuthToken represents a single authentication token returned by the Destination Service alongside a resolved destination.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client for the SAP BTP Destination Service. It is safe for concurrent use.
func NewClient ¶
func NewClient(serviceURL string, tokens TokenSource, httpClient *http.Client) *Client
NewClient creates a new Client. serviceURL is the base URL from the destination service binding (e.g. "https://destination-configuration.cfapps.eu10.hana.ondemand.com"). When httpClient is nil, http.DefaultClient is used.
func (*Client) Find ¶
Find resolves a destination by name from the subaccount-level Destination Service. It calls tokens.Token(ctx) to obtain a bearer JWT for the API request.
Example ¶
package main
import (
"context"
"fmt"
"log"
"github.com/bluefunda/btp-go/destination"
)
// staticToken is a stub TokenSource for illustration.
type staticToken struct{ value string }
func (s staticToken) Token(_ context.Context) (string, error) { return s.value, nil }
func main() {
client := destination.NewClient(
"https://destination-configuration.cfapps.eu10.hana.ondemand.com",
staticToken{"my-bearer-token"},
nil, // use http.DefaultClient
)
dest, err := client.Find(context.Background(), "MY_SFTP_DEST")
if err != nil {
log.Fatal(err)
}
fmt.Printf("host=%s port=%s user=%s\n", dest.Host, dest.Port, dest.User)
}
Output:
func (*Client) ListAll ¶ added in v0.2.0
func (c *Client) ListAll(ctx context.Context) ([]Destination, error)
ListAll fetches every destination visible to the service binding: both the subaccount-level and the instance-level scopes. Results from both scopes are merged into a single slice (subaccount first, then instance). Each call invokes tokens.Token once and makes two HTTP requests.
type Destination ¶
type Destination struct {
// Name is the logical destination name as configured in the BTP cockpit.
Name string
// Type is the destination type: "HTTP", "TCP", "MAIL", "RFC", or "LDAP".
Type string
// ProxyType describes connectivity: "Internet", "OnPremise", or "PrivateLink".
ProxyType string
// Authentication is the authentication method configured on the destination.
Authentication string
// URL is populated for HTTP destinations.
URL string
// Host is populated for TCP (and on-prem) destinations.
Host string
// Port is populated for TCP destinations (string to preserve leading zeros
// and avoid uint16 overflow at parse time).
Port string
// User is the username for authentication (SSH/FTP destinations).
User string
// Password is the credential for authentication (SSH/FTP destinations).
Password string
// Path is the remote path configured on the destination (e.g. SFTP root dir).
Path string
// CloudConnectorLocationID holds the SCC location the destination routes
// through. Empty string means the default location.
CloudConnectorLocationID string
// Properties contains all remaining key/value pairs from the
// destinationConfiguration map that are not mapped to named fields above.
// Consumers use this for service-specific keys such as "User", "sshKey",
// "RemotePath", etc.
Properties map[string]string
// AuthTokens holds the OAuth/SAML tokens that the Destination Service may
// return alongside the destination configuration.
AuthTokens []AuthToken
}
Destination holds the resolved fields of a BTP Destination Service entry.
func (*Destination) BestAuthToken ¶ added in v0.2.0
func (d *Destination) BestAuthToken() (AuthToken, bool)
BestAuthToken returns the first AuthToken whose Error field is empty. The Destination Service may return multiple tokens (e.g. one per auth method); this helper picks the first valid one so callers don't have to iterate and filter manually. Returns (token, true) when a valid token is found, (AuthToken{}, false) when AuthTokens is empty or all entries carry errors.
type Finder ¶ added in v0.2.0
type Finder interface {
Find(ctx context.Context, name string) (*Destination, error)
}
Finder is implemented by any value that can look up a named destination. *Client satisfies this interface; consumers can also supply a stub in tests without spinning up an HTTP server.
type TokenSource ¶
TokenSource is the interface for obtaining a bearer JWT. It is defined locally so that the destination module remains stdlib-only. Any concrete type that implements Token(ctx) (string, error) satisfies it — including xsuaa.NewClientCredentialsSource().