edgio-go-sdk

Go SDK implementing Edgio's REST API

MIT License

Stars
8

Edgio Go SDK

This project goal is to implement a GO SDK wrapper for the Edgio's REST API. This SDK is a starting point for more advanced projects like a CLI and a Terraform Provider.

Project Standards

Project Meta Data

Project Status

Table of Contents

Internal Packages

The internal package documentation is intended to potential contributors of the repository, since they are not exposed to be directly imported. If you are a user, you shoud use our public api-specific packages to develop your application.

internal/client

This package provides a base client configuration and connection to Edgio's REST API, as well as configuration validation. The public packages under edgio namespace uses this client under the hood to perform their API calls.

client.New(creds common.Creds, config common.ClientConfig) (client.Client, error)

This constructor validates and assing default valued (if applicable) to the provided credentials and configurations and returns a client instance with a valid access token, or an error if anything goes wrong.

utils.GetServiceURL(params common.URLParams) string

This function generates the fully formatted Edgio REST API's url for the desired resource, identified by its service, scope and apiVersion.

Check a more in-depth documentation of thw internal/client package here.

internal/token

The main goal of this package is to hold any logic related to the aquisition/refreshing/invalidation generated by Edgio REST API client.

token.GetAccessToken(credentials common.Creds) (string, error)

This func outsources the process of getting an auth token from Edgio's Auth service. It assumes Edgio's standard auth endpoint as a default URL, but that can be overwritten by your own, in the event of an enterprise/self-hosted app.

Check a more in-depth documentation of the internal/token package here.

internal/utils

This package package holds some utility functions that are used to outsource some common logic from other packages to avoid repetition/ease testing.

utils.GetHttpJsonResult(httpClient *http.Client, request *http.Request, token string, model interface{}) (interface{}, error)

This function has mainly three related goals:

  1. Process http requests;
  2. treat HTTP errors in a standardized way, and;
  3. Process and decode returned json data from the endpoints.

utils.FilterList[T common.Filterable](params common.FilterListParams[T]) []T

Filters the list of items (haystack) by the given needle. Returns a list of items that contain the needle in their name, key or slug, depending on the entity type (Property, Environment, Variable), or an empty list if no items match the needle.

Check a more in-depth documentation of the internal/utils package here.

Public Packages

The public packages are the parts of the SDK that are actually intended to be used. You should be able to import just those you need for your project.

edgio/common

This package expose public interfaces, structs and other functions that could not be hosted on the internal packages, since in some cases they are required by both other internal packages and some public ones, leading to cyclic imports. Due to that, they were outsourced to their own package.

common.ClientConfig.Merge(other common.ClientConfig{})

Merges the other ClientConfig into the default one, overwriting the current values with the other's if they are not empty.

Check a more in-depth documentation of the edgio/common package here.

edgio/org

[WIP]

This package groups Edgio Organization specific funcs.

org.NewClient(params ClientParams) (ClientStruct, error)

This func returns a new client with the provided parameters, with an access token already set, and the default edgio params values for service, scope and API version (which can be overwritten if needed) to interact with your application's orgs.

org.Get(params common.URLParams) (common.Org, error)

This func returns the relevant organization details (name and id).

org.Patch(params common.URLParams, body PatchBody) (common.Org, error)

This func updates the relevant Org's name and return the Org object with the new data (name and id).

Check a more in-depth documentation of the edgio/org package here.

Reference: Edgio Organizations REST API documentation reference.

edgio/property

[WIP]

This package groups Edgio Property specific funcs.

property.NewClient(params ClientParams) (ClientStruct, error)

This func returns a new client with the provided parameters, with an access token already set, and the default edgio params values for service, scope and API version (which can be overwritten if needed) to interact with your application's properties.

property.List() (ListResultType, error)

This func lists properties for a given Edgio Organization. Edgio's list page size was defaulted to 100 for now, which is the highest value. The idea is to return all properties until actual pagination is implemented. Returns a list of properties for a given Organization or an error if anything goes wrong.

property.FilterList(params property.FilterParams) (common.FilteredListResultType[common.Property], error)

Filters the list of properties for a given Org by the property slug, and returns a list of properties that contain the provided slug, or all properties if no slug is provided.

property.Get(params property.FilterParams) (common.Property, error)

This func retrieves a property by ID and returns it, or empty if none was found.

GetBySlug(params FilterParams) (common.Property, error)

Returns the first property in the list that matches the slug, or nil if no properties match the slug.

Check a more in-depth documentation of the edgio/property package here.

Reference: Edgio Properties REST API documentation reference.

edgio/env

[WIP]

This package groups Edgio Environment specific funcs.

env.NewClient(params common.ClientParams) (ClientStruct, error)

This func returns a new client with the provided parameters, with an access token already set, and the default edgio params values for service, scope and API version (which can be overwritten if needed) to interact with your application's environments.

env.List(propertyID string) (ListResultType, error)

This func list environments for a given Edgio Property. Edgio's list page size was defaulted to 100 for now, which is the highest value. The idea is to return all environments until actual pagination is implemented. Returns a list of environments for a given Property or an error if anything goes wrong.

env.FilterList(params env.FilterParams) (common.FilteredListResultType[common.Env], error)

Filters the list of environments for a given Property by the environment name, and returns a list of environments for a given Property that contain the provided name, or all environments if no name is provided.

env.Get(params env.FilterParams) (common.Env, error)

This func retrieves an environment by ID and returns it, or empty if none was found.

env.GetByName(params FilterParams) (common.Env, error)

Returns the first environment in the list that matches the name, or nil if no environments match the name.

Check a more in-depth documentation of the edgio/env package here.

Reference: Edgio Environments REST API documentation reference.

edgio/variables

[WIP]

This package groups Edgio Environment Variables specific funcs.

variable.NewClient(params common.ClientParams) (ClientStruct, error)

This func returns a new client with the provided parameters, with an access token already set, and the default edgio params values for service, scope and API version (which can be overwritten if needed) to interact with your application's environments.

variable.List(environmentID string) (ListResultType, error)

This func list environment variables for a given Edgio Environment. Edgio's list page size was defaulted to 100 for now, which is the highest value. The idea is to return all environment variables until actual pagination is implemented. Returns a list of environment variables for a given Property or an error if anything goes wrong.

variable.FilterList(params variable.FilterParams) (common.FilteredListResultType[common.Variable], error)

This func filters the list of environment variables for a given Environment by the variable key, and returns a list of environment variables that contain the provided key, or all environment variables if no key is provided.

variable.Get(params variable.FilterParams) (common.Variable, error)

This func retrieves an environment variable by ID and returns it, or empty if none was found.

GetByKey(params FilterParams) (common.Variable, error)

This func returns the environment variable that matches the provided key, or nil if no environment variables match the key.

Check a more in-depth documentation of the edgio/variables package here.

Reference: Edgio Environment Variables REST API documentation reference.

edgio/cache

[WIP]

Edgio Cache REST API documentation reference.

edgio/cdn

[WIP]

Edgio CDN REST API documentation reference.

edgio/deployment

[WIP]

Edgio Deployment REST API documentation reference.

edgio/tsl

[WIP]

Edgio TSL REST API documentation reference.

edgio/acl

[WIP]

Edgio ACL REST API documentation reference.

edgio/security_ruleset

[WIP]

Edgio Security Ruleset REST API documentation reference.

edgio/schemas

[WIP]

Edgio Schemas REST API documentation reference.

edgio/rate

[WIP]

Edgio Rate Rules REST API documentation reference.

edgio/bot_manager

[WIP]

Edgio Managers Config REST API documentation reference.

edgio/bot_ruleset

[WIP]

Edgio Bot Ruleset REST API documentation reference.

edgio/bot_known

[WIP]

Edgio Known Bots REST API documentation reference.

edgio/custom_rule

[WIP]

Edgio Custom Rules REST API documentation reference.

edgio/managed_rule

[WIP]

Edgio Managed Rules REST API documentation reference.

edgio/ruleset

[WIP]

Edgio Edgio Rulesets REST API documentation reference.

edgio/security_app

[WIP]

Edgio Security Apps REST API documentation reference.

Tooling

There are a few tools we provide alongside with the source code to ease a little bit the burden of following a bunch of patterns and standards we set up, as well as automate some boring processes.

  • comitizen: This CLI helps with writting commit messages in a meaningful and standardized way, so that our automation process can use them to properly write our software, changelog. To use it, you just need to run ./tools/commitizen-go install from the repository's root folder. After that, you just need to use git cz command instead of the standard git commit and follow the cli interactive steps :)

Contributors

Kudos to all our dear contributors. Without them, nothing would have been possible ❤️

Would you like to see your profile here? Take a look on our Code of Conduct and our Contributing docs, and start coding! We would be thrilled to review a PR of yours! 💯

Changelog

All changes made to this module since the start of development can be found either on our release list or on the changelog.

Roadmap

Any planned enhancement to the module will be described and tracked in our project page