Skip to content

IBM/vpc-beta-go-sdk

Repository files navigation

Build Status License GitHub go.mod Go version semantic-release

IBM Cloud VPC Beta Go SDK Version 0.1.0

Go client library to interact with the various IBM Cloud VPC Services APIs.

This SDK uses Semantic Versioning, and as such there may be backward-incompatible changes for any new 0.y.z version.

Note:

This SDK surfaces IBM Cloud VPC features with Beta maturity which are subject to change before general availability. IBM Cloud VPC features with general availability can be found here

Table of Contents

Overview

The IBM Cloud VPC Beta Go SDK allows developers to programmatically interact with the following IBM Cloud services:

Service Name Package name
VPC vpcbetav1

Prerequisites

  • An IBM Cloud account.
  • An IAM API key to allow the SDK to access your account. Create an apikey here.
  • Go version 1.18 or above.

Installation

There are a few different ways to download and install the VPC Go SDK services for use by your Go application:

go get command

Use this command to download and install the VPC Go SDK service to allow your Go application to use it:

go get github.com/IBM/vpc-beta-go-sdk@v0.1.0

Go modules

If your application is using Go modules, you can add a suitable import to your Go application, like this:

import (
	"github.com/IBM/vpc-beta-go-sdk/vpcbetav1"
)

Then run go mod tidy to download and install the new dependency and update your Go application's go.mod file.

dep dependency manager

If your application is using the dep dependency management tool, you can add a dependency to your Gopkg.toml file. Here is an example:

[[constraint]]
  name = "github.com/IBM/vpc-beta-go-sdk/"
  version = "0.1.0"

Then run dep ensure.

Using the SDK

For general SDK usage information, see the IBM Cloud SDK Common README

Setting up VPC service

A quick example to get you up and running with VPC Go SDK service in Dallas (us-south) region.

For other regions, see API Endpoints for VPC and update the URL variable accordingly.

Refer to the VPC Release Notes to find out latest version release.

package main

import (
	"log"
	"os"

	"github.com/IBM/go-sdk-core/v4/core"
	"github.com/IBM/vpc-beta-go-sdk/vpcbetav1"
)

func main() {
	apiKey := os.Getenv("IBMCLOUD_API_KEY")
	if apiKey == "" {
		log.Fatal("No API key set")
	}

	// Instantiate the service with an API key based IAM authenticator
	vpcService, err := vpcbetav1.NewVpcbetaV1(&vpcbetav1.VpcbetaV1Options{
		Authenticator: &core.IamAuthenticator{
			ApiKey: apiKey,
		},
	})
	if err != nil {
		log.Fatal("Error creating VPC Beta Service.")
	}

	// Retrieve the list of regions for your account.
	regions, detailedResponse, err := vpcService.ListRegions(&vpcbetav1.ListRegionsOptions{})
	if err != nil {
		log.Fatalf("Failed to list the regions: %v and the response is: %s", err, detailedResponse)
	}
	log.Printf("Regions: %#v", regions)

	// Retrieve the list of vpcs for your account.
	vpcs, detailedResponse, err := vpcService.ListVpcs(&vpcbetav1.ListVpcsOptions{})
	if err != nil {
		log.Fatalf("Failed to list vpcs: %v and the response is: %s", err, detailedResponse)
	}
	log.Printf("VPCs: %#v", vpcs)

	// Create an SSH key
	sshKeyOptions := &vpcbetav1.CreateKeyOptions{
		Name: core.StringPtr("my-ssh-key"),
	}
	// Setters also exist to set fields are the struct has been created
	sshKeyOptions.SetPublicKey("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDsnrSAe8eBi8mS576Z96UtYgUzDR9Sbw/s1ELxsa1KUK82JQ0Ejmz31N6sHyiT/l5533JgGL6rKamLFziMY2VX2bdyuF5YzyHhmapT+e21kuTatB50UsXzxlYEWpCmFdnd4LhwFn6AycJWOV0k3e0ePpVxgHc+pVfE89322cbmfuppeHxvxc+KSzQNYC59A+A2vhucbuWppyL3EIF4YgLwOr5iDISm1IR0+EEL3yJQIG4M2WKu526anI85QBcIWyFwQXOpdcX2eZRcd6WW2EgAM3fIOaezkm0CFrsz8rQ0MPYZI4BS2CWwg5d4Bj7SU2sjXz62gfQkQGTYWSqhizVb root@localhost")
	key, detailedResponse, err := vpcService.CreateKey(sshKeyOptions)
	if err != nil {
		log.Fatalf("Failed to create the ssh key: %v and the response is: %s", err, detailedResponse)
	}
	log.Printf("SSH key: %s created with ID: %s", *key.Name, *key.ID)

	// Delete SSH key
	detailedResponse, err = vpcService.DeleteKey(&vpcbetav1.DeleteKeyOptions{
		ID: key.ID,
	})
	if err != nil {
		log.Fatalf("Failed to delete the ssh key: %v and the response is: %s", err, detailedResponse)
	}

	log.Printf("SSH key: %s deleted with ID: %s", *key.Name, *key.ID)
}

Questions

If you have difficulties using this SDK or you have a question about the IBM Cloud services, ask a question at Stack Overflow.

Issues

If you encounter an issue with the project, you are welcome to submit a [bug report](/issues). Before you create a new issue, search for similar issues. It's possible that someone has already reported the problem.

Open source @ IBM

Find more open source projects on the IBM Github Page.

Contributing

See CONTRIBUTING.

License

This SDK project is released under the Apache 2.0 license. The license's full text can be found in LICENSE.

About

Go client library to interact with the various IBM Cloud VPC Services APIs in Beta.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages