oracle / oci-go-sdk

Go SDK for Oracle Cloud Infrastructure
https://cloud.oracle.com/cloud-infrastructure
Other
176 stars 82 forks source link
cloud go oracle-cloud oracle-cloud-infrastructure sdk

Oracle Cloud Infrastructure Golang SDK

wercker status

This is the Go SDK for Oracle Cloud Infrastructure. This project is open source and maintained by Oracle Corp. The home page for the project is here.

Survey

Are you a Developer using the OCI SDK? If so, please fill out our survey to help us make the OCI SDK better for you. Click here for the survey page.

Dependencies

Versioning

Installing

If you want to install the SDK under $GOPATH, you can use go get to retrieve the SDK:

go get -u github.com/oracle/oci-go-sdk

If you are using Go modules, you can install by running the following command within a folder containing a go.mod file:

go get -d github.com/oracle/oci-go-sdk/v49@latest

The latest major version (for example v49) can be identified on the Github releases page.

Alternatively, you can install a specific version (supported from v25.0.0 on):

go get -d github.com/oracle/oci-go-sdk/v49@v49.1.0

Run go mod tidy

In your project, you also need to ensure the import paths contain the correct major-version:

import "github.com/oracle/oci-go-sdk/v49/common"  // or whatever major version you're using

Working with the Go SDK

To start working with the Go SDK, you import the service package, create a client, and then use that client to make calls.

Configuring

Before using the SDK, set up a config file with the required credentials. See SDK and Tool Configuration for instructions.

Note that the Go SDK does not support profile inheritance or defining custom values in the configuration file.

Once a config file has been setup, call common.DefaultConfigProvider() function as follows:

 // Import necessary packages
 import (
    "github.com/oracle/oci-go-sdk/v49/common"
    "github.com/oracle/oci-go-sdk/v49/identity" // Identity or any other service you wish to make requests to
)

 //...

configProvider := common.DefaultConfigProvider()

Or, to configure the SDK programmatically instead, implement the ConfigurationProvider interface shown below:

// ConfigurationProvider wraps information about the account owner
type ConfigurationProvider interface {
    KeyProvider
    TenancyOCID() (string, error)
    UserOCID() (string, error)
    KeyFingerprint() (string, error)
    Region() (string, error)
    // AuthType() is used for specify the needed auth type, like UserPrincipal, InstancePrincipal, etc. AuthConfig is used for getting auth related paras in config file.
    AuthType() (AuthConfig, error)
}

Or simply use one of structs exposed by the oci-go-sdk that already implement the above interface

Making a Request

To make a request to an Oracle Cloud Infrastructure service, create a client for the service and then use the client to call a function from the service.

For example:

config := common.DefaultConfigProvider()
client, err := identity.NewIdentityClientWithConfigurationProvider(config)
if err != nil { 
     panic(err)
}

For example:

id := "your_group_id"
response, err := client.GetGroup(context.Background(), identity.GetGroupRequest{GroupId:&id})
if err != nil {
    //Something happened
    panic(err)
}
//Process the data in response struct
fmt.Println("Group's name is:", response.Name)

Organization of the SDK

The oci-go-sdk contains the following:

Examples

Examples can be found here

Documentation

Full documentation can be found on the godocs site.

Help

Contributing

This project welcomes contributions from the community. Before submitting a pull request, please review our contribution guide

Security

Please consult the security guide for our responsible security vulnerability disclosure process

License

Copyright (c) 2016, 2023, Oracle and/or its affiliates. All rights reserved. This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.

See LICENSE for more details.

Changes

See CHANGELOG.

Known Issues

You can find information on any known issues with the SDK here and under the Issues tab of this project's GitHub repository.

Building and Testing

Dev Dependencies

For Go versions below 1.17

For Go versions 1.17 and above

Linting and Staticcheck

Linting (performed by golint) can be done with the following command:

make lint

Linting will perform a number of formatting changes across the code base.

make static-check

This command is also run by the make build and make test commands. Staticcheck will provide formatting warnings but will not make any changes to any files. You can also cause staticcheck to be run before calls to "git commit" with the pre-commit plugin.

pre-commit install

You can install pre-commit itself, you can use your package manager of choice, such as

brew install pre-commit

Build

Building is provided by the make file at the root of the project. To build the project execute.

make build

To run the tests:

make test