add config values for token retrieval
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s

This commit is contained in:
2026-10-11 23:04:39 +02:00
parent 58b26304ae
commit f5e9cbc423
3 changed files with 41 additions and 4 deletions
+6 -4
View File
@@ -118,16 +118,18 @@ func GetToken(client *resty.Client, server config.Server) (token string) {
_, err := client.R().
SetBody(Login{
Email: "thomas.peetz@thpeetz.de",
Password: "admin",
Email: server.Username,
Password: server.Password,
}).
SetHeader("Accept", "application/json").
SetResult(&login).
Post("http://127.0.0.1:8550/api/login")
Post(fmt.Sprintf("%s/api/login", server.Url))
if err != nil {
slog.Info("Health", "error", err.Error())
}
slog.Info("health", "token", login.Token)
if config.Verbose > 2 {
slog.Info("login", "token", login.Token)
}
return login.Token
}
+1
View File
@@ -36,6 +36,7 @@ func init() {
rootCmd.PersistentFlags().CountVarP(&config.Verbose, "verbose", "v", "increase verbosity (-v, -vv, -vvv)")
viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config"))
exportCmd.Flags().StringVarP(&config.ServerName, "servername", "s", "local", "Define server to get Kontor items")
updateTitleCmd.Flags().StringVarP(&config.ServerName, "servername", "s", "local", "Define server to get Kontor items")
viper.BindPFlag("server", exportCmd.PersistentFlags().Lookup("server"))
cobra.OnInitialize(config.InitCliConfig)
}
+34
View File
@@ -0,0 +1,34 @@
package cmd
import (
"kontor-api-gin/internal/api"
"kontor-api-gin/internal/config"
"log/slog"
"github.com/spf13/cobra"
"resty.dev/v3"
)
var updateTitleCmd = &cobra.Command{
Use: "update-title",
Short: "Update titles",
Long: "Update titles",
Run: func(cmd *cobra.Command, args []string) {
slog.Info("Update titles using server", "server", config.ServerName)
client := resty.New()
localServer := config.Config.Server[config.ServerName]
slog.Info("get token", "url", localServer.Url)
token := api.GetToken(client, localServer)
api.GetJSON(client, token, localServer, "media/lofis", &api.Medialofis)
for _, lofi := range api.Medialofis {
if lofi.Review {
slog.Info("get title for Url", "url", lofi.WebLink)
}
}
},
}
func init() {
rootCmd.AddCommand(updateTitleCmd)
}