Adding upstream version 3.10.8.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
37e9b6d587
commit
03bfe4079e
356 changed files with 28857 additions and 0 deletions
16
options/auth/interface.go
Normal file
16
options/auth/interface.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright Earl Warren <contact@earl-warren.org>
|
||||
// Copyright Loïc Dachary <loic@dachary.org>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package auth
|
||||
|
||||
type Interface interface {
|
||||
SetUsername(username string)
|
||||
GetUsername() string
|
||||
|
||||
SetPassword(password string)
|
||||
GetPassword() string
|
||||
|
||||
SetToken(token string)
|
||||
GetToken() string
|
||||
}
|
16
options/cli/interface.go
Normal file
16
options/cli/interface.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright Earl Warren <contact@earl-warren.org>
|
||||
// Copyright Loïc Dachary <loic@dachary.org>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
type Interface interface {
|
||||
GetFlags(prefix, category string) []cli.Flag
|
||||
FromFlags(ctx context.Context, c *cli.Command, prefix string)
|
||||
}
|
20
options/cli/options.go
Normal file
20
options/cli/options.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Copyright Earl Warren <contact@earl-warren.org>
|
||||
// Copyright Loïc Dachary <loic@dachary.org>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
type OptionsCLI struct{}
|
||||
|
||||
func (o *OptionsCLI) FromFlags(ctx context.Context, c *cli.Command, prefix string) {
|
||||
}
|
||||
|
||||
func (o *OptionsCLI) GetFlags(prefix, category string) []cli.Flag {
|
||||
return []cli.Flag{}
|
||||
}
|
35
options/factory.go
Normal file
35
options/factory.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Copyright Earl Warren <contact@earl-warren.org>
|
||||
// Copyright Loïc Dachary <loic@dachary.org>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package options
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type (
|
||||
Factory func() Interface
|
||||
Factories map[string]Factory
|
||||
)
|
||||
|
||||
var factories = make(Factories, 10)
|
||||
|
||||
func GetFactories() Factories {
|
||||
return factories
|
||||
}
|
||||
|
||||
func RegisterFactory(name string, factory Factory) {
|
||||
name = strings.ToLower(name)
|
||||
factories[name] = factory
|
||||
}
|
||||
|
||||
func GetFactory(name string) Factory {
|
||||
name = strings.ToLower(name)
|
||||
factory, ok := factories[name]
|
||||
if !ok {
|
||||
panic(fmt.Errorf("no options factory registered for %s", name))
|
||||
}
|
||||
return factory
|
||||
}
|
71
options/http/implementation.go
Normal file
71
options/http/implementation.go
Normal file
|
@ -0,0 +1,71 @@
|
|||
// Copyright Earl Warren <contact@earl-warren.org>
|
||||
// Copyright Loïc Dachary <loic@dachary.org>
|
||||
// Copyright twenty-panda <twenty-panda@posteo.com>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package http
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type Implementation struct {
|
||||
newMigrationHTTPClient NewMigrationHTTPClientFun
|
||||
skipTLSVerify *bool
|
||||
proxy *string
|
||||
}
|
||||
|
||||
func (o *Implementation) GetNewMigrationHTTPClient() NewMigrationHTTPClientFun {
|
||||
if o.newMigrationHTTPClient == nil {
|
||||
return func() *http.Client {
|
||||
transport := &http.Transport{}
|
||||
if o.GetSkipTLSVerify() {
|
||||
transport.TLSClientConfig = &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
}
|
||||
if o.GetProxy() != "" {
|
||||
proxyURL, err := url.Parse(o.GetProxy())
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("url.Parse %w", err))
|
||||
}
|
||||
transport.Proxy = func(req *http.Request) (*url.URL, error) {
|
||||
return http.ProxyURL(proxyURL)(req)
|
||||
}
|
||||
}
|
||||
return &http.Client{
|
||||
Transport: transport,
|
||||
}
|
||||
}
|
||||
}
|
||||
return o.newMigrationHTTPClient
|
||||
}
|
||||
|
||||
func (o *Implementation) SetNewMigrationHTTPClient(fun NewMigrationHTTPClientFun) {
|
||||
o.newMigrationHTTPClient = fun
|
||||
}
|
||||
|
||||
func (o *Implementation) GetSkipTLSVerify() bool {
|
||||
if o.skipTLSVerify == nil {
|
||||
return false
|
||||
}
|
||||
return *o.skipTLSVerify
|
||||
}
|
||||
|
||||
func (o *Implementation) SetSkipTLSVerify(skipTLSVerify bool) {
|
||||
o.skipTLSVerify = &skipTLSVerify
|
||||
}
|
||||
|
||||
func (o *Implementation) GetProxy() string {
|
||||
if o.proxy == nil {
|
||||
return ""
|
||||
}
|
||||
return *o.proxy
|
||||
}
|
||||
|
||||
func (o *Implementation) SetProxy(proxy string) {
|
||||
o.proxy = &proxy
|
||||
}
|
41
options/http/implementation_test.go
Normal file
41
options/http/implementation_test.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
// Copyright Earl Warren <contact@earl-warren.org>
|
||||
// Copyright Loïc Dachary <loic@dachary.org>
|
||||
// Copyright twenty-panda <twenty-panda@posteo.com>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package http
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestImplementation(t *testing.T) {
|
||||
i := Implementation{}
|
||||
|
||||
{
|
||||
newClient := i.GetNewMigrationHTTPClient()
|
||||
assert.NotNil(t, newClient)
|
||||
client := newClient()
|
||||
assert.Nil(t, client.Transport.(*http.Transport).TLSClientConfig)
|
||||
assert.Nil(t, client.Transport.(*http.Transport).Proxy)
|
||||
}
|
||||
|
||||
{
|
||||
i.SetSkipTLSVerify(true)
|
||||
proxy := "https://example.com"
|
||||
i.SetProxy(proxy)
|
||||
|
||||
newClient := i.GetNewMigrationHTTPClient()
|
||||
assert.NotNil(t, newClient)
|
||||
client := newClient()
|
||||
assert.NotNil(t, client.Transport.(*http.Transport).TLSClientConfig)
|
||||
assert.True(t, client.Transport.(*http.Transport).TLSClientConfig.InsecureSkipVerify)
|
||||
assert.NotNil(t, client.Transport.(*http.Transport).Proxy)
|
||||
proxyURL, err := client.Transport.(*http.Transport).Proxy(nil)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, proxy, proxyURL.String())
|
||||
}
|
||||
}
|
20
options/http/interface.go
Normal file
20
options/http/interface.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
// Copyright Earl Warren <contact@earl-warren.org>
|
||||
// Copyright Loïc Dachary <loic@dachary.org>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package http
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type NewMigrationHTTPClientFun func() *http.Client
|
||||
|
||||
type Interface interface {
|
||||
GetNewMigrationHTTPClient() NewMigrationHTTPClientFun
|
||||
SetNewMigrationHTTPClient(fun NewMigrationHTTPClientFun)
|
||||
GetSkipTLSVerify() bool
|
||||
SetSkipTLSVerify(skipTLSVerify bool)
|
||||
GetProxy() string
|
||||
SetProxy(proxy string)
|
||||
}
|
26
options/interface.go
Normal file
26
options/interface.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
// Copyright Earl Warren <contact@earl-warren.org>
|
||||
// Copyright Loïc Dachary <loic@dachary.org>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package options
|
||||
|
||||
import (
|
||||
"code.forgejo.org/f3/gof3/v3/options/auth"
|
||||
"code.forgejo.org/f3/gof3/v3/options/cli"
|
||||
"code.forgejo.org/f3/gof3/v3/options/http"
|
||||
"code.forgejo.org/f3/gof3/v3/options/logger"
|
||||
"code.forgejo.org/f3/gof3/v3/options/url"
|
||||
)
|
||||
|
||||
type (
|
||||
CLIInterface cli.Interface
|
||||
LoggerInterface logger.Interface
|
||||
URLInterface url.Interface
|
||||
AuthInterface auth.Interface
|
||||
HTTPInterface http.Interface
|
||||
)
|
||||
|
||||
type Interface interface {
|
||||
GetName() string
|
||||
SetName(string)
|
||||
}
|
14
options/logger/interface.go
Normal file
14
options/logger/interface.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
// Copyright Earl Warren <contact@earl-warren.org>
|
||||
// Copyright Loïc Dachary <loic@dachary.org>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package logger
|
||||
|
||||
import (
|
||||
"code.forgejo.org/f3/gof3/v3/logger"
|
||||
)
|
||||
|
||||
type Interface interface {
|
||||
SetLogger(logger.Interface)
|
||||
GetLogger() logger.Interface
|
||||
}
|
16
options/logger/options.go
Normal file
16
options/logger/options.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
// Copyright Earl Warren <contact@earl-warren.org>
|
||||
// Copyright Loïc Dachary <loic@dachary.org>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package logger
|
||||
|
||||
import (
|
||||
"code.forgejo.org/f3/gof3/v3/logger"
|
||||
)
|
||||
|
||||
type OptionsLogger struct {
|
||||
logger logger.Interface
|
||||
}
|
||||
|
||||
func (o *OptionsLogger) GetLogger() logger.Interface { return o.logger }
|
||||
func (o *OptionsLogger) SetLogger(logger logger.Interface) { o.logger = logger }
|
12
options/options.go
Normal file
12
options/options.go
Normal file
|
@ -0,0 +1,12 @@
|
|||
// Copyright Earl Warren <contact@earl-warren.org>
|
||||
// Copyright Loïc Dachary <loic@dachary.org>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package options
|
||||
|
||||
type Options struct {
|
||||
name string
|
||||
}
|
||||
|
||||
func (o *Options) GetName() string { return o.name }
|
||||
func (o *Options) SetName(name string) { o.name = name }
|
10
options/url/interface.go
Normal file
10
options/url/interface.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
// Copyright Earl Warren <contact@earl-warren.org>
|
||||
// Copyright Loïc Dachary <loic@dachary.org>
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package url
|
||||
|
||||
type Interface interface {
|
||||
SetURL(url string)
|
||||
GetURL() string
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue