### Install goldmark-meta Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/yuin/goldmark-meta/README.md Install the goldmark-meta package using go get. ```bash go get github.com/yuin/goldmark-meta ``` -------------------------------- ### Install Goldmark Frontmatter Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/go.abhg.dev/goldmark/frontmatter/README.md Install the goldmark-frontmatter extension using go get. ```bash go get go.abhg.dev/goldmark/frontmatter@latest ``` -------------------------------- ### Install go-version Library Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/go-version/README.md Install the go-version library using the standard go get command. ```bash $ go get github.com/hashicorp/go-version ``` -------------------------------- ### Install tagparser Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/vmihailenco/tagparser/v2/README.md Install the tagparser library using go get. ```shell go get github.com/vmihailenco/tagparser/v2 ``` -------------------------------- ### Install go-isatty Package Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/mattn/go-isatty/README.md Install the go-isatty package using the go get command. ```bash go get github.com/mattn/go-isatty ``` -------------------------------- ### Install msgpack/v5 Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/vmihailenco/msgpack/v5/README.md Install the msgpack/v5 library using go get. Ensure you are using Go modules. ```shell go get github.com/vmihailenco/msgpack/v5 ``` -------------------------------- ### Install xstrings Package Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/huandu/xstrings/README.md Use `go get` to install the xstrings library. This command fetches and installs the package and its dependencies. ```go go get github.com/huandu/xstrings ``` -------------------------------- ### Install Golang Color Package Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/fatih/color/README.md Use 'go get' to install the color package. ```bash go get github.com/fatih/color ``` -------------------------------- ### Quickstart: Marshal and Unmarshal Example Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/vmihailenco/msgpack/README.md Demonstrates basic usage of msgpack.Marshal and msgpack.Unmarshal to encode and decode a Go struct. Ensure error handling for production code. ```go func ExampleMarshal() { type Item struct { Foo string } b, err := msgpack.Marshal(&Item{Foo: "bar"}) if err != nil { panic(err) } var item Item err = msgpack.Unmarshal(b, &item) if err != nil { panic(err) } fmt.Println(item.Foo) // Output: bar } ``` -------------------------------- ### Install copystructure Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/mitchellh/copystructure/README.md Install the copystructure library using the standard Go get command. ```bash $ go get github.com/mitchellh/copystructure ``` -------------------------------- ### Install Mergo Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/imdario/mergo/README.md Install the Mergo library using go get. This command fetches and installs the package. ```go go get github.com/imdario/mergo ``` -------------------------------- ### Install doublestar Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/bmatcuk/doublestar/v4/README.md Install the doublestar package using go get. ```bash go get github.com/bmatcuk/doublestar/v4 ``` -------------------------------- ### Install mapstructure Go Library Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/mitchellh/mapstructure/README.md Use standard 'go get' command to install the mapstructure library. ```bash go get github.com/mitchellh/mapstructure ``` -------------------------------- ### Simple HTTP Mocking Example Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/jarcoal/httpmock/README.md Demonstrates basic mocking of GET requests with exact and regular expression URL matching. Shows how to activate mocking, register responders, and retrieve call count information. ```go func TestFetchArticles(t *testing.T) { httpmock.Activate(t) // Exact URL match httpmock.RegisterResponder("GET", "https://api.mybiz.com/articles", httpmock.NewStringResponder(200, `[{"id": 1, "name": "My Great Article"}]`)) // Regexp match (could use httpmock.RegisterRegexpResponder instead) httpmock.RegisterResponder("GET", `=~^https://api\.mybiz\.com/articles/id/\d+\z`, httpmock.NewStringResponder(200, `{"id": 1, "name": "My Great Article"}`)) // do stuff that makes a request to articles ... // get count info httpmock.GetTotalCallCount() // get the amount of calls for the registered responder info := httpmock.GetCallCountInfo() info["GET https://api.mybiz.com/articles"] // number of GET calls made to https://api.mybiz.com/articles info["GET https://api.mybiz.com/articles/id/12"] // number of GET calls made to https://api.mybiz.com/articles/id/12 info[`GET =~^https://api\.mybiz\.com/articles/id/\d+\z`] // number of GET calls made to https://api.mybiz.com/articles/id/ } ``` -------------------------------- ### Install uuid Package Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/google/uuid/README.md Use 'go get' to install the uuid package. This command fetches and installs the package and its dependencies. ```sh go get github.com/google/uuid ``` -------------------------------- ### Install Levenshtein Package Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/agext/levenshtein/README.md Use 'go get' to install the Levenshtein package for your Go project. ```go go get github.com/agext/levenshtein ``` -------------------------------- ### Basic CLI Application Setup Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/cli/README.md This Go code demonstrates the basic setup for a CLI application using the hashicorp/cli library. It initializes a new CLI, sets arguments, and defines commands. ```go package main import ( "log" "os" "github.com/hashicorp/cli" ) func main() { c := cli.NewCLI("app", "1.0.0") c.Args = os.Args[1:] c.Commands = map[string]cli.CommandFactory{ "foo": fooCommandFactory, "bar": barCommandFactory, } exitStatus, err := c.Run() if err != nil { log.Println(err) } os.Exit(exitStatus) } ``` -------------------------------- ### Install Goldmark Markdown Parser Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/yuin/goldmark/README.md Install the Goldmark package using the go get command. This is the initial step before using the library in your Go project. ```bash $ go get github.com/yuin/goldmark ``` -------------------------------- ### Installer Methods Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/hc-install/README.md The Installer object provides high-level methods for managing HashiCorp binary installations. These methods allow users to ensure a specific version of a product is installed or to directly install a product version. ```APIDOC ## Installer Methods The `Installer` offers a few high-level methods: ### `Ensure(context.Context, []src.Source)` **Description**: Finds, installs, or builds a product version based on the provided sources. ### `Install(context.Context, []src.Installable)` **Description**: Installs a product version using the specified installable sources. ``` -------------------------------- ### Install TOML Package Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/BurntSushi/toml/README.md Install the TOML package using go get. This command fetches the latest version of the library. ```bash go get github.com/BurntSushi/toml@latest ``` -------------------------------- ### Singleton Tracer Initialization Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/opentracing/opentracing-go/README.md Initialize the global OpenTracing tracer as early as possible in your application's main function. This is the simplest starting point for tracer setup. ```go import "github.com/opentracing/opentracing-go" import ".../some_tracing_impl" func main() { opentracing.SetGlobalTracer( // tracing impl specific: some_tracing_impl.New(...), ) ... } ``` -------------------------------- ### Enhanced GET Request with Query Parameters and Headers Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/go-resty/resty/v2/README.md Perform a GET request with custom query parameters, headers, and authentication token. This example demonstrates how to set multiple query parameters and an authorization token. ```go // Create a Resty Client client := resty.New() resp, err := client.R(). SetQueryParams(map[string]string{ "page_no": "1", "limit": "20", "sort":"name", "order": "asc", "random":strconv.FormatInt(time.Now().Unix(), 10), }). SetHeader("Accept", "application/json"). SetAuthToken("BC594900518B4F7EAC75BD37F019E08FBC594900518B4F7EAC75BD37F019E08F"). Get("/search_result") ``` -------------------------------- ### Ginkgo Example Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/jarcoal/httpmock/README.md This example demonstrates setting up and tearing down httpmock using Ginkgo's BeforeSuite, BeforeEach, and AfterSuite hooks. It shows how to block all requests and reset mocks between tests. ```go // article_suite_test.go import ( // ... "github.com/jarcoal/httpmock" ) // ... var _ = BeforeSuite(func() { // block all HTTP requests httpmock.Activate() }) var _ = BeforeEach(func() { // remove any mocks httpmock.Reset() }) var _ = AfterSuite(func() { httpmock.DeactivateAndReset() }) // article_test.go import ( // ... "github.com/jarcoal/httpmock" ) var _ = Describe("Articles", func() { It("returns a list of articles", func() { httpmock.RegisterResponder("GET", "https://api.mybiz.com/articles.json", httpmock.NewStringResponder(200, `[{"id": 1, "name": "My Great Article"}]`)) // do stuff that makes a request to articles.json }) }) ``` -------------------------------- ### Install gocomplete for Go Command Completion Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/posener/complete/readme.md Installs the gocomplete tool for bash completion of the Go command line. Restart your shell after installation. ```bash go get -u github.com/posener/complete/gocomplete gocomplete -install ``` -------------------------------- ### Install msgpack Package Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/vmihailenco/msgpack/README.md Use this command to install the msgpack package for your Go project. ```shell go get -u github.com/vmihailenco/msgpack ``` -------------------------------- ### Enable Key Conversion for Basic/Manual Scaling Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/google.golang.org/appengine/README.md This start handler enables key conversion for all handlers in the service for basic and manual scaling App Engine environments. ```go http.HandleFunc("/_ah/start", func(w http.ResponseWriter, r *http.Request) { datastore.EnableKeyConversion(appengine.NewContext(r)) }) ``` -------------------------------- ### hc-install CLI Usage Help Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/hc-install/README.md Displays the usage information for the hc-install CLI, outlining available commands and options for installing HashiCorp products. ```text Usage: hc-install install [options] -version This command installs a HashiCorp product. Options: -version [REQUIRED] Version of product to install. -path Path to directory where the product will be installed. Defaults to current working directory. -log-file Path to file where logs will be written. /dev/stdout or /dev/stderr can be used to log to STDOUT/STDERR. ``` -------------------------------- ### Build and Test with Bazel Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/go-resty/resty/v2/README.md Example command for building and testing the Resty library using Bazel. ```shell bazel test :resty_test ``` -------------------------------- ### Source Types Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/hc-install/README.md The Installer methods accept various Source types, each with different trade-offs for obtaining HashiCorp binaries. ```APIDOC ## Source Types The `Installer` methods accept a number of different `Source` types. Each comes with different trade-offs described below. ### `fs.{AnyVersion,ExactVersion,Version}` **Description**: Finds a binary in `$PATH` (or additional paths). **Pros**: Convenient when the product is already installed and managed by the user. **Cons**: Relies on a single version; not recommended for environments where product installation is not controlled by the user (e.g., default GitHub Actions images). ### `releases.{LatestVersion,ExactVersion}` **Description**: Downloads, verifies & installs any known product from `releases.hashicorp.com`. **Pros**: Fast and reliable for obtaining pre-built versions, allows installation of enterprise versions. **Cons**: Consumes bandwidth, disk space, and time; potentially less stable builds. ### `checkpoint.LatestVersion` **Description**: Downloads, verifies & installs any known product available in HashiCorp Checkpoint. **Pros**: Checkpoint typically contains only stable product versions. **Cons**: Consumes bandwidth, disk space, and time; currently does not allow installation of old or enterprise versions. ### `build.GitRevision` **Description**: Clones raw source code and builds the product from it. **Pros**: Useful for catching bugs and incompatibilities early. **Cons**: Building from scratch consumes significant time and resources; build instructions may not always be up-to-date; increased likelihood of build containing bugs prior to release; CI builds can be fragile. ``` -------------------------------- ### Delimiter Length Example Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/go.abhg.dev/goldmark/frontmatter/README.md Example showing that the front matter block must end with the same number of delimiter instances as it started with. ```markdown --------------------------- title: goldmark-frontmatter tags: [markdown, goldmark] --------------------------- ``` -------------------------------- ### Get App Engine Go SDK Package Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/google.golang.org/appengine/CONTRIBUTING.md Use 'go get -d' to download the App Engine Go SDK source code. This command fetches the package without installing it. ```bash go get -d google.golang.org/appengine ``` -------------------------------- ### hc-install CLI Installation Confirmation Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/hc-install/README.md Shows the output message from hc-install after successfully installing a product, indicating the product name, version, and installation path. ```text hc-install: will install terraform@1.3.7 installed terraform@1.3.7 to /current/working/dir/terraform ``` -------------------------------- ### Custom Decoder Implementation Example Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/kelseyhightower/envconfig/README.md Provides an example of a custom decoder for a type that implements the envconfig.Decoder interface, allowing custom parsing logic. ```Bash export DNS_SERVER=8.8.8.8 ``` ```Go type IPDecoder net.IP func (ipd *IPDecoder) Decode(value string) error { *ipd = IPDecoder(net.ParseIP(value)) return nil } type DNSConfig struct { Address IPDecoder `envconfig:"DNS_SERVER"` } ``` -------------------------------- ### CreateGatewaySetupToken Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/atko-pam/pam-sdk-go/client/pam/README.md Creates a setup token for a gateway. ```APIDOC ## POST /v1/teams/{team_name}/gateway_setup_tokens ### Description Create a gateway setup token. ### Method Post ### Endpoint /v1/teams/{team_name}/gateway_setup_tokens ``` -------------------------------- ### PUT Method Example Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/go-resty/resty/v2/README.md Demonstrates how to send a PUT request, typically used for updating resources. The example shows sending a struct as the request body. ```APIDOC ## PUT Request ### Description Sends a PUT request with a struct as the request body. The content type defaults to `application/json`. ### Method PUT ### Endpoint `https://myapp.com/article/1234` ### Request Body - **(struct)** - A Go struct representing the resource to be updated. ### Request Example ```go resp, err := client.R(). SetBody(Article{ Title: "go-resty", Content: "This is my article content, oh ya!", Author: "Jeevanandam M", Tags: []string{"article", "sample", "resty"}, }). SetAuthToken("C6A79608-782F-4ED0-A11D-BD82FAD829CD"). SetError(&Error{}). Put("https://myapp.com/article/1234") ``` ``` -------------------------------- ### Use the Global Logger Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/go-hclog/README.md Access and use the default global logger instance to log messages. This is the simplest way to start logging. ```go hclog.Default().Info("hello world") ``` -------------------------------- ### DELETE, HEAD, OPTIONS Request Examples with Go-Resty Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/go-resty/resty/v2/README.md Provides examples for DELETE, HEAD, and OPTIONS requests. The DELETE method can optionally include a JSON payload. Client-level settings for auth tokens or errors can be omitted. ```go // Create a Resty Client client := resty.New() // DELETE a article // No need to set auth token, error, if you have client level settings resp, err := client.R(). SetAuthToken("C6A79608-782F-4ED0-A11D-BD82FAD829CD"). SetError(&Error{}). // or SetError(Error{}). Delete("https://myapp.com/articles/1234") ``` ```go // DELETE a articles with payload/body as a JSON string // No need to set auth token, error, if you have client level settings resp, err := client.R(). SetAuthToken("C6A79608-782F-4ED0-A11D-BD82FAD829CD"). SetError(&Error{}). // or SetError(Error{}). SetHeader("Content-Type", "application/json"). SetBody(`{article_ids: [1002, 1006, 1007, 87683, 45432] }`). Delete("https://myapp.com/articles") ``` ```go // HEAD of resource // No need to set auth token, if you have client level settings resp, err := client.R(). SetAuthToken("C6A79608-782F-4ED0-A11D-BD82FAD829CD"). Head("https://myapp.com/videos/hi-res-video") ``` ```go // OPTIONS of resource // No need to set auth token, if you have client level settings resp, err := client.R(). SetAuthToken("C6A79608-782F-4ED0-A11D-BD82FAD829CD"). Options("https://myapp.com/servers/nyc-dc-01") ``` -------------------------------- ### Install Terraform using hc-install CLI Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/hc-install/README.md Installs a specific version of the Terraform product using the hc-install CLI. The version and product name are specified as arguments. ```sh hc-install install -version 1.3.7 terraform ``` -------------------------------- ### Set Environment Variables for envconfig Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/kelseyhightower/envconfig/README.md Example of setting environment variables that envconfig will process. Ensure variables are prefixed with 'MYAPP_'. ```Bash export MYAPP_DEBUG=false export MYAPP_PORT=8080 export MYAPP_USER=Kelsey export MYAPP_RATE="0.5" export MYAPP_TIMEOUT="3m" export MYAPP_USERS="rob,ken,robert" export MYAPP_COLORCODES="red:1,green:2,blue:3" ``` -------------------------------- ### Install the Provider Locally Source: https://github.com/okta/terraform-provider-oktapam/blob/master/README.md Builds and installs the provider to the local Terraform plugin directory. This makes the provider available for use in Terraform configurations. ```sh make install ``` -------------------------------- ### ToString Examples Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/spf13/cast/README.md Demonstrates converting various types to strings using cast.ToString. If conversion is not possible, an empty string is returned. ```go cast.ToString("mayonegg") // "mayonegg" cast.ToString(8) // "8" cast.ToString(8.31) // "8.31" cast.ToString([]byte("one time")) // "one time" cast.ToString(nil) // "" ``` ```go var foo interface{} = "one more time" cast.ToString(foo) // "one more time" ``` -------------------------------- ### Envconfig Struct Tag Support Example Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/kelseyhightower/envconfig/README.md Illustrates using struct tags for manual overrides, default values, required fields, and word splitting for environment variable names. ```Go type Specification struct { ManualOverride1 string `envconfig:"manual_override_1"` DefaultVar string `default:"foobar"` RequiredVar string `required:"true"` IgnoredVar string `ignored:"true"` AutoSplitVar string `split_words:"true"` RequiredAndAutoSplitVar string `required:"true" split_words:"true"` } ``` -------------------------------- ### HCL Native Syntax Example Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/hcl/v2/README.md Illustrates the native HCL syntax with attributes and hierarchical blocks for defining application configuration. ```hcl io_mode = "async" service "http" "web_proxy" { listen_addr = "127.0.0.1:8080" process "main" { command = ["/usr/local/bin/awesome-app", "server"] } process "mgmt" { command = ["/usr/local/bin/awesome-app", "mgmt"] } } ``` -------------------------------- ### StartActiveDirectoryAccountForceSync Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/atko-pam/pam-sdk-go/client/pam/README.md Start Active Directory account force sync. ```APIDOC ## PUT /v1/teams/{team_name}/resource_assignment/active_directory/{ad_connection_id}/force_sync ### Description Start Active Directory account force sync. ### Method PUT ### Endpoint /v1/teams/{team_name}/resource_assignment/active_directory/{ad_connection_id}/force_sync ``` -------------------------------- ### ListGatewaySetupTokens Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/atko-pam/pam-sdk-go/client/pam/README.md Lists all gateway setup tokens for a given team. ```APIDOC ## ListGatewaySetupTokens ### Description List all gateway setup tokens for a given team. ### Method GET ### Endpoint /v1/teams/{team_name}/gateway_setup_tokens ``` -------------------------------- ### Enable gRPC-Go Logging Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/google.golang.org/grpc/README.md Set environment variables to control the verbosity and severity of gRPC-Go logs. This example enables all logging. ```sh export GRPC_GO_LOG_VERBOSITY_LEVEL=99 export GRPC_GO_LOG_SEVERITY_LEVEL=info ``` -------------------------------- ### HCL JSON Representation Example Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/hcl/v2/README.md Shows the JSON equivalent of the HCL native syntax, demonstrating how HCL configurations can be represented in JSON. ```json { "io_mode": "async", "service": { "http": { "web_proxy": { "listen_addr": "127.0.0.1:8080", "process": { "main": { "command": ["/usr/local/bin/awesome-app", "server"] }, "mgmt": { "command": ["/usr/local/bin/awesome-app", "mgmt"] }, } } } } } ``` -------------------------------- ### FetchGatewaySetupToken Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/atko-pam/pam-sdk-go/client/pam/README.md Retrieves a specific gateway setup token. ```APIDOC ## GET /v1/teams/{team_name}/gateway_setup_tokens/{gateway_setup_token_id} ### Description Retrieve a gateway setup token. ### Method Get ### Endpoint /v1/teams/{team_name}/gateway_setup_tokens/{gateway_setup_token_id} ``` -------------------------------- ### Go Modules Installation Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/go-resty/resty/v2/README.md Add the resty library to your Go project dependencies using Go Modules. ```bash # Go Modules require github.com/go-resty/resty/v2 v2.16.5 ``` -------------------------------- ### Import Gateway Setup Token Source: https://github.com/okta/terraform-provider-oktapam/blob/master/docs/resources/gateway_setup_token.md Import is supported using the ID of this resource. This is useful for bringing existing resources under Terraform management. ```shell terraform import oktapam_gateway_setup_token.example {{id}} ``` -------------------------------- ### Ginkgo + Resty Example Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/jarcoal/httpmock/README.md This snippet integrates httpmock with Ginkgo and the Resty HTTP client. It shows how to activate httpmock for a non-default client and register a JSON responder. ```go // article_suite_test.go import ( // ... "github.com/jarcoal/httpmock" "github.com/go-resty/resty/v2" ) // ... // global client (using resty.New() creates a new transport each time, // so you need to use the same one here and when making the request) var client = resty.New() var _ = BeforeSuite(func() { // block all HTTP requests httpmock.ActivateNonDefault(client.GetClient()) }) var _ = BeforeEach(func() { // remove any mocks httpmock.Reset() }) var _ = AfterSuite(func() { httpmock.DeactivateAndReset() }) // article_test.go import ( // ... "github.com/jarcoal/httpmock" ) type Article struct { Status struct { Message string `json:"message"` Code int `json:"code"` } `json:"status"` } var _ = Describe("Articles", func() { It("returns a list of articles", func() { fixture := `{"status":{"message": "Your message", "code": 200}}` // have to use NewJsonResponder to get an application/json content-type // alternatively, create a go object instead of using json.RawMessage responder, _ := httpmock.NewJsonResponder(200, json.RawMessage(`{"status":{"message": "Your message", "code": 200}}`) fakeUrl := "https://api.mybiz.com/articles.json" httpmock.RegisterResponder("GET", fakeUrl, responder) // fetch the article into struct articleObject := &Article{} _, err := resty.R().SetResult(articleObject).Get(fakeUrl) // do stuff with the article object ... }) }) ``` -------------------------------- ### Test Helper Using go-testing-interface Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/mitchellh/go-testing-interface/README.md Example of a test helper function that accepts the testing.T interface from the go-testing-interface library. This allows the helper to be used with both standard *testing.T and the runtime version. ```go import "github.com/mitchellh/go-testing-interface" func TestHelper(t testing.T) { t.Fatal("I failed") } ``` -------------------------------- ### Link Legacy Provider (Terraform 0.12.x) Source: https://github.com/okta/terraform-provider-oktapam/blob/master/README.md Creates a symbolic link for Terraform 0.12.x users to use the installed provider binary. This is a one-time setup. ```sh make link_legacy ``` -------------------------------- ### Basic Radix Tree Usage in Go Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/armon/go-radix/README.md Demonstrates the creation of a new radix tree, insertion of key-value pairs, and performing a longest prefix match. Ensure the radix package is imported. ```go package main import ( "fmt" "github.com/armon/go-radix" ) func main() { // Create a tree r := radix.New() r.Insert("foo", 1) r.Insert("bar", 2) r.Insert("foobar", 2) // Find the longest prefix match m, _, _ := r.LongestPrefix("foozip") if m != "foo" { panic("should be foo") } fmt.Println("Longest prefix match found:", m) } ``` -------------------------------- ### Implement Bash Completion for a Custom Command Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/posener/complete/readme.md Example of using the 'complete' package to define bash completion for a custom command named 'run'. It demonstrates how to specify subcommands, flags with expected arguments, and global flags. ```go import "github.com/posener/complete" func main() { // create a Command object, that represents the command we want // to complete. run := complete.Command{ // Sub defines a list of sub commands of the program, // this is recursive, since every command is of type command also. Sub: complete.Commands{ // add a build sub command "build": complete.Command { // define flags of the build sub command Flags: complete.Flags{ // build sub command has a flag '-cpus', which // expects number of cpus after it. in that case // anything could complete this flag. "-cpus": complete.PredictAnything, }, }, }, // define flags of the 'run' main command Flags: complete.Flags{ // a flag -o, which expects a file ending with .out after // it, the tab completion will auto complete for files matching // the given pattern. "-o": complete.PredictFiles("*.out"), }, // define global flags of the 'run' main command // those will show up also when a sub command was entered in the // command line GlobalFlags: complete.Flags{ // a flag '-h' which does not expects anything after it "-h": complete.PredictNothing, }, } // run the command completion, as part of the main() function. // this triggers the autocompletion when needed. // name must be exactly as the binary that we want to complete. complete.New("run", run).Run() } ``` -------------------------------- ### Install TOML Validator CLI Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/BurntSushi/toml/README.md Install the TOML validator CLI tool using go install. This tool can be used to validate TOML files. ```bash go install github.com/BurntSushi/toml/cmd/tomlv@latest tomlv some-toml-file.toml ``` -------------------------------- ### Go Decimal Arithmetic Example Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/shopspring/decimal/README.md Demonstrates basic arithmetic operations like addition, subtraction, multiplication, and division using the decimal library. It shows how to create Decimal values from strings and integers, and perform calculations without loss of precision. ```go package main import ( "fmt" "github.com/shopspring/decimal" ) func main() { price, err := decimal.NewFromString("136.02") if err != nil { panic(err) } quantity := decimal.NewFromInt(3) fee, _ := decimal.NewFromString(".035") taxRate, _ := decimal.NewFromString(".08875") subtotal := price.Mul(quantity) preTax := subtotal.Mul(fee.Add(decimal.NewFromFloat(1))) total := preTax.Mul(taxRate.Add(decimal.NewFromFloat(1))) fmt.Println("Subtotal:", subtotal) // Subtotal: 408.06 fmt.Println("Pre-tax:", preTax) // Pre-tax: 422.3421 fmt.Println("Taxes:", total.Sub(preTax)) // Taxes: 37.482861375 fmt.Println("Total:", total) // Total: 459.824961375 fmt.Println("Tax rate:", total.Sub(preTax).Div(preTax)) // Tax rate: 0.08875 } ``` -------------------------------- ### TOML Front Matter Example Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/go.abhg.dev/goldmark/frontmatter/README.md Example of Markdown content with TOML front matter delimited by '+++'. ```markdown +++ title = "goldmark-frontmatter" tags = ["markdown", "goldmark"] description = """ Adds support for parsing YAML front matter. """ +++ # Heading 1 ``` -------------------------------- ### YAML Front Matter Example Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/go.abhg.dev/goldmark/frontmatter/README.md Example of Markdown content with YAML front matter delimited by '---'. ```markdown --- title: goldmark-frontmatter tags: [markdown, goldmark] description: | Adds support for parsing YAML front matter. --- # Heading 1 ``` -------------------------------- ### Install hc-install via Homebrew Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/hc-install/README.md Installs the hc-install CLI using the Homebrew package manager on macOS or Linux. ```sh brew install hashicorp/tap/hc-install ``` -------------------------------- ### Enable GET Request with Payload Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/go-resty/resty/v2/README.md Configure the Resty client to allow sending a payload with GET requests, which is disabled by default. ```go client := resty.New() client.SetAllowGetMethodPayload(true) ``` -------------------------------- ### Import Goldmark Packages Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/yuin/goldmark/README.md Import the necessary packages, 'bytes' for buffer operations and 'github.com/yuin/goldmark' for the Markdown parser, to begin using Goldmark. ```go import ( "bytes" "github.com/yuin/goldmark" ) ``` -------------------------------- ### GET Request with Query String Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/go-resty/resty/v2/README.md Perform a GET request using a pre-formatted query string. This is an alternative to setting individual query parameters. ```go // Sample of using Request.SetQueryString method resp, err := client.R(). SetQueryString("productId=232&template=fresh-sample&cat=resty&source=google&kw=buy a lot more"). SetHeader("Accept", "application/json"). SetAuthToken("BC594900518B4F7EAC75BD37F019E08FBC594900518B4F7EAC75BD37F019E08F"). Get("/show_product") ``` -------------------------------- ### Create and Use Multiple Resty Clients Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/go-resty/resty/v2/README.md Demonstrates creating multiple independent Resty clients, each with its own request configurations and execution. ```go client1 := resty.New() client1.R().Get("http://httpbin.org") // ... client2 := resty.New() client2.R().Head("http://httpbin.org") // ... ``` -------------------------------- ### Add Custom Root Certificates from File Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/go-resty/resty/v2/README.md Configure the client to use custom root certificates by providing the path to PEM-encoded certificate files. Multiple certificates can be added. ```go client := resty.New() // Custom Root certificates, just supply .pem file. // you can add one or more root certificates, its get appended client.SetRootCertificate("/path/to/root/pemFile1.pem") client.SetRootCertificate("/path/to/root/pemFile2.pem") // ... and so on! ``` -------------------------------- ### PATCH Method Example Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/go-resty/resty/v2/README.md Demonstrates how to send a PATCH request, used for partial updates of a resource. The example shows sending a struct with specific fields to update. ```APIDOC ## PATCH Request ### Description Sends a PATCH request with a struct as the request body, typically for partial updates. The content type defaults to `application/json`. ### Method PATCH ### Endpoint `https://myapp.com/articles/1234` ### Request Body - **(struct)** - A Go struct containing the fields to be updated. ### Request Example ```go resp, err := client.R(). SetBody(Article{ Tags: []string{"new tag1", "new tag2"}, }). SetAuthToken("C6A79608-782F-4ED0-A11D-BD82FAD829CD"). SetError(&Error{}). Patch("https://myapp.com/articles/1234") ``` ``` -------------------------------- ### Yamux Client Usage Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/yamux/README.md Demonstrates how to set up a Yamux client session and open a new stream over an existing network connection. ```go func client() { // Get a TCP connection conn, err := net.Dial(...) if err != nil { panic(err) } // Setup client side of yamux session, err := yamux.Client(conn, nil) if err != nil { panic(err) } // Open a new stream stream, err := session.Open() if err != nil { panic(err) } // Stream implements net.Conn stream.Write([]byte("ping")) } ``` -------------------------------- ### Simple GET Request with Trace Information Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/go-resty/resty/v2/README.md Perform a simple GET request and log detailed trace information about the request and response. This is useful for debugging and performance analysis. ```go // Create a Resty Client client := resty.New() resp, err := client.R(). EnableTrace(). Get("https://httpbin.org/get") // Explore response object fmt.Println("Response Info:") fmt.Println(" Error :", err) fmt.Println(" Status Code:", resp.StatusCode()) fmt.Println(" Status :", resp.Status()) fmt.Println(" Proto :", resp.Proto()) fmt.Println(" Time :", resp.Time()) fmt.Println(" Received At:", resp.ReceivedAt()) fmt.Println(" Body :\n", resp) fmt.Println() // Explore trace info fmt.Println("Request Trace Info:") ti := resp.Request.TraceInfo() fmt.Println(" DNSLookup :", ti.DNSLookup) fmt.Println(" ConnTime :", ti.ConnTime) fmt.Println(" TCPConnTime :", ti.TCPConnTime) fmt.Println(" TLSHandshake :", ti.TLSHandshake) fmt.Println(" ServerTime :", ti.ServerTime) fmt.Println(" ResponseTime :", ti.ResponseTime) fmt.Println(" TotalTime :", ti.TotalTime) fmt.Println(" IsConnReused :", ti.IsConnReused) fmt.Println(" IsConnWasIdle :", ti.IsConnWasIdle) fmt.Println(" ConnIdleTime :", ti.ConnIdleTime) fmt.Println(" RequestAttempt:", ti.RequestAttempt) fmt.Println(" RemoteAddr :", ti.RemoteAddr.String()) ``` -------------------------------- ### Simple GET Request with go-retryablehttp Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/go-retryablehttp/README.md Demonstrates the basic usage of making a GET request using the retryablehttp package. The call will automatically retry on failure with exponential backoff. ```go resp, err := retryablehttp.Get("/foo") if err != nil { panic(err) } ``` -------------------------------- ### Yamux Server Usage Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/yamux/README.md Illustrates how to set up a Yamux server session, accept an incoming stream, and read data from it. ```go func server() { // Accept a TCP connection conn, err := listener.Accept() if err != nil { panic(err) } // Setup server side of yamux session, err := yamux.Server(conn, nil) if err != nil { panic(err) } // Accept a stream stream, err := session.Accept() if err != nil { panic(err) } // Listen for a message buf := make([]byte, 4) stream.Read(buf) } ``` -------------------------------- ### Add Client Certificates from Files Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/go-resty/resty/v2/README.md Configure the client to use custom client certificates for mutual TLS authentication by loading them from PEM-encoded files. ```go // Adding Client Certificates, you add one or more certificates // Sample for creating certificate object // Parsing public/private key pair from a pair of files. The files must contain PEM encoded data. cert1, err := tls.LoadX509KeyPair("certs/client.pem", "certs/client.key") if err != nil { log.Fatalf("ERROR client certificate: %s", err) } // ... // You add one or more certificates client.SetCertificates(cert1, cert2, cert3) ``` -------------------------------- ### Import Server Enrollment Token Source: https://github.com/okta/terraform-provider-oktapam/blob/master/docs/resources/server_enrollment_token.md Import is supported using the syntax: terraform import oktapam_server_enrollment_token.example {{project_name}}/{{id}}. ```shell # Server Enrollment Token can be imported using Project Name and ID of the resource separated by a forward slash (/), e.g., terraform import oktapam_server_enrollment_token.example {{project_name}}/{{id}} ``` -------------------------------- ### DeleteGatewaySetupToken Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/atko-pam/pam-sdk-go/client/pam/README.md Deletes a specific gateway setup token. ```APIDOC ## DELETE /v1/teams/{team_name}/gateway_setup_tokens/{gateway_setup_token_id} ### Description Delete a gateway setup token. ### Method Delete ### Endpoint /v1/teams/{team_name}/gateway_setup_tokens/{gateway_setup_token_id} ``` -------------------------------- ### POST Request Examples with Go-Resty Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/go-resty/resty/v2/README.md Demonstrates various ways to send POST requests, including JSON strings, byte arrays, structs, and maps. Content-Type is automatically handled for struct and map types. ```go // Create a Resty Client client := resty.New() // POST JSON string // No need to set content type, if you have client level setting resp, err := client.R(). SetHeader("Content-Type", "application/json"). SetBody(`{"username":"testuser", "password":"testpass"}`). SetResult(&AuthSuccess{}). // or SetResult(AuthSuccess{}). Post("https://myapp.com/login") ``` ```go // POST []byte array // No need to set content type, if you have client level setting resp, err := client.R(). SetHeader("Content-Type", "application/json"). SetBody([]byte(`{"username":"testuser", "password":"testpass"}`)). SetResult(&AuthSuccess{}). // or SetResult(AuthSuccess{}). Post("https://myapp.com/login") ``` ```go // POST Struct, default is JSON content type. No need to set one resp, err := client.R(). SetBody(User{Username: "testuser", Password: "testpass"}). SetResult(&AuthSuccess{}). // or SetResult(AuthSuccess{}). SetError(&AuthError{}). // or SetError(AuthError{}). Post("https://myapp.com/login") ``` ```go // POST Map, default is JSON content type. No need to set one resp, err := client.R(). SetBody(map[string]interface{}{"username": "testuser", "password": "testpass"}). SetResult(&AuthSuccess{}). // or SetResult(AuthSuccess{}). SetError(&AuthError{}). // or SetError(AuthError{}). Post("https://myapp.com/login") ``` ```go // POST of raw bytes for file upload. For example: upload file to Dropbox fileBytes, _ := os.ReadFile("/Users/jeeva/mydocument.pdf") // See we are not setting content-type header, since go-resty automatically detects Content-Type for you resp, err := client.R(). SetBody(fileBytes). SetContentLength(true). // Dropbox expects this value SetAuthToken(""). SetError(&DropboxError{}). // or SetError(DropboxError{}). Post("https://content.dropboxapi.com/1/files_put/auto/resty/mydocument.pdf") // for upload Dropbox supports PUT too ``` -------------------------------- ### GET Request with Forced Content Type for JSON Parsing Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/go-resty/resty/v2/README.md Perform a GET request and force the response content type to JSON, enabling Resty to parse the JSON response directly into a struct. This is useful when the server does not set the Content-Type header correctly. ```go // If necessary, you can force response content type to tell Resty to parse a JSON response into your struct resp, err := client.R(). SetResult(result). ForceContentType("application/json"). Get("v2/alpine/manifests/latest") ``` -------------------------------- ### Create a New Logger Instance Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/go-hclog/README.md Instantiate a new logger with custom options, including a name and a specific log level. Ensure the desired log level is correctly parsed from a string. ```go appLogger := hclog.New(&hclog.LoggerOptions{ Name: "my-app", Level: hclog.LevelFromString("DEBUG"), }) ``` -------------------------------- ### Advanced HTTP Mocking with Custom Responders Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/jarcoal/httpmock/README.md Illustrates advanced mocking scenarios including dynamic JSON responses, using request parameters (regexp submatches), and handling POST requests with custom logic. Also shows how to use a matcher to conditionally respond. ```go func TestFetchArticles(t *testing.T) { httpmock.Activate(t) // our database of articles articles := make([]map[string]interface{}, 0) // mock to list out the articles httpmock.RegisterResponder("GET", "https://api.mybiz.com/articles", func(req *http.Request) (*http.Response, error) { resp, err := httpmock.NewJsonResponse(200, articles) if err != nil { return httpmock.NewStringResponse(500, ""), nil } return resp, nil }) // return an article related to the request with the help of regexp submatch (\d+) httpmock.RegisterResponder("GET", `=~^https://api\.mybiz\.com/articles/id/(\d+)\z`, func(req *http.Request) (*http.Response, error) { // Get ID from request id := httpmock.MustGetSubmatchAsUint(req, 1) // 1=first regexp submatch return httpmock.NewJsonResponse(200, map[string]interface{}{ "id": id, "name": "My Great Article", }) }) // mock to add a new article httpmock.RegisterResponder("POST", "https://api.mybiz.com/articles", func(req *http.Request) (*http.Response, error) { article := make(map[string]interface{}) if err := json.NewDecoder(req.Body).Decode(&article); err != nil { return httpmock.NewStringResponse(400, ""), nil } articles = append(articles, article) resp, err := httpmock.NewJsonResponse(200, article) if err != nil { return httpmock.NewStringResponse(500, ""), nil } return resp, nil }) // mock to add a specific article, send a Bad Request response // when the request body contains `"type":"toy"` httpmock.RegisterMatcherResponder("POST", "https://api.mybiz.com/articles", httpmock.BodyContainsString(`"type":"toy"`), httpmock.NewStringResponder(400, `{"reason":"Invalid article type"}`)) // do stuff that adds and checks articles } ``` -------------------------------- ### FetchGatewaySetupTokenAsAgentToken Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/atko-pam/pam-sdk-go/client/pam/README.md Retrieves a gateway setup token as an agent token. ```APIDOC ## GET /v1/teams/{team_name}/gateway_setup_tokens/{gateway_setup_token_id}/token ### Description Retrieve a gateway setup token. ### Method Get ### Endpoint /v1/teams/{team_name}/gateway_setup_tokens/{gateway_setup_token_id}/token ``` -------------------------------- ### Import Resty Library Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/go-resty/resty/v2/README.md Import the resty library into your Go code to start using it. ```go // Import resty into your code and refer it as `resty`. import "github.com/go-resty/resty/v2" ``` -------------------------------- ### Create Goldmark with GFM Extension and Options Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/yuin/goldmark/README.md Demonstrates how to create a Goldmark instance with the GitHub Flavored Markdown extension, auto heading IDs, hard wraps, and XHTML rendering. This is useful for parsing Markdown with common extensions and specific rendering requirements. ```go import ( "bytes" "github.com/yuin/goldmark" "github.com/yuin/goldmark/extension" "github.com/yuin/goldmark/parser" "github.com/yuin/goldmark/renderer/html" ) md := goldmark.New( goldmark.WithExtensions(extension.GFM), goldmark.WithParserOptions( parser.WithAutoHeadingID(), ), goldmark.WithRendererOptions( html.WithHardWraps(), html.WithXHTML(), ), ) var buf bytes.Buffer if err := md.Convert(source, &buf); err != nil { panic(err) } ``` -------------------------------- ### Markdown Syntax for YAML Metadata Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/yuin/goldmark-meta/README.md Example of how to structure a Markdown document with a YAML metadata block. ```markdown --- Title: goldmark-meta Summary: Add YAML metadata to the document Tags: - markdown - goldmark --- # Heading 1 ``` -------------------------------- ### Parse and Compare Versions in Go Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/go-version/README.md Demonstrates parsing two version strings and comparing them using the LessThan method. Handles metadata in version strings. ```go v1, err := version.NewVersion("1.2") v2, err := version.NewVersion("1.5+metadata") // Comparison example. There is also GreaterThan, Equal, and just // a simple Compare that returns an int allowing easy >=, <=, etc. if v1.LessThan(v2) { fmt.Printf("%s is less than %s", v1, v2) } ``` -------------------------------- ### Object Element with Variable Attribute Name Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/hcl/v2/hclsyntax/spec.md Example of an object element where the attribute name is derived from a variable. ```hcl {(foo) = "baz"} ``` -------------------------------- ### Object Element with Literal Attribute Name Source: https://github.com/okta/terraform-provider-oktapam/blob/master/vendor/github.com/hashicorp/hcl/v2/hclsyntax/spec.md Example of an object element where the attribute name is a literal string. ```hcl {foo = "baz"} ```