splunk-cloud-sdk-go

module
v1.11.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2021 License: Apache-2.0

README

Splunk Cloud Services SDK for Go

Go Report Card GoDoc

The Splunk Cloud Services software development kit (SDK) for Go contains library code and examples to enable you to build apps using the Splunk Cloud Services with the Go programming language.

Note: This SDK is not used for Splunk Enterprise or Splunk Cloud development. For information about developing apps and add-ons for those products, see the Splunk Developer Portal for Splunk Enterprise.

Splunk Cloud Services CLI

Splunk Cloud Services CLI, scloud, is a command-line tool for developers to make API calls to Splunk Cloud Services.

For more information about Splunk Cloud Services CLI, see the Splunk Developer Portal.

Terms of Service

Log in to Splunk Investigate and accept the Terms of Service when prompted.

Get started

Install Go and Go tools
  1. Install Go 1.11 or later from the Getting Started page on the Go Programmming Language website.

  2. Install recommended tools for Go by running the following commands:

    $ go get golang.org/x/lint/golint
    $ go get -u golang.org/x/tools/cmd/goimports
    
Initialize your project

Initialize your project using Go modules for dependency support. Your project can be located outside of the $GOPATH/src directory. For more about modules, see Go 1.11 Modules on the GitHub website.

  1. If your project is within your $GOPATH, set GO111MODULE=on in your environment variables.

  2. Initialize your project by running the following commands, but replace the <github.com/example/myproject> path with your Git host, organization, user name, and project name as appropriate:

    $ mkdir myproject && cd myproject
    $ go mod init <github.com/example/myproject>
    
  3. Create a main.go file within your project directory containing the following code:

    package main
    
    import (
        "fmt"
        "os"
    
        "github.com/splunk/splunk-cloud-sdk-go/sdk"
        "github.com/splunk/splunk-cloud-sdk-go/services"
        "github.com/splunk/splunk-cloud-sdk-go/services/identity"
    )
    
    func main() {
        checkForTenantToken()
        // Initialize the client
        client, err := sdk.NewClient(&services.Config{
            Token:  os.Getenv("BEARER_TOKEN"),
            Tenant: os.Getenv("TENANT"),
        })
        exitOnErr(err)
        // Validate access to Splunk Cloud Services and tenant
        query := identity.ValidateTokenQueryParams{Include: identity.ValidateTokeninclude{"principal", "tenant"}}
        info, err := client.IdentityService.ValidateToken(&query)
        exitOnErr(err)
        fmt.Println("name: " + info.Name)
        fmt.Println("principal name: " + info.Principal.Name)
        fmt.Println("tenant name: " + info.Tenant.Name)
    }
    
    func exitOnErr(err error) {
        if err != nil {
            fmt.Println(err)
            os.Exit(1)
        }
    }
    
    func checkForTenantToken() {
        if os.Getenv("BEARER_TOKEN") == "" {
            exitOnErr(fmt.Errorf("$BEARER_TOKEN must be set"))
        }
        if os.Getenv("TENANT") == "" {
            exitOnErr(fmt.Errorf("$TENANT must be set"))
        }
    }
    
  4. Set your access token and tenant.

    • Retrieve your access token from the Splunk Cloud Console.

      • Log in with your email address.
      • Enter/Choose your tenant.
      • Navigate to the Settings page from the top-right dropdown.
      • Under Authorization / Access Token click Copy to clipboard to copy your token.
    • Run the following command, replacing <accessToken> and <tenant> with your values:

      $ export BEARER_TOKEN=<accessToken>
      $ export TENANT=<tenant>
      
  5. Build and run your project by running the following commands, where <project> is the name of your project, and <me@example.com> is your user name:

    $ go build
    $ ./<project>
    name: <me@example.com>
    principal name: <me@example.com>
    tenant name: <mytenant>
    

Documentation

For general documentation, see the Splunk Developer Portal.

For reference documentation, see the Splunk Cloud Services SDK for Go API Reference.

Contributing

Do not directly edit any source file with _generated in the name because that file was generated from service specifications.

Contact

If you have questions, reach out to us on Slack in the #sdc channel or email us at devinfo@splunk.com.

Directories

Path Synopsis
cmd
scloud/auth/statik
Package statik contains static assets.
Package statik contains static assets.
scloud/cmd/action
Package action -- generated by scloudgen !! DO NOT EDIT !!
Package action -- generated by scloudgen !! DO NOT EDIT !!
scloud/cmd/appregistry
Package appregistry -- generated by scloudgen !! DO NOT EDIT !!
Package appregistry -- generated by scloudgen !! DO NOT EDIT !!
scloud/cmd/catalog
Package catalog -- generated by scloudgen !! DO NOT EDIT !!
Package catalog -- generated by scloudgen !! DO NOT EDIT !!
scloud/cmd/collect
Package collect -- generated by scloudgen !! DO NOT EDIT !!
Package collect -- generated by scloudgen !! DO NOT EDIT !!
scloud/cmd/forwarders
Package forwarders -- generated by scloudgen !! DO NOT EDIT !!
Package forwarders -- generated by scloudgen !! DO NOT EDIT !!
scloud/cmd/identity
Package identity -- generated by scloudgen !! DO NOT EDIT !!
Package identity -- generated by scloudgen !! DO NOT EDIT !!
scloud/cmd/ingest
Package ingest -- generated by scloudgen !! DO NOT EDIT !!
Package ingest -- generated by scloudgen !! DO NOT EDIT !!
scloud/cmd/kvstore
Package kvstore -- generated by scloudgen !! DO NOT EDIT !!
Package kvstore -- generated by scloudgen !! DO NOT EDIT !!
scloud/cmd/ml
Package ml -- generated by scloudgen !! DO NOT EDIT !!
Package ml -- generated by scloudgen !! DO NOT EDIT !!
scloud/cmd/provisioner
Package provisioner -- generated by scloudgen !! DO NOT EDIT !!
Package provisioner -- generated by scloudgen !! DO NOT EDIT !!
scloud/cmd/search
Package search -- generated by scloudgen !! DO NOT EDIT !!
Package search -- generated by scloudgen !! DO NOT EDIT !!
scloud/cmd/streams
Package streams -- generated by scloudgen !! DO NOT EDIT !!
Package streams -- generated by scloudgen !! DO NOT EDIT !!
scloud/pkg/action
Package action -- generated by scloudgen !! DO NOT EDIT !!
Package action -- generated by scloudgen !! DO NOT EDIT !!
scloud/pkg/appregistry
Package appregistry -- generated by scloudgen !! DO NOT EDIT !!
Package appregistry -- generated by scloudgen !! DO NOT EDIT !!
scloud/pkg/catalog
Package catalog -- generated by scloudgen !! DO NOT EDIT !!
Package catalog -- generated by scloudgen !! DO NOT EDIT !!
scloud/pkg/collect
Package collect -- generated by scloudgen !! DO NOT EDIT !!
Package collect -- generated by scloudgen !! DO NOT EDIT !!
scloud/pkg/forwarders
Package forwarders -- generated by scloudgen !! DO NOT EDIT !!
Package forwarders -- generated by scloudgen !! DO NOT EDIT !!
scloud/pkg/identity
Package identity -- generated by scloudgen !! DO NOT EDIT !!
Package identity -- generated by scloudgen !! DO NOT EDIT !!
scloud/pkg/ingest
Package ingest -- generated by scloudgen !! DO NOT EDIT !!
Package ingest -- generated by scloudgen !! DO NOT EDIT !!
scloud/pkg/kvstore
Package kvstore -- generated by scloudgen !! DO NOT EDIT !!
Package kvstore -- generated by scloudgen !! DO NOT EDIT !!
scloud/pkg/ml
Package ml -- generated by scloudgen !! DO NOT EDIT !!
Package ml -- generated by scloudgen !! DO NOT EDIT !!
scloud/pkg/provisioner
Package provisioner -- generated by scloudgen !! DO NOT EDIT !!
Package provisioner -- generated by scloudgen !! DO NOT EDIT !!
scloud/pkg/search
Package search -- generated by scloudgen !! DO NOT EDIT !!
Package search -- generated by scloudgen !! DO NOT EDIT !!
scloud/pkg/streams
Package streams -- generated by scloudgen !! DO NOT EDIT !!
Package streams -- generated by scloudgen !! DO NOT EDIT !!
examples
logging
This example demonstrates how to setup logging of requests/responses with the sdk using the standard Go "log" library.
This example demonstrates how to setup logging of requests/responses with the sdk using the standard Go "log" library.
mock
This example demonstrates how to setup the Splunk Cloud SDK for Go to return mocked responses rather than sending requests to the Splunk Cloud Platform itself.
This example demonstrates how to setup the Splunk Cloud SDK for Go to return mocked responses rather than sending requests to the Splunk Cloud Platform itself.
Package services implements a service client which is used to communicate with Splunk Cloud endpoints, each service being split into its own package.
Package services implements a service client which is used to communicate with Splunk Cloud endpoints, each service being split into its own package.
action
This files contains models that can't be auto-generated from codegen
This files contains models that can't be auto-generated from codegen
ml
test

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL