initial commit
This commit is contained in:
49
internal/metal/providers/emgql/client.go
Normal file
49
internal/metal/providers/emgql/client.go
Normal 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
|
||||
}
|
||||
12
internal/metal/providers/emgql/config.go
Normal file
12
internal/metal/providers/emgql/config.go
Normal 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 != ""
|
||||
}
|
||||
52
internal/metal/providers/emgql/options.go
Normal file
52
internal/metal/providers/emgql/options.go
Normal 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
|
||||
}
|
||||
}
|
||||
12
internal/metal/providers/emgql/organizations.go
Normal file
12
internal/metal/providers/emgql/organizations.go
Normal 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
|
||||
}
|
||||
12
internal/metal/providers/emgql/projects.go
Normal file
12
internal/metal/providers/emgql/projects.go
Normal 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
|
||||
}
|
||||
12
internal/metal/providers/emgql/users.go
Normal file
12
internal/metal/providers/emgql/users.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user