Fixed a bunch of linting issues
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
687c48127b
commit
b354cedf7e
22 changed files with 76 additions and 60 deletions
|
|
@ -42,11 +42,7 @@ type Authenticator struct {
|
|||
}
|
||||
|
||||
func (a *Authenticator) IsInitialized() bool {
|
||||
if a.store.HasAdminUser(context.Background()) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
return a.store.HasAdminUser(context.Background())
|
||||
}
|
||||
|
||||
func (a *Authenticator) GetJWTToken(ctx context.Context) (string, error) {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ package auth
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"garm/apiserver/params"
|
||||
|
|
@ -40,7 +41,9 @@ func (i *initRequired) Middleware(next http.Handler) http.Handler {
|
|||
if err != nil || ctrlInfo.ControllerID.String() == "" {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusConflict)
|
||||
json.NewEncoder(w).Encode(params.InitializationRequired)
|
||||
if err := json.NewEncoder(w).Encode(params.InitializationRequired); err != nil {
|
||||
log.Printf("failed to encode response: %s", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
ctx := r.Context()
|
||||
|
|
|
|||
|
|
@ -73,7 +73,6 @@ func NewInstanceJWTToken(instance params.Instance, secret, entity string, poolTy
|
|||
// used with gorilla
|
||||
type instanceMiddleware struct {
|
||||
store dbCommon.Store
|
||||
auth *Authenticator
|
||||
cfg config.JWTAuth
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
|
|
@ -42,7 +43,6 @@ type JWTClaims struct {
|
|||
// used with gorilla
|
||||
type jwtMiddleware struct {
|
||||
store dbCommon.Store
|
||||
auth *Authenticator
|
||||
cfg config.JWTAuth
|
||||
}
|
||||
|
||||
|
|
@ -75,10 +75,12 @@ func (amw *jwtMiddleware) claimsToContext(ctx context.Context, claims *JWTClaims
|
|||
func invalidAuthResponse(w http.ResponseWriter) {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(
|
||||
if err := json.NewEncoder(w).Encode(
|
||||
apiParams.APIErrorResponse{
|
||||
Error: "Authentication failed",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Middleware implements the middleware interface
|
||||
|
|
|
|||
|
|
@ -139,8 +139,8 @@ func init() {
|
|||
enterpriseAddCmd.Flags().StringVar(&enterpriseName, "name", "", "The name of the enterprise")
|
||||
enterpriseAddCmd.Flags().StringVar(&enterpriseWebhookSecret, "webhook-secret", "", "The webhook secret for this enterprise")
|
||||
enterpriseAddCmd.Flags().StringVar(&enterpriseCreds, "credentials", "", "Credentials name. See credentials list.")
|
||||
enterpriseAddCmd.MarkFlagRequired("credentials")
|
||||
enterpriseAddCmd.MarkFlagRequired("name")
|
||||
enterpriseAddCmd.MarkFlagRequired("credentials") //nolint
|
||||
enterpriseAddCmd.MarkFlagRequired("name") //nolint
|
||||
|
||||
enterpriseCmd.AddCommand(
|
||||
enterpriseListCmd,
|
||||
|
|
|
|||
|
|
@ -128,8 +128,8 @@ func init() {
|
|||
initCmd.Flags().StringVarP(&loginEmail, "email", "e", "", "Email address")
|
||||
initCmd.Flags().StringVarP(&loginFullName, "full-name", "f", "", "Full name of the user")
|
||||
initCmd.Flags().StringVarP(&loginPassword, "password", "p", "", "The admin password")
|
||||
initCmd.MarkFlagRequired("name")
|
||||
initCmd.MarkFlagRequired("url")
|
||||
initCmd.MarkFlagRequired("name") //nolint
|
||||
initCmd.MarkFlagRequired("url") //nolint
|
||||
}
|
||||
|
||||
func renderUserTable(user params.User) {
|
||||
|
|
|
|||
|
|
@ -238,10 +238,10 @@ func init() {
|
|||
orgPoolAddCmd.Flags().UintVar(&poolMaxRunners, "max-runners", 5, "The maximum number of runner this pool will create.")
|
||||
orgPoolAddCmd.Flags().UintVar(&poolMinIdleRunners, "min-idle-runners", 1, "Attempt to maintain a minimum of idle self-hosted runners of this type.")
|
||||
orgPoolAddCmd.Flags().BoolVar(&poolEnabled, "enabled", false, "Enable this pool.")
|
||||
orgPoolAddCmd.MarkFlagRequired("provider-name")
|
||||
orgPoolAddCmd.MarkFlagRequired("image")
|
||||
orgPoolAddCmd.MarkFlagRequired("flavor")
|
||||
orgPoolAddCmd.MarkFlagRequired("tags")
|
||||
orgPoolAddCmd.MarkFlagRequired("provider-name") //nolint
|
||||
orgPoolAddCmd.MarkFlagRequired("image") //nolint
|
||||
orgPoolAddCmd.MarkFlagRequired("flavor") //nolint
|
||||
orgPoolAddCmd.MarkFlagRequired("tags") //nolint
|
||||
|
||||
orgPoolUpdateCmd.Flags().StringVar(&poolImage, "image", "", "The provider-specific image name to use for runners in this pool.")
|
||||
orgPoolUpdateCmd.Flags().StringVar(&poolFlavor, "flavor", "", "The flavor to use for this runner.")
|
||||
|
|
|
|||
|
|
@ -139,8 +139,8 @@ func init() {
|
|||
orgAddCmd.Flags().StringVar(&orgName, "name", "", "The name of the organization")
|
||||
orgAddCmd.Flags().StringVar(&orgWebhookSecret, "webhook-secret", "", "The webhook secret for this organization")
|
||||
orgAddCmd.Flags().StringVar(&orgCreds, "credentials", "", "Credentials name. See credentials list.")
|
||||
orgAddCmd.MarkFlagRequired("credentials")
|
||||
orgAddCmd.MarkFlagRequired("name")
|
||||
orgAddCmd.MarkFlagRequired("credentials") //nolint
|
||||
orgAddCmd.MarkFlagRequired("name") //nolint
|
||||
|
||||
organizationCmd.AddCommand(
|
||||
orgListCmd,
|
||||
|
|
|
|||
|
|
@ -85,11 +85,11 @@ Example:
|
|||
} else if cmd.Flags().Changed("all") {
|
||||
pools, err = cli.ListAllPools()
|
||||
} else {
|
||||
cmd.Help()
|
||||
cmd.Help() //nolint
|
||||
os.Exit(0)
|
||||
}
|
||||
default:
|
||||
cmd.Help()
|
||||
cmd.Help() //nolint
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
|
@ -195,7 +195,7 @@ var poolAddCmd = &cobra.Command{
|
|||
} else if cmd.Flags().Changed("enterprise") {
|
||||
pool, err = cli.CreateEnterprisePool(poolEnterprise, newPoolParams)
|
||||
} else {
|
||||
cmd.Help()
|
||||
cmd.Help() //nolint
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
|
@ -313,10 +313,10 @@ func init() {
|
|||
poolAddCmd.Flags().UintVar(&poolRunnerBootstrapTimeout, "runner-bootstrap-timeout", 20, "Duration in minutes after which a runner is considered failed if it does not join Github.")
|
||||
poolAddCmd.Flags().UintVar(&poolMinIdleRunners, "min-idle-runners", 1, "Attempt to maintain a minimum of idle self-hosted runners of this type.")
|
||||
poolAddCmd.Flags().BoolVar(&poolEnabled, "enabled", false, "Enable this pool.")
|
||||
poolAddCmd.MarkFlagRequired("provider-name")
|
||||
poolAddCmd.MarkFlagRequired("image")
|
||||
poolAddCmd.MarkFlagRequired("flavor")
|
||||
poolAddCmd.MarkFlagRequired("tags")
|
||||
poolAddCmd.MarkFlagRequired("provider-name") //nolint
|
||||
poolAddCmd.MarkFlagRequired("image") //nolint
|
||||
poolAddCmd.MarkFlagRequired("flavor") //nolint
|
||||
poolAddCmd.MarkFlagRequired("tags") //nolint
|
||||
|
||||
poolAddCmd.Flags().StringVarP(&poolRepository, "repo", "r", "", "Add the new pool within this repository.")
|
||||
poolAddCmd.Flags().StringVarP(&poolOrganization, "org", "o", "", "Add the new pool withing this organization.")
|
||||
|
|
|
|||
|
|
@ -218,8 +218,8 @@ func init() {
|
|||
profileAddCmd.Flags().StringVarP(&loginURL, "url", "a", "", "The base URL for the runner manager API")
|
||||
profileAddCmd.Flags().StringVarP(&loginUserName, "username", "u", "", "Username to log in as")
|
||||
profileAddCmd.Flags().StringVarP(&loginPassword, "password", "p", "", "The user passowrd")
|
||||
profileAddCmd.MarkFlagRequired("name")
|
||||
profileAddCmd.MarkFlagRequired("url")
|
||||
profileAddCmd.MarkFlagRequired("name") //nolint
|
||||
profileAddCmd.MarkFlagRequired("url") //nolint
|
||||
|
||||
profileCmd.AddCommand(
|
||||
profileListCmd,
|
||||
|
|
|
|||
|
|
@ -225,10 +225,10 @@ func init() {
|
|||
repoPoolAddCmd.Flags().UintVar(&poolMaxRunners, "max-runners", 5, "The maximum number of runner this pool will create.")
|
||||
repoPoolAddCmd.Flags().UintVar(&poolMinIdleRunners, "min-idle-runners", 1, "Attempt to maintain a minimum of idle self-hosted runners of this type.")
|
||||
repoPoolAddCmd.Flags().BoolVar(&poolEnabled, "enabled", false, "Enable this pool.")
|
||||
repoPoolAddCmd.MarkFlagRequired("provider-name")
|
||||
repoPoolAddCmd.MarkFlagRequired("image")
|
||||
repoPoolAddCmd.MarkFlagRequired("flavor")
|
||||
repoPoolAddCmd.MarkFlagRequired("tags")
|
||||
repoPoolAddCmd.MarkFlagRequired("provider-name") //nolint
|
||||
repoPoolAddCmd.MarkFlagRequired("image") //nolint
|
||||
repoPoolAddCmd.MarkFlagRequired("flavor") //nolint
|
||||
repoPoolAddCmd.MarkFlagRequired("tags") //nolint
|
||||
|
||||
repoPoolUpdateCmd.Flags().StringVar(&poolImage, "image", "", "The provider-specific image name to use for runners in this pool.")
|
||||
repoPoolUpdateCmd.Flags().StringVar(&poolFlavor, "flavor", "", "The flavor to use for this runner.")
|
||||
|
|
|
|||
|
|
@ -142,9 +142,9 @@ func init() {
|
|||
repoAddCmd.Flags().StringVar(&repoName, "name", "", "The name of the repository")
|
||||
repoAddCmd.Flags().StringVar(&repoWebhookSecret, "webhook-secret", "", "The webhook secret for this repository")
|
||||
repoAddCmd.Flags().StringVar(&repoCreds, "credentials", "", "Credentials name. See credentials list.")
|
||||
repoAddCmd.MarkFlagRequired("credentials")
|
||||
repoAddCmd.MarkFlagRequired("owner")
|
||||
repoAddCmd.MarkFlagRequired("name")
|
||||
repoAddCmd.MarkFlagRequired("credentials") //nolint
|
||||
repoAddCmd.MarkFlagRequired("owner") //nolint
|
||||
repoAddCmd.MarkFlagRequired("name") //nolint
|
||||
|
||||
repositoryCmd.AddCommand(
|
||||
repoListCmd,
|
||||
|
|
|
|||
|
|
@ -98,11 +98,11 @@ Example:
|
|||
} else if cmd.Flags().Changed("all") {
|
||||
instances, err = cli.ListAllInstances()
|
||||
} else {
|
||||
cmd.Help()
|
||||
cmd.Help() //nolint
|
||||
os.Exit(0)
|
||||
}
|
||||
default:
|
||||
cmd.Help()
|
||||
cmd.Help() //nolint
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ func (c *Config) SaveConfig() error {
|
|||
}
|
||||
cfgHandle, err := os.Create(cfgFile)
|
||||
if err != nil {
|
||||
errors.Wrap(err, "getting file handle")
|
||||
return errors.Wrap(err, "getting file handle")
|
||||
}
|
||||
|
||||
encoder := toml.NewEncoder(cfgHandle)
|
||||
|
|
|
|||
|
|
@ -86,8 +86,10 @@ func main() {
|
|||
var hub *websocket.Hub
|
||||
if cfg.Default.EnableLogStreamer {
|
||||
hub = websocket.NewHub(ctx)
|
||||
hub.Start()
|
||||
defer hub.Stop()
|
||||
if err := hub.Start(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer hub.Stop() //nolint
|
||||
writers = append(writers, hub)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,9 @@ func (r *Runner) CreateEnterprise(ctx context.Context, param params.CreateEnterp
|
|||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
r.store.DeleteEnterprise(ctx, enterprise.ID)
|
||||
if deleteErr := r.store.DeleteEnterprise(ctx, enterprise.ID); deleteErr != nil {
|
||||
log.Printf("failed to delete enterprise: %s", deleteErr)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,9 @@ func (r *Runner) CreateOrganization(ctx context.Context, param params.CreateOrgP
|
|||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
r.store.DeleteOrganization(ctx, org.ID)
|
||||
if deleteErr := r.store.DeleteOrganization(ctx, org.ID); deleteErr != nil {
|
||||
log.Printf("failed to delete org: %s", deleteErr)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
|||
|
|
@ -1009,7 +1009,7 @@ func (r *basePoolManager) deletePendingInstances() {
|
|||
return errors.Wrap(err, "deleting instance from database")
|
||||
}
|
||||
return
|
||||
}(instance)
|
||||
}(instance) //nolint
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
|
|
@ -128,28 +127,28 @@ func getClientFromConfig(ctx context.Context, cfg *config.LXD) (cli lxd.Instance
|
|||
var srvCrtContents, tlsCAContents, clientCertContents, clientKeyContents []byte
|
||||
|
||||
if cfg.TLSServerCert != "" {
|
||||
srvCrtContents, err = ioutil.ReadFile(cfg.TLSServerCert)
|
||||
srvCrtContents, err = os.ReadFile(cfg.TLSServerCert)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "reading TLSServerCert")
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.TLSCA != "" {
|
||||
tlsCAContents, err = ioutil.ReadFile(cfg.TLSCA)
|
||||
tlsCAContents, err = os.ReadFile(cfg.TLSCA)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "reading TLSCA")
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.ClientCertificate != "" {
|
||||
clientCertContents, err = ioutil.ReadFile(cfg.ClientCertificate)
|
||||
clientCertContents, err = os.ReadFile(cfg.ClientCertificate)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "reading ClientCertificate")
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.ClientKey != "" {
|
||||
clientKeyContents, err = ioutil.ReadFile(cfg.ClientKey)
|
||||
clientKeyContents, err = os.ReadFile(cfg.ClientKey)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "reading ClientKey")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,9 @@ func (r *Runner) CreateRepository(ctx context.Context, param params.CreateRepoPa
|
|||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
r.store.DeleteRepository(ctx, repo.ID)
|
||||
if deleteErr := r.store.DeleteRepository(ctx, repo.ID); deleteErr != nil {
|
||||
log.Printf("failed to delete repository: %s", deleteErr)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
|||
|
|
@ -8,9 +8,5 @@ import (
|
|||
)
|
||||
|
||||
func IsExecutable(path string) bool {
|
||||
if unix.Access(path, unix.X_OK) == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
return unix.Access(path, unix.X_OK) == nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,8 +55,15 @@ func (c *Client) clientReader() {
|
|||
c.conn.Close()
|
||||
}()
|
||||
c.conn.SetReadLimit(maxMessageSize)
|
||||
c.conn.SetReadDeadline(time.Now().Add(pongWait))
|
||||
c.conn.SetPongHandler(func(string) error { c.conn.SetReadDeadline(time.Now().Add(pongWait)); return nil })
|
||||
if err := c.conn.SetReadDeadline(time.Now().Add(pongWait)); err != nil {
|
||||
log.Printf("failed to set read deadline: %s", err)
|
||||
}
|
||||
c.conn.SetPongHandler(func(string) error {
|
||||
if err := c.conn.SetReadDeadline(time.Now().Add(pongWait)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
for {
|
||||
mt, _, err := c.conn.ReadMessage()
|
||||
if err != nil {
|
||||
|
|
@ -78,10 +85,14 @@ func (c *Client) clientWriter() {
|
|||
for {
|
||||
select {
|
||||
case message, ok := <-c.send:
|
||||
c.conn.SetWriteDeadline(time.Now().Add(writeWait))
|
||||
if err := c.conn.SetWriteDeadline(time.Now().Add(writeWait)); err != nil {
|
||||
log.Printf("failed to set write deadline: %s", err)
|
||||
}
|
||||
if !ok {
|
||||
// The hub closed the channel.
|
||||
c.conn.WriteMessage(websocket.CloseMessage, []byte{})
|
||||
if err := c.conn.WriteMessage(websocket.CloseMessage, []byte{}); err != nil {
|
||||
log.Printf("failed to write message: %s", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -90,7 +101,9 @@ func (c *Client) clientWriter() {
|
|||
return
|
||||
}
|
||||
case <-ticker.C:
|
||||
c.conn.SetWriteDeadline(time.Now().Add(writeWait))
|
||||
if err := c.conn.SetWriteDeadline(time.Now().Add(writeWait)); err != nil {
|
||||
log.Printf("failed to set write deadline: %s", err)
|
||||
}
|
||||
if err := c.conn.WriteMessage(websocket.PingMessage, nil); err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue