garm/params/params.go

267 lines
8.7 KiB
Go
Raw Normal View History

2022-05-05 13:25:50 +00:00
// Copyright 2022 Cloudbase Solutions SRL
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations
// under the License.
2022-04-15 15:22:47 +00:00
package params
import (
"garm/config"
"garm/runner/providers/common"
2022-04-28 16:13:20 +00:00
"time"
2022-04-18 17:26:13 +00:00
2022-10-20 12:07:56 +03:00
"github.com/google/go-github/v48/github"
2022-04-28 16:13:20 +00:00
uuid "github.com/satori/go.uuid"
2022-04-15 15:22:47 +00:00
)
2022-04-26 20:29:58 +00:00
type AddressType string
const (
PublicAddress AddressType = "public"
PrivateAddress AddressType = "private"
)
type Address struct {
Address string `json:"address"`
Type AddressType `json:"type"`
}
2022-05-03 19:49:14 +00:00
type StatusMessage struct {
CreatedAt time.Time `json:"created_at"`
Message string `json:"message"`
}
2022-04-15 15:22:47 +00:00
type Instance struct {
2022-04-26 20:29:58 +00:00
// ID is the database ID of this instance.
ID string `json:"id,omitempty"`
2022-04-15 15:22:47 +00:00
// PeoviderID is the unique ID the provider associated
// with the compute instance. We use this to identify the
// instance in the provider.
ProviderID string `json:"provider_id,omitempty"`
// AgentID is the github runner agent ID.
AgentID int64 `json:"agent_id"`
2022-04-15 15:22:47 +00:00
// Name is the name associated with an instance. Depending on
// the provider, this may or may not be useful in the context of
// the provider, but we can use it internally to identify the
// instance.
Name string `json:"name,omitempty"`
// OSType is the operating system type. For now, only Linux and
// Windows are supported.
2022-04-26 20:29:58 +00:00
OSType config.OSType `json:"os_type,omitempty"`
// OSName is the name of the OS. Eg: ubuntu, centos, etc.
2022-04-26 20:29:58 +00:00
OSName string `json:"os_name,omitempty"`
2022-04-15 15:22:47 +00:00
// OSVersion is the version of the operating system.
2022-04-26 20:29:58 +00:00
OSVersion string `json:"os_version,omitempty"`
2022-04-15 15:22:47 +00:00
// OSArch is the operating system architecture.
2022-04-26 20:29:58 +00:00
OSArch config.OSArch `json:"os_arch,omitempty"`
2022-04-15 15:22:47 +00:00
// Addresses is a list of IP addresses the provider reports
// for this instance.
2022-04-26 20:29:58 +00:00
Addresses []Address `json:"addresses,omitempty"`
// Status is the status of the instance inside the provider (eg: running, stopped, etc)
Status common.InstanceStatus `json:"status,omitempty"`
RunnerStatus common.RunnerStatus `json:"runner_status,omitempty"`
PoolID string `json:"pool_id,omitempty"`
ProviderFault []byte `json:"provider_fault,omitempty"`
2022-04-26 20:29:58 +00:00
2022-05-03 19:49:14 +00:00
StatusMessages []StatusMessage `json:"status_messages,omitempty"`
UpdatedAt time.Time `json:"updated_at"`
2022-05-03 19:49:14 +00:00
2022-04-26 20:29:58 +00:00
// Do not serialize sensitive info.
CallbackURL string `json:"-"`
MetadataURL string `json:"-"`
CreateAttempt int `json:"-"`
2022-04-15 15:22:47 +00:00
}
2022-04-18 17:26:13 +00:00
2022-12-04 17:30:27 +00:00
func (i Instance) GetName() string {
return i.Name
}
func (i Instance) GetID() string {
return i.ID
}
2022-04-18 17:26:13 +00:00
type BootstrapInstance struct {
2022-04-26 20:29:58 +00:00
Name string `json:"name"`
2022-04-18 17:26:13 +00:00
Tools []*github.RunnerApplicationDownload `json:"tools"`
// RepoURL is the URL the github runner agent needs to configure itself.
RepoURL string `json:"repo_url"`
// CallbackUrl is the URL where the instance can send a post, signaling
// progress or status.
CallbackURL string `json:"callback-url"`
// MetadataURL is the URL where instances can fetch information needed to set themselves up.
MetadataURL string `json:"metadata-url"`
2022-04-18 17:26:13 +00:00
// InstanceToken is the token that needs to be set by the instance in the headers
// in order to send updated back to the garm via CallbackURL.
InstanceToken string `json:"instance-token"`
2022-04-18 17:26:13 +00:00
// SSHKeys are the ssh public keys we may want to inject inside the runners, if the
// provider supports it.
SSHKeys []string `json:"ssh-keys"`
2022-04-22 14:46:27 +00:00
CACertBundle []byte `json:"ca-cert-bundle"`
2022-04-22 14:46:27 +00:00
OSArch config.OSArch `json:"arch"`
Flavor string `json:"flavor"`
Image string `json:"image"`
Labels []string `json:"labels"`
2022-04-26 20:29:58 +00:00
PoolID string `json:"pool_id"`
2022-04-18 17:26:13 +00:00
}
2022-04-25 00:03:26 +00:00
type Tag struct {
ID string `json:"id"`
Name string `json:"name"`
}
type Pool struct {
ID string `json:"id"`
ProviderName string `json:"provider_name"`
MaxRunners uint `json:"max_runners"`
MinIdleRunners uint `json:"min_idle_runners"`
Image string `json:"image"`
Flavor string `json:"flavor"`
OSType config.OSType `json:"os_type"`
OSArch config.OSArch `json:"os_arch"`
Tags []Tag `json:"tags"`
Enabled bool `json:"enabled"`
Instances []Instance `json:"instances"`
RepoID string `json:"repo_id,omitempty"`
RepoName string `json:"repo_name,omitempty"`
OrgID string `json:"org_id,omitempty"`
OrgName string `json:"org_name,omitempty"`
EnterpriseID string `json:"enterprise_id,omitempty"`
EnterpriseName string `json:"enterprise_name,omitempty"`
RunnerBootstrapTimeout uint `json:"runner_bootstrap_timeout"`
}
2022-12-04 17:30:27 +00:00
func (p Pool) GetID() string {
return p.ID
}
func (p *Pool) RunnerTimeout() uint {
if p.RunnerBootstrapTimeout == 0 {
return config.DefaultRunnerBootstrapTimeout
}
return p.RunnerBootstrapTimeout
2022-04-25 00:03:26 +00:00
}
2022-04-26 20:29:58 +00:00
type Internal struct {
OAuth2Token string `json:"oauth2"`
ControllerID string `json:"controller_id"`
InstanceCallbackURL string `json:"instance_callback_url"`
InstanceMetadataURL string `json:"instance_metadata_url"`
2022-04-27 16:56:28 +00:00
JWTSecret string `json:"jwt_secret"`
// GithubCredentialsDetails contains all info about the credentials, except the
// token, which is added above.
GithubCredentialsDetails GithubCredentials `json:"gh_creds_details"`
2022-04-26 20:29:58 +00:00
}
2022-04-25 00:03:26 +00:00
type Repository struct {
ID string `json:"id"`
Owner string `json:"owner"`
Name string `json:"name"`
Pools []Pool `json:"pool,omitempty"`
CredentialsName string `json:"credentials_name"`
PoolManagerStatus PoolManagerStatus `json:"pool_manager_status,omitempty"`
2022-04-26 20:29:58 +00:00
// Do not serialize sensitive info.
WebhookSecret string `json:"-"`
2022-04-25 00:03:26 +00:00
}
2022-12-04 17:30:27 +00:00
func (r Repository) GetName() string {
return r.Name
}
func (r Repository) GetID() string {
return r.ID
}
2022-04-25 00:03:26 +00:00
type Organization struct {
ID string `json:"id"`
Name string `json:"name"`
Pools []Pool `json:"pool,omitempty"`
CredentialsName string `json:"credentials_name"`
PoolManagerStatus PoolManagerStatus `json:"pool_manager_status,omitempty"`
2022-04-26 20:29:58 +00:00
// Do not serialize sensitive info.
WebhookSecret string `json:"-"`
2022-04-25 00:03:26 +00:00
}
2022-12-04 17:30:27 +00:00
func (o Organization) GetName() string {
return o.Name
}
func (o Organization) GetID() string {
return o.ID
}
type Enterprise struct {
ID string `json:"id"`
Name string `json:"name"`
Pools []Pool `json:"pool,omitempty"`
CredentialsName string `json:"credentials_name"`
PoolManagerStatus PoolManagerStatus `json:"pool_manager_status,omitempty"`
// Do not serialize sensitive info.
WebhookSecret string `json:"-"`
}
2022-12-04 17:30:27 +00:00
func (e Enterprise) GetName() string {
return e.Name
}
func (e Enterprise) GetID() string {
return e.ID
}
2022-04-28 16:13:20 +00:00
// Users holds information about a particular user
type User struct {
ID string `json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Email string `json:"email"`
Username string `json:"username"`
FullName string `json:"full_name"`
Password string `json:"-"`
Enabled bool `json:"enabled"`
IsAdmin bool `json:"is_admin"`
2022-04-25 00:03:26 +00:00
}
2022-04-26 20:29:58 +00:00
2022-04-28 16:13:20 +00:00
// JWTResponse holds the JWT token returned as a result of a
// successful auth
type JWTResponse struct {
Token string `json:"token"`
}
2022-04-26 20:29:58 +00:00
2022-04-28 16:13:20 +00:00
type ControllerInfo struct {
ControllerID uuid.UUID `json:"controller_id"`
2022-04-26 20:29:58 +00:00
}
2022-04-28 16:13:20 +00:00
type GithubCredentials struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
BaseURL string `json:"base_url"`
APIBaseURL string `json:"api_base_url"`
UploadBaseURL string `json:"upload_base_url"`
CABundle []byte `json:"ca_bundle,omitempty"`
2022-04-27 16:56:28 +00:00
}
2022-04-28 16:13:20 +00:00
type Provider struct {
Name string `json:"name"`
ProviderType config.ProviderType `json:"type"`
2022-05-03 19:49:14 +00:00
Description string `json:"description"`
2022-04-27 16:56:28 +00:00
}
2022-05-04 16:27:24 +00:00
type UpdatePoolStateParams struct {
WebhookSecret string
}
type PoolManagerStatus struct {
IsRunning bool `json:"running"`
FailureReason string `json:"failure_reason,omitempty"`
}