make client interface
This commit is contained in:
@@ -10,41 +10,46 @@ import (
|
||||
"go.equinixmetal.net/infra9-metal-bridge/internal/metal/providers"
|
||||
)
|
||||
|
||||
// Client is the Equinix Metal API Client struct.
|
||||
type Client struct {
|
||||
// Client is the Equinix Metal Client Interface.
|
||||
type Client interface {
|
||||
providers.Provider
|
||||
}
|
||||
|
||||
// client is the Equinix Metal Client struct.
|
||||
type client struct {
|
||||
logger *zap.Logger
|
||||
|
||||
provider providers.Provider
|
||||
}
|
||||
|
||||
// GetOrganizationDetails fetches the organization id provided with its memberships.
|
||||
func (c *Client) GetOrganizationDetails(ctx context.Context, id gidx.PrefixedID) (*models.OrganizationDetails, error) {
|
||||
func (c *client) GetOrganizationDetails(ctx context.Context, id gidx.PrefixedID) (*models.OrganizationDetails, error) {
|
||||
return c.provider.GetOrganizationDetails(ctx, id)
|
||||
}
|
||||
|
||||
// GetProjectDetails fetchs the provided project id with membership information.
|
||||
func (c *Client) GetProjectDetails(ctx context.Context, id gidx.PrefixedID) (*models.ProjectDetails, error) {
|
||||
func (c *client) GetProjectDetails(ctx context.Context, id gidx.PrefixedID) (*models.ProjectDetails, error) {
|
||||
return c.provider.GetProjectDetails(ctx, id)
|
||||
}
|
||||
|
||||
// GetUserDetails fetches the provided user id.
|
||||
func (c *Client) GetUserDetails(ctx context.Context, id gidx.PrefixedID) (*models.UserDetails, error) {
|
||||
func (c *client) GetUserDetails(ctx context.Context, id gidx.PrefixedID) (*models.UserDetails, error) {
|
||||
return c.provider.GetUserDetails(ctx, id)
|
||||
}
|
||||
|
||||
// GetUserOrganizationRole returns the role for the user in the organization.
|
||||
func (c *Client) GetUserOrganizationRole(ctx context.Context, userID, orgID gidx.PrefixedID) (string, error) {
|
||||
func (c *client) GetUserOrganizationRole(ctx context.Context, userID, orgID gidx.PrefixedID) (string, error) {
|
||||
return c.provider.GetUserOrganizationRole(ctx, userID, orgID)
|
||||
}
|
||||
|
||||
// GetUserProjectRole returns the role for the user in the project.
|
||||
func (c *Client) GetUserProjectRole(ctx context.Context, userID, projID gidx.PrefixedID) (string, error) {
|
||||
func (c *client) GetUserProjectRole(ctx context.Context, userID, projID gidx.PrefixedID) (string, error) {
|
||||
return c.provider.GetUserProjectRole(ctx, userID, projID)
|
||||
}
|
||||
|
||||
// New creates a new Client.
|
||||
func New(options ...Option) (*Client, error) {
|
||||
client := new(Client)
|
||||
// New creates a new Equinix Metal Client.
|
||||
func New(options ...Option) (Client, error) {
|
||||
client := new(client)
|
||||
|
||||
for _, opt := range options {
|
||||
if err := opt(client); err != nil {
|
||||
|
||||
@@ -9,11 +9,11 @@ import (
|
||||
)
|
||||
|
||||
// Option is a Client configuration Option definition.
|
||||
type Option func(c *Client) error
|
||||
type Option func(c *client) error
|
||||
|
||||
// WithProvider sets the provider on the client.
|
||||
func WithProvider(provider providers.Provider) Option {
|
||||
return func(c *Client) error {
|
||||
return func(c *client) error {
|
||||
c.provider = provider
|
||||
|
||||
return nil
|
||||
@@ -22,7 +22,7 @@ func WithProvider(provider providers.Provider) Option {
|
||||
|
||||
// WithLogger sets the logger for the client.
|
||||
func WithLogger(logger *zap.Logger) Option {
|
||||
return func(c *Client) error {
|
||||
return func(c *client) error {
|
||||
c.logger = logger
|
||||
|
||||
return nil
|
||||
@@ -31,7 +31,7 @@ func WithLogger(logger *zap.Logger) Option {
|
||||
|
||||
// WithConfig applies all configurations defined in the config.
|
||||
func WithConfig(config Config) Option {
|
||||
return func(c *Client) error {
|
||||
return func(c *client) error {
|
||||
var options []Option
|
||||
|
||||
if config.EMGQL.Populated() {
|
||||
|
||||
Reference in New Issue
Block a user