Fix lint errors
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
d7d6d1e31a
commit
e51f19acc8
15 changed files with 109 additions and 68 deletions
|
|
@ -445,7 +445,7 @@ func (g *githubClient) GithubBaseURL() *url.URL {
|
|||
return g.cli.BaseURL
|
||||
}
|
||||
|
||||
func GithubClient(ctx context.Context, entity params.GithubEntity) (common.GithubClient, error) {
|
||||
func Client(ctx context.Context, entity params.GithubEntity) (common.GithubClient, error) {
|
||||
// func GithubClient(ctx context.Context, entity params.GithubEntity) (common.GithubClient, error) {
|
||||
httpClient, err := entity.Credentials.GetHTTPClient(ctx)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -29,10 +29,10 @@ type acquireJobsResult struct {
|
|||
Value []int64 `json:"value"`
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) AcquireJobs(ctx context.Context, runnerScaleSetId int, messageQueueAccessToken string, requestIds []int64) ([]int64, error) {
|
||||
u := fmt.Sprintf("%s/%d/acquirejobs?api-version=6.0-preview", scaleSetEndpoint, runnerScaleSetId)
|
||||
func (s *ScaleSetClient) AcquireJobs(ctx context.Context, runnerScaleSetID int, messageQueueAccessToken string, requestIDs []int64) ([]int64, error) {
|
||||
u := fmt.Sprintf("%s/%d/acquirejobs?api-version=6.0-preview", scaleSetEndpoint, runnerScaleSetID)
|
||||
|
||||
body, err := json.Marshal(requestIds)
|
||||
body, err := json.Marshal(requestIDs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -60,8 +60,8 @@ func (s *ScaleSetClient) AcquireJobs(ctx context.Context, runnerScaleSetId int,
|
|||
return acquiredJobs.Value, nil
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) GetAcquirableJobs(ctx context.Context, runnerScaleSetId int) (params.AcquirableJobList, error) {
|
||||
path := fmt.Sprintf("%d/acquirablejobs", runnerScaleSetId)
|
||||
func (s *ScaleSetClient) GetAcquirableJobs(ctx context.Context, runnerScaleSetID int) (params.AcquirableJobList, error) {
|
||||
path := fmt.Sprintf("%d/acquirablejobs", runnerScaleSetID)
|
||||
|
||||
req, err := s.newActionsRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -17,11 +17,12 @@ package scalesets
|
|||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"math/rand/v2"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
|
@ -103,7 +104,7 @@ func (m *MessageSession) SessionsRelativeURL() (string, error) {
|
|||
if m.session.RunnerScaleSet == nil {
|
||||
return "", fmt.Errorf("runner scale set is nil")
|
||||
}
|
||||
relativePath := fmt.Sprintf("%s/%d/sessions/%s", scaleSetEndpoint, m.session.RunnerScaleSet.Id, m.session.SessionId.String())
|
||||
relativePath := fmt.Sprintf("%s/%d/sessions/%s", scaleSetEndpoint, m.session.RunnerScaleSet.ID, m.session.SessionID.String())
|
||||
return relativePath, nil
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +139,11 @@ func (m *MessageSession) maybeRefreshToken(ctx context.Context) error {
|
|||
return fmt.Errorf("session is nil")
|
||||
}
|
||||
// add some jitter
|
||||
jitter := time.Duration(rand.IntN(10000)) * time.Millisecond
|
||||
randInt, err := rand.Int(rand.Reader, big.NewInt(1000))
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get a random number")
|
||||
}
|
||||
jitter := time.Duration(randInt.Int64()) * time.Millisecond
|
||||
if m.session.ExpiresIn(2*time.Minute + jitter) {
|
||||
if err := m.Refresh(ctx); err != nil {
|
||||
return fmt.Errorf("failed to refresh message queue token: %w", err)
|
||||
|
|
@ -147,15 +152,15 @@ func (m *MessageSession) maybeRefreshToken(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *MessageSession) GetMessage(ctx context.Context, lastMessageId int64, maxCapacity uint) (params.RunnerScaleSetMessage, error) {
|
||||
u, err := url.Parse(m.session.MessageQueueUrl)
|
||||
func (m *MessageSession) GetMessage(ctx context.Context, lastMessageID int64, maxCapacity uint) (params.RunnerScaleSetMessage, error) {
|
||||
u, err := url.Parse(m.session.MessageQueueURL)
|
||||
if err != nil {
|
||||
return params.RunnerScaleSetMessage{}, err
|
||||
}
|
||||
|
||||
if lastMessageId > 0 {
|
||||
if lastMessageID > 0 {
|
||||
q := u.Query()
|
||||
q.Set("lastMessageId", strconv.FormatInt(lastMessageId, 10))
|
||||
q.Set("lastMessageId", strconv.FormatInt(lastMessageID, 10))
|
||||
u.RawQuery = q.Encode()
|
||||
}
|
||||
|
||||
|
|
@ -185,13 +190,13 @@ func (m *MessageSession) GetMessage(ctx context.Context, lastMessageId int64, ma
|
|||
return message, nil
|
||||
}
|
||||
|
||||
func (m *MessageSession) DeleteMessage(ctx context.Context, messageId int64) error {
|
||||
u, err := url.Parse(m.session.MessageQueueUrl)
|
||||
func (m *MessageSession) DeleteMessage(ctx context.Context, messageID int64) error {
|
||||
u, err := url.Parse(m.session.MessageQueueURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
u.Path = fmt.Sprintf("%s/%d", u.Path, messageId)
|
||||
u.Path = fmt.Sprintf("%s/%d", u.Path, messageID)
|
||||
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, u.String(), nil)
|
||||
if err != nil {
|
||||
|
|
@ -210,8 +215,8 @@ func (m *MessageSession) DeleteMessage(ctx context.Context, messageId int64) err
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) CreateMessageSession(ctx context.Context, runnerScaleSetId int, owner string) (*MessageSession, error) {
|
||||
path := fmt.Sprintf("%s/%d/sessions", scaleSetEndpoint, runnerScaleSetId)
|
||||
func (s *ScaleSetClient) CreateMessageSession(ctx context.Context, runnerScaleSetID int, owner string) (*MessageSession, error) {
|
||||
path := fmt.Sprintf("%s/%d/sessions", scaleSetEndpoint, runnerScaleSetID)
|
||||
|
||||
newSession := params.RunnerScaleSetSession{
|
||||
OwnerName: owner,
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ func (s *ScaleSetClient) GenerateJitRunnerConfig(ctx context.Context, runnerName
|
|||
return params.RunnerScaleSetJitRunnerConfig{}, err
|
||||
}
|
||||
|
||||
req, err := s.newActionsRequest(ctx, http.MethodPost, scaleSet.RunnerJitConfigUrl, bytes.NewBuffer(body))
|
||||
req, err := s.newActionsRequest(ctx, http.MethodPost, scaleSet.RunnerJitConfigURL, bytes.NewBuffer(body))
|
||||
if err != nil {
|
||||
return params.RunnerScaleSetJitRunnerConfig{}, fmt.Errorf("failed to create request: %w", err)
|
||||
}
|
||||
|
|
@ -59,8 +59,8 @@ func (s *ScaleSetClient) GenerateJitRunnerConfig(ctx context.Context, runnerName
|
|||
return runnerJitConfig, nil
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) GetRunner(ctx context.Context, runnerId int64) (params.RunnerReference, error) {
|
||||
path := fmt.Sprintf("%s/%d", runnerEndpoint, runnerId)
|
||||
func (s *ScaleSetClient) GetRunner(ctx context.Context, runnerID int64) (params.RunnerReference, error) {
|
||||
path := fmt.Sprintf("%s/%d", runnerEndpoint, runnerID)
|
||||
|
||||
req, err := s.newActionsRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
|
|
@ -111,8 +111,8 @@ func (s *ScaleSetClient) GetRunnerByName(ctx context.Context, runnerName string)
|
|||
return runnerList.RunnerReferences[0], nil
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) RemoveRunner(ctx context.Context, runnerId int64) error {
|
||||
path := fmt.Sprintf("%s/%d", runnerEndpoint, runnerId)
|
||||
func (s *ScaleSetClient) RemoveRunner(ctx context.Context, runnerID int64) error {
|
||||
path := fmt.Sprintf("%s/%d", runnerEndpoint, runnerID)
|
||||
|
||||
req, err := s.newActionsRequest(ctx, http.MethodDelete, path, nil)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ const (
|
|||
HeaderGitHubRequestID = "X-GitHub-Request-Id"
|
||||
)
|
||||
|
||||
func (s *ScaleSetClient) GetRunnerScaleSetByNameAndRunnerGroup(ctx context.Context, runnerGroupId int, name string) (params.RunnerScaleSet, error) {
|
||||
path := fmt.Sprintf("%s?runnerGroupId=%d&name=%s", scaleSetEndpoint, runnerGroupId, name)
|
||||
func (s *ScaleSetClient) GetRunnerScaleSetByNameAndRunnerGroup(ctx context.Context, runnerGroupID int, name string) (params.RunnerScaleSet, error) {
|
||||
path := fmt.Sprintf("%s?runnerGroupId=%d&name=%s", scaleSetEndpoint, runnerGroupID, name)
|
||||
req, err := s.newActionsRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return params.RunnerScaleSet{}, err
|
||||
|
|
@ -53,7 +53,7 @@ func (s *ScaleSetClient) GetRunnerScaleSetByNameAndRunnerGroup(ctx context.Conte
|
|||
return params.RunnerScaleSet{}, fmt.Errorf("failed to decode response: %w", err)
|
||||
}
|
||||
if runnerScaleSetList.Count == 0 {
|
||||
return params.RunnerScaleSet{}, runnerErrors.NewNotFoundError("runner scale set with name %s and runner group ID %d was not found", name, runnerGroupId)
|
||||
return params.RunnerScaleSet{}, runnerErrors.NewNotFoundError("runner scale set with name %s and runner group ID %d was not found", name, runnerGroupID)
|
||||
}
|
||||
|
||||
// Runner scale sets must have a uniqe name. Attempting to create a runner scale set with the same name as
|
||||
|
|
@ -61,8 +61,8 @@ func (s *ScaleSetClient) GetRunnerScaleSetByNameAndRunnerGroup(ctx context.Conte
|
|||
return runnerScaleSetList.RunnerScaleSets[0], nil
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) GetRunnerScaleSetById(ctx context.Context, runnerScaleSetId int) (params.RunnerScaleSet, error) {
|
||||
path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetId)
|
||||
func (s *ScaleSetClient) GetRunnerScaleSetByID(ctx context.Context, runnerScaleSetID int) (params.RunnerScaleSet, error) {
|
||||
path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetID)
|
||||
req, err := s.newActionsRequest(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return params.RunnerScaleSet{}, err
|
||||
|
|
@ -70,7 +70,7 @@ func (s *ScaleSetClient) GetRunnerScaleSetById(ctx context.Context, runnerScaleS
|
|||
|
||||
resp, err := s.Do(req)
|
||||
if err != nil {
|
||||
return params.RunnerScaleSet{}, fmt.Errorf("failed to get runner scaleset with ID %d: %w", runnerScaleSetId, err)
|
||||
return params.RunnerScaleSet{}, fmt.Errorf("failed to get runner scaleset with ID %d: %w", runnerScaleSetID, err)
|
||||
}
|
||||
|
||||
var runnerScaleSet params.RunnerScaleSet
|
||||
|
|
@ -127,8 +127,8 @@ func (s *ScaleSetClient) CreateRunnerScaleSet(ctx context.Context, runnerScaleSe
|
|||
return createdRunnerScaleSet, nil
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) UpdateRunnerScaleSet(ctx context.Context, runnerScaleSetId int, runnerScaleSet params.RunnerScaleSet) (params.RunnerScaleSet, error) {
|
||||
path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetId)
|
||||
func (s *ScaleSetClient) UpdateRunnerScaleSet(ctx context.Context, runnerScaleSetID int, runnerScaleSet params.RunnerScaleSet) (params.RunnerScaleSet, error) {
|
||||
path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetID)
|
||||
|
||||
body, err := json.Marshal(runnerScaleSet)
|
||||
if err != nil {
|
||||
|
|
@ -152,8 +152,8 @@ func (s *ScaleSetClient) UpdateRunnerScaleSet(ctx context.Context, runnerScaleSe
|
|||
return ret, nil
|
||||
}
|
||||
|
||||
func (s *ScaleSetClient) DeleteRunnerScaleSet(ctx context.Context, runnerScaleSetId int) error {
|
||||
path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetId)
|
||||
func (s *ScaleSetClient) DeleteRunnerScaleSet(ctx context.Context, runnerScaleSetID int) error {
|
||||
path := fmt.Sprintf("%s/%d", scaleSetEndpoint, runnerScaleSetID)
|
||||
req, err := s.newActionsRequest(ctx, http.MethodDelete, path, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -26,12 +26,12 @@ func (s *ScaleSetClient) newActionsRequest(ctx context.Context, method, path str
|
|||
return nil, fmt.Errorf("failed to update token: %w", err)
|
||||
}
|
||||
|
||||
actionsUri, err := s.actionsServiceInfo.GetURL()
|
||||
actionsURI, err := s.actionsServiceInfo.GetURL()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get pipeline URL: %w", err)
|
||||
}
|
||||
|
||||
uri, err := actionsUri.Parse(path)
|
||||
uri, err := actionsURI.Parse(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse path: %w", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue