initial commit

This commit is contained in:
Mike Mason
2023-07-01 00:04:52 +00:00
commit 80fb879ef6
65 changed files with 3544 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
package emgql
import (
"net/http"
"net/url"
"time"
provider "go.equinixmetal.net/infra9-metal-bridge/internal/metal/providers"
"go.uber.org/zap"
)
const (
defaultHTTPTimeout = 5 * time.Second
)
var (
DefaultHTTPClient = &http.Client{
Timeout: defaultHTTPTimeout,
}
)
var _ provider.Provider = &Client{}
type Client struct {
logger *zap.SugaredLogger
httpClient *http.Client
baseURL *url.URL
}
// New creates a new emapi client
func New(options ...Option) (*Client, error) {
client := &Client{}
for _, opt := range options {
if err := opt(client); err != nil {
return nil, err
}
}
if client.logger == nil {
client.logger = zap.NewNop().Sugar()
}
if client.httpClient == nil {
client.httpClient = DefaultHTTPClient
}
return client, nil
}

View File

@@ -0,0 +1,12 @@
package emgql
// Config provides configuration for connecting to the Equinix Metal API provider.
type Config struct {
// BaseURL is the baseurl to use when connecting to the Equinix Metal API Provider.
BaseURL string
}
func (c Config) Populated() bool {
return c.BaseURL != ""
}

View File

@@ -0,0 +1,52 @@
package emgql
import (
"net/url"
"go.uber.org/zap"
)
// Option is a Client configuration Option definition.
type Option func(c *Client) error
// WithLogger sets the logger for the client.
func WithLogger(logger *zap.SugaredLogger) Option {
return func(c *Client) error {
c.logger = logger
return nil
}
}
// WithBaseURL updates the baseurl used by the client.
func WithBaseURL(baseURL string) Option {
return func(c *Client) error {
u, err := url.Parse(baseURL)
if err != nil {
return err
}
c.baseURL = u
return nil
}
}
// WithConfig applies all configurations defined in the config.
func WithConfig(config Config) Option {
return func(c *Client) error {
var options []Option
if config.BaseURL != "" {
options = append(options, WithBaseURL(config.BaseURL))
}
for _, opt := range options {
if err := opt(c); err != nil {
return err
}
}
return nil
}
}

View File

@@ -0,0 +1,12 @@
package emgql
import (
"context"
"go.equinixmetal.net/infra9-metal-bridge/internal/metal/models"
"go.infratographer.com/x/gidx"
)
func (c *Client) GetOrganizationDetails(ctx context.Context, id gidx.PrefixedID) (*models.OrganizationDetails, error) {
return nil, nil
}

View File

@@ -0,0 +1,12 @@
package emgql
import (
"context"
"go.equinixmetal.net/infra9-metal-bridge/internal/metal/models"
"go.infratographer.com/x/gidx"
)
func (c *Client) GetProjectDetails(ctx context.Context, id gidx.PrefixedID) (*models.ProjectDetails, error) {
return nil, nil
}

View File

@@ -0,0 +1,12 @@
package emgql
import (
"context"
"go.equinixmetal.net/infra9-metal-bridge/internal/metal/models"
"go.infratographer.com/x/gidx"
)
func (c *Client) GetUserDetails(ctx context.Context, id gidx.PrefixedID) (*models.UserDetails, error) {
return nil, nil
}