1
0
Fork 0

Adding upstream version 3.10.8.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-05-18 09:37:23 +02:00
parent 37e9b6d587
commit 03bfe4079e
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
356 changed files with 28857 additions and 0 deletions

View file

@ -0,0 +1,81 @@
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT
package auth
import (
"net/url"
)
type ForgeAuthInterface interface {
SetURL(url string)
GetURL() string
GetPushURL() string
SetUsername(username string)
GetUsername() string
SetPassword(password string)
GetPassword() string
SetToken(token string)
GetToken() string
}
type ForgeAuth struct {
url string
username string
password string
token string
}
func NewForgeAuth() ForgeAuth {
return ForgeAuth{}
}
func (o *ForgeAuth) GetPushURL() string {
u, err := url.Parse(o.url)
if err != nil {
panic(err)
}
if o.GetToken() != "" {
u.User = url.UserPassword("token", o.GetToken())
} else {
u.User = url.UserPassword(o.GetUsername(), o.GetPassword())
}
return u.String()
}
func (o *ForgeAuth) SetURL(url string) {
o.url = url
}
func (o *ForgeAuth) GetURL() string {
return o.url
}
func (o *ForgeAuth) SetUsername(username string) {
o.username = username
}
func (o *ForgeAuth) GetUsername() string {
return o.username
}
func (o *ForgeAuth) SetPassword(password string) {
o.password = password
}
func (o *ForgeAuth) GetPassword() string {
return o.password
}
func (o *ForgeAuth) SetToken(token string) {
o.token = token
}
func (o *ForgeAuth) GetToken() string {
return o.token
}

View file

@ -0,0 +1,61 @@
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT
package auth
import (
"context"
"github.com/urfave/cli/v3"
)
func ForgeUserOption(prefix string) string {
return prefix + "-user"
}
func ForgePasswordOption(prefix string) string {
return prefix + "-password"
}
func ForgeTokenOption(prefix string) string {
return prefix + "-token"
}
func ForgeURLOption(prefix string) string {
return prefix + "-url"
}
func (o *ForgeAuth) FromFlags(ctx context.Context, c *cli.Command, prefix string) {
o.SetUsername(c.String(ForgeUserOption(prefix)))
o.SetPassword(c.String(ForgePasswordOption(prefix)))
o.SetToken(c.String(ForgeTokenOption(prefix)))
o.SetURL(c.String(ForgeURLOption(prefix)))
}
func (o *ForgeAuth) GetFlags(prefix, category string) []cli.Flag {
flags := make([]cli.Flag, 0, 10)
flags = append(flags, &cli.StringFlag{
Name: ForgeUserOption(prefix),
Usage: "`USER` to access the forge API",
Category: prefix,
})
flags = append(flags, &cli.StringFlag{
Name: ForgePasswordOption(prefix),
Usage: "`PASSWORD` of the user",
Category: prefix,
})
flags = append(flags, &cli.StringFlag{
Name: ForgeTokenOption(prefix),
Usage: "`TOKEN` of the user",
Category: prefix,
})
flags = append(flags, &cli.StringFlag{
Name: ForgeURLOption(prefix),
Usage: "`URL` of the forge",
Category: prefix,
})
return flags
}