73 lines
2.1 KiB
Go
73 lines
2.1 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 needsInitError
|
|
}
|
|
|
|
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"}
|
|
t.AppendHeader(header)
|
|
for _, val := range creds {
|
|
t.AppendRow(table.Row{val.Name, val.Description})
|
|
t.AppendSeparator()
|
|
}
|
|
fmt.Println(t.Render())
|
|
}
|