garm/cmd/garm-cli/cmd/credentials.go
Gabriel Adrian Samfira 05057e37fd
Start pool managers in the background
Garm no longer fails on startup if a pool manager cannot be started. It
will attempt to start the pool manager in the background. If it fails
due to an unauthorized error, it will sleep for 3 hours. It is unlikely
it will work a second time if credentials are not updated in the config
and garm is restarted, so no point in getting rate limited.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
2022-10-21 17:14:03 +03:00

73 lines
2.2 KiB
Go

// 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.
package cmd
import (
"fmt"
"garm/params"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/spf13/cobra"
)
// credentialsCmd represents the credentials command
var credentialsCmd = &cobra.Command{
Use: "credentials",
Aliases: []string{"creds"},
Short: "List configured credentials",
Long: `List all available credentials configured in the service
config file.
Currently, github personal tokens are configured statically in the config file
of the garm service. This command lists the names of those credentials,
which in turn can be used to define pools of runners withing repositories.`,
Run: nil,
}
func init() {
credentialsCmd.AddCommand(
&cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Short: "List configured github credentials",
Long: `List the names of the github personal access tokens availabe to the garm.`,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
if needsInit {
return errNeedsInitError
}
creds, err := cli.ListCredentials()
if err != nil {
return err
}
formatGithubCredentials(creds)
return nil
},
})
rootCmd.AddCommand(credentialsCmd)
}
func formatGithubCredentials(creds []params.GithubCredentials) {
t := table.NewWriter()
header := table.Row{"Name", "Description", "Base URL", "API URL", "Upload URL"}
t.AppendHeader(header)
for _, val := range creds {
t.AppendRow(table.Row{val.Name, val.Description, val.BaseURL, val.APIBaseURL, val.UploadBaseURL})
t.AppendSeparator()
}
fmt.Println(t.Render())
}