api

package
v1.9.0-test2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2025 License: LGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoOrganizationID = eris.New("organization ID is required")
	ErrNoProjectID      = eris.New("project ID is required")
	ErrNoProjectSlug    = eris.New("project slug is required")
)
View Source
var (
	ErrNoUserEmail = eris.New("user email is required")
	ErrNoUserName  = eris.New("user name is required")
)
View Source
var ErrOrganizationSlugAlreadyExists = eris.New("organization slug already exists")

ErrOrganizationSlugAlreadyExists is passed from forge to world-cli, Must always match.

View Source
var ErrProjectSlugAlreadyExists = eris.New("project slug already exists")

ErrProjectSlugAlreadyExists is passed from forge to world-cli, Must always match.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL        string
	ArgusIDBaseURL string
	// TODO: Remove this once we have a proper RPC client
	RPCURL     string
	Token      string
	HTTPClient HTTPClientInterface
}

Client implements HTTP API client with retry logic and authentication.

func (*Client) AcceptOrganizationInvitation

func (c *Client) AcceptOrganizationInvitation(ctx context.Context, orgID string) error

AcceptOrganizationInvitation accepts an invitation to join an organization.

func (*Client) CheckProjectSlugIsTaken

func (c *Client) CheckProjectSlugIsTaken(ctx context.Context, orgID, projID, slug string) error

CheckProjectSlugIsTaken checks if a project slug is already taken.

func (*Client) CreateOrganization

func (c *Client) CreateOrganization(ctx context.Context, name, slug string) (models.Organization, error)

CreateOrganization creates a new organization.

func (*Client) CreateProject

func (c *Client) CreateProject(ctx context.Context, orgID string, project models.Project) (models.Project, error)

CreateProject creates a new project.

func (*Client) DeleteProject

func (c *Client) DeleteProject(ctx context.Context, orgID, projID string) error

DeleteProject deletes a project.

func (*Client) DeployProject

func (c *Client) DeployProject(
	ctx context.Context,
	orgID, projID, deployType string,
) error

DeployProject deploy, resets, destroys, or promotes a project.

func (*Client) GetDeploymentHealthStatus

func (c *Client) GetDeploymentHealthStatus(
	ctx context.Context,
	projID string,
) (map[string]models.DeploymentHealthCheckResult, error)

GetDeploymentHealthStatus retrieves deployment health status.

func (*Client) GetDeploymentStatus

func (c *Client) GetDeploymentStatus(ctx context.Context, projID string) ([]byte, error)

GetDeploymentStatus retrieves deployment status.

func (*Client) GetHealthStatus

func (c *Client) GetHealthStatus(ctx context.Context, projID string) ([]byte, error)

GetHealthStatus retrieves health status.

func (*Client) GetListRegions

func (c *Client) GetListRegions(ctx context.Context, orgID, projID string) ([]string, error)

GetListRegions retrieves available regions for a project.

func (c *Client) GetLoginLink(ctx context.Context) (LoginLinkResponse, error)

GetLoginLink gets the login link from ArgusID service.

func (*Client) GetLoginToken

func (c *Client) GetLoginToken(ctx context.Context, callbackURL string) (models.LoginToken, error)

GetLoginToken polls the callback URL for login token.

func (*Client) GetOrganizationByID

func (c *Client) GetOrganizationByID(ctx context.Context, id string) (models.Organization, error)

GetOrganizationByID retrieves a specific organization by ID.

func (*Client) GetOrganizationMembers

func (c *Client) GetOrganizationMembers(ctx context.Context, orgID string) ([]models.OrganizationMember, error)

func (*Client) GetOrganizations

func (c *Client) GetOrganizations(ctx context.Context) ([]models.Organization, error)

GetOrganizations retrieves the list of organizations the user belongs to.

func (*Client) GetOrganizationsInvitedTo

func (c *Client) GetOrganizationsInvitedTo(ctx context.Context) ([]models.Organization, error)

GetOrganizationsInvitedTo retrieves organizations the user has been invited to.

func (*Client) GetProjectByID

func (c *Client) GetProjectByID(ctx context.Context, orgID, projID string) (models.Project, error)

GetProjectByID retrieves a specific project by ID.

func (*Client) GetProjects

func (c *Client) GetProjects(ctx context.Context, orgID string) ([]models.Project, error)

GetProjects retrieves all projects for a given organization.

func (*Client) GetRPCBaseURL

func (c *Client) GetRPCBaseURL() string

TODO: Remove this once we have a proper RPC client

func (*Client) GetTemporaryCredential

func (c *Client) GetTemporaryCredential(ctx context.Context, orgID, projID string) (models.TemporaryCredential, error)

func (*Client) GetUser

func (c *Client) GetUser(ctx context.Context) (models.User, error)

GetUser retrieves the current user information.

func (*Client) InviteUserToOrganization

func (c *Client) InviteUserToOrganization(ctx context.Context, orgID, userEmail, role string) error

InviteUserToOrganization invites a user to an organization.

func (*Client) LookupProjectFromRepo

func (c *Client) LookupProjectFromRepo(ctx context.Context, repoURL, repoPath string) (models.Project, error)

LookupProjectFromRepo looks up a project based on repository URL and path.

func (*Client) PreviewDeployment

func (c *Client) PreviewDeployment(
	ctx context.Context,
	orgID, projID, deployType string,
) (models.DeploymentPreview, error)

PreviewDeployment previews a deployment.

func (*Client) SetAuthToken

func (c *Client) SetAuthToken(token string)

SetAuthToken updates the client's authentication credentials.

func (*Client) UpdateProject

func (c *Client) UpdateProject(
	ctx context.Context,
	orgID, projID string,
	project models.Project,
) (models.Project, error)

UpdateProject updates a project.

func (*Client) UpdateUser

func (c *Client) UpdateUser(ctx context.Context, name, email string) error

UpdateUser updates the current user information.

func (*Client) UpdateUserRoleInOrganization

func (c *Client) UpdateUserRoleInOrganization(ctx context.Context, orgID, userEmail, role string) error

UpdateUserRoleInOrganization updates the role of a user in an organization.

type ClientInterface

type ClientInterface interface {

	// GetLoginLink initiates the login flow by getting the login URLs from ArgusID
	GetLoginLink(ctx context.Context) (LoginLinkResponse, error)
	// GetLoginToken polls the callback URL to get the login token status
	GetLoginToken(ctx context.Context, callbackURL string) (models.LoginToken, error)
	// SetAuthToken updates the client's authentication token for API requests
	SetAuthToken(token string)

	// GetUser retrieves the current authenticated user's information
	GetUser(ctx context.Context) (models.User, error)
	// UpdateUser updates the current user's profile information
	UpdateUser(ctx context.Context, name, email string) error
	// InviteUserToOrganization invites a user to join an organization with a specific role
	InviteUserToOrganization(ctx context.Context, orgID, userEmail, role string) error
	// UpdateUserRoleInOrganization updates a user's role within an organization
	UpdateUserRoleInOrganization(ctx context.Context, orgID, userEmail, role string) error
	// GetOrganizationsInvitedTo retrieves organizations the user has been invited to
	GetOrganizationsInvitedTo(ctx context.Context) ([]models.Organization, error)
	// AcceptOrganizationInvitation accepts an invitation to join an organization
	AcceptOrganizationInvitation(ctx context.Context, orgID string) error

	// GetOrganizations retrieves all organizations the user belongs to
	GetOrganizations(ctx context.Context) ([]models.Organization, error)
	// GetOrganizationByID retrieves a specific organization by its ID
	GetOrganizationByID(ctx context.Context, id string) (models.Organization, error)
	// CreateOrganization creates a new organization
	CreateOrganization(ctx context.Context, name, slug string) (models.Organization, error)
	// GetOrganizationMembers retrieves all members of an organization
	GetOrganizationMembers(ctx context.Context, orgID string) ([]models.OrganizationMember, error)

	// GetProjects retrieves all projects within an organization
	GetProjects(ctx context.Context, orgID string) ([]models.Project, error)
	// GetProjectByID retrieves a specific project by its ID
	GetProjectByID(ctx context.Context, projID, orgID string) (models.Project, error)
	// LookupProjectFromRepo looks up a project based on repository URL and path
	LookupProjectFromRepo(ctx context.Context, repoURL, repoPath string) (models.Project, error)
	// CreateProject creates a new project within an organization
	CreateProject(ctx context.Context, orgID string, project models.Project) (models.Project, error)
	// UpdateProject updates an existing project's configuration
	UpdateProject(ctx context.Context, orgID, projID string, project models.Project) (models.Project, error)
	// DeleteProject removes a project from an organization
	DeleteProject(ctx context.Context, orgID, projID string) error
	// CheckProjectSlugIsTaken verifies if a project slug is available
	CheckProjectSlugIsTaken(ctx context.Context, orgID, projID, slug string) error

	// GetListRegions retrieves available deployment regions for a project
	GetListRegions(ctx context.Context, orgID, projID string) ([]string, error)
	// PreviewDeployment shows what would happen during a deployment without executing it
	PreviewDeployment(ctx context.Context, orgID, projID, deployType string) (models.DeploymentPreview, error)
	// DeployProject deploy, resets, destroys, or promotes a project
	DeployProject(ctx context.Context, orgID, projID, deployType string) error
	// GetTemporaryCredential retrieves temporary credentials for a project
	GetTemporaryCredential(ctx context.Context, orgID, projID string) (models.TemporaryCredential, error)
	// GetDeploymentStatus retrieves the current deployment status for a project
	GetDeploymentStatus(ctx context.Context, projID string) ([]byte, error)
	// GetHealthStatus retrieves the health status of deployed services
	GetHealthStatus(ctx context.Context, projID string) ([]byte, error)
	// GetDeploymentHealthStatus retrieves detailed health check results for deployments
	GetDeploymentHealthStatus(ctx context.Context, projID string) (map[string]models.DeploymentHealthCheckResult, error)

	// GetRPCBaseURL returns the RPC service base URL
	// TODO: Remove this once we have a proper RPC client
	GetRPCBaseURL() string
}

ClientInterface defines the contract for making API calls. This interface focuses on business operations rather than low-level HTTP details.

func NewClient

func NewClient(baseURL, rpcURL, argusIDBaseURL string) ClientInterface

NewClient creates a new API client with the given base URL.

type HTTPClientInterface

type HTTPClientInterface interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClientInterface allows for mocking the underlying HTTP client.

type LoginLinkResponse

type LoginLinkResponse struct {
	CallBackURL string `json:"callbackUrl"`
	ClientURL   string `json:"clientUrl"`
}

Login link response structure.

type MockClient

type MockClient struct {
	mock.Mock
}

MockClient is a mock implementation of ClientInterface.

func (*MockClient) AcceptOrganizationInvitation

func (m *MockClient) AcceptOrganizationInvitation(ctx context.Context, orgID string) error

AcceptOrganizationInvitation mocks accepting an organization invitation.

func (*MockClient) CheckProjectSlugIsTaken

func (m *MockClient) CheckProjectSlugIsTaken(ctx context.Context, orgID, projID, slug string) error

CheckProjectSlugIsTaken mocks checking if a project slug is taken.

func (*MockClient) CreateOrganization

func (m *MockClient) CreateOrganization(
	ctx context.Context,
	name, slug string,
) (models.Organization, error)

CreateOrganization mocks creating an organization.

func (*MockClient) CreateProject

func (m *MockClient) CreateProject(ctx context.Context, orgID string, project models.Project) (models.Project, error)

CreateProject mocks creating a project.

func (*MockClient) DeleteProject

func (m *MockClient) DeleteProject(ctx context.Context, orgID, projID string) error

DeleteProject mocks deleting a project.

func (*MockClient) DeployProject

func (m *MockClient) DeployProject(
	ctx context.Context,
	orgID, projID, deployType string,
) error

DeployProject mocks deploying a project.

func (*MockClient) GetDeploymentHealthStatus

func (m *MockClient) GetDeploymentHealthStatus(
	ctx context.Context,
	projID string,
) (map[string]models.DeploymentHealthCheckResult, error)

GetDeploymentHealthStatus mocks getting deployment health status.

func (*MockClient) GetDeploymentStatus

func (m *MockClient) GetDeploymentStatus(ctx context.Context, projID string) ([]byte, error)

GetDeploymentStatus mocks getting deployment status.

func (*MockClient) GetHealthStatus

func (m *MockClient) GetHealthStatus(ctx context.Context, projID string) ([]byte, error)

GetHealthStatus mocks getting health status.

func (*MockClient) GetListRegions

func (m *MockClient) GetListRegions(ctx context.Context, orgID, projID string) ([]string, error)

GetListRegions mocks getting list of regions.

func (m *MockClient) GetLoginLink(ctx context.Context) (LoginLinkResponse, error)

GetLoginLink mocks getting the login link.

func (*MockClient) GetLoginToken

func (m *MockClient) GetLoginToken(ctx context.Context, callbackURL string) (models.LoginToken, error)

GetLoginToken mocks getting the login token.

func (*MockClient) GetOrganizationByID

func (m *MockClient) GetOrganizationByID(ctx context.Context, id string) (models.Organization, error)

GetOrganizationByID mocks getting an organization by ID.

func (*MockClient) GetOrganizationMembers

func (m *MockClient) GetOrganizationMembers(ctx context.Context, orgID string) ([]models.OrganizationMember, error)

GetOrganizationMembers mocks getting organization members.

func (*MockClient) GetOrganizations

func (m *MockClient) GetOrganizations(ctx context.Context) ([]models.Organization, error)

GetOrganizations mocks getting organizations.

func (*MockClient) GetOrganizationsInvitedTo

func (m *MockClient) GetOrganizationsInvitedTo(ctx context.Context) ([]models.Organization, error)

GetOrganizationsInvitedTo mocks getting organization invitations.

func (*MockClient) GetProjectByID

func (m *MockClient) GetProjectByID(ctx context.Context, orgID, projID string) (models.Project, error)

GetProjectByID mocks getting a project by ID.

func (*MockClient) GetProjects

func (m *MockClient) GetProjects(ctx context.Context, orgID string) ([]models.Project, error)

GetProjects mocks getting projects for an organization.

func (*MockClient) GetRPCBaseURL

func (m *MockClient) GetRPCBaseURL() string

TODO: Remove this once we have a proper RPC client GetRPCBaseURL mocks getting RPC base URL.

func (*MockClient) GetTemporaryCredential

func (m *MockClient) GetTemporaryCredential(
	ctx context.Context,
	orgID, projID string,
) (models.TemporaryCredential, error)

func (*MockClient) GetUser

func (m *MockClient) GetUser(ctx context.Context) (models.User, error)

GetUser mocks getting user information.

func (*MockClient) InviteUserToOrganization

func (m *MockClient) InviteUserToOrganization(ctx context.Context, orgID, userEmail, role string) error

InviteUserToOrganization mocks inviting a user to an organization.

func (*MockClient) LookupProjectFromRepo

func (m *MockClient) LookupProjectFromRepo(ctx context.Context, repoURL, repoPath string) (models.Project, error)

LookupProjectFromRepo mocks looking up a project from repository information.

func (*MockClient) PreviewDeployment

func (m *MockClient) PreviewDeployment(
	ctx context.Context,
	orgID, projID, deployType string,
) (models.DeploymentPreview, error)

PreviewDeployment mocks previewing a deployment.

func (*MockClient) SetAuthToken

func (m *MockClient) SetAuthToken(token string)

SetAuthToken mocks setting auth token.

func (*MockClient) UpdateProject

func (m *MockClient) UpdateProject(
	ctx context.Context,
	orgID, projID string,
	project models.Project,
) (models.Project, error)

UpdateProject mocks updating a project.

func (*MockClient) UpdateUser

func (m *MockClient) UpdateUser(ctx context.Context, name, email string) error

UpdateUser mocks updating user information.

func (*MockClient) UpdateUserRoleInOrganization

func (m *MockClient) UpdateUserRoleInOrganization(ctx context.Context, orgID, userEmail, role string) error

UpdateUserRoleInOrganization mocks updating user role in organization.

type MockHTTPClient

type MockHTTPClient struct {
	mock.Mock
}

MockHTTPClient is a mock implementation of HTTPClientInterface for testing.

func (*MockHTTPClient) Do

func (m *MockHTTPClient) Do(req *http.Request) (*http.Response, error)

type RequestConfig

type RequestConfig struct {
	MaxRetries    int
	BaseDelay     time.Duration
	Timeout       time.Duration
	ContentType   string
	CustomHeaders map[string]string
}

RequestConfig holds configuration for individual requests.

func DefaultRequestConfig

func DefaultRequestConfig() RequestConfig

DefaultRequestConfig returns sensible defaults.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL