Skip to content

SDK Initialization


title: “Go SDK Overview” description: “Go SDK Overview for Trimble Access Management” lead: "" date: 2023-06-12T13:46:25-06:00 lastmod: 2023-06-12T13:46:25-06:00 draft: false images: [] menu: docs: parent: “go” weight: 331 toc: true

SDK Initialization

The Go SDK provides an interface to interact with Trimble Access Management by allowing users to register applications, packages, and query policy decisions from a running appliance.

To use the SDK, call the tamsdk.New function in the tamsdk package.

Usage

Using the SDK requires creating an instance of the SDK interface by using the tamsdk.New function. The environment, application credentials, and the appliance URL are required to fully initialize the SDK. In the following example these values have been defined as environment variables.

tam, err := tamsdk.New(tamsdk.DevelopmentEnvironment, os.Getenv("CLIENT_ID"), os.Getenv("CLIENT_SECRET"), os.Getenv("APPLIANCE_URL"))
if err != nil {
// Handle SDK initialization error...
}

Once the SDK has been initialized, the PackageRegistration, ApplicationRegistration, PackageMetadataUpdate, and Decision functions may be called on the tamsdk.SDK instance.

p, err := tam.RegisterPackage(ctx, namespace, policyFilePath, policyTestFilePath, remoteDataSources, contactName, contactEmail, packageDescription, "", false, packageDependencyNamespaces)
if err != nil {
// Handle package registration error...
}
err := tam.RegisterApplication(ctx, namespaces)
if err != nil {
// Handle application registration error...
}
p, err := tam.UpdatePackageMetadata(c, namespace, revision, contactName, contactEmail, description, example, isDiscoverable)
if err != nil {
// Handle update error error...
}
result, err := tam.Decision(ctx, namespace, rule, input)
if err != nil {
// Handle decision error...
}

Go Gin Middleware

The Go SDK can also be used as middleware with the Gin Web Framework. The tammiddleware.Middleware function returns a handler that can be added to the middleware chain. In the example below, the variable tam is an instance of the tamsdk.SDK interface used to initialize middleware handler.

tamMiddleware, err := tammiddleware.Middleware(tam, packageNamespace, rule)
if err != nil {
// Handle middleware initialization error...
}
// Set up gin to use TAM middleware
r := gin.Default()
r.Use(tamMiddleware)

Examples

Examples of how to use the Go SDK can be found on Trimble GitHub Enterprise.