podman

Форк
0
77 строк · 2.5 Кб
1
// Copyright 2015 go-swagger maintainers
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//    http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15
package client
16

17
import (
18
	"encoding/base64"
19

20
	"github.com/go-openapi/strfmt"
21

22
	"github.com/go-openapi/runtime"
23
)
24

25
// PassThroughAuth never manipulates the request
26
var PassThroughAuth runtime.ClientAuthInfoWriter
27

28
func init() {
29
	PassThroughAuth = runtime.ClientAuthInfoWriterFunc(func(_ runtime.ClientRequest, _ strfmt.Registry) error { return nil })
30
}
31

32
// BasicAuth provides a basic auth info writer
33
func BasicAuth(username, password string) runtime.ClientAuthInfoWriter {
34
	return runtime.ClientAuthInfoWriterFunc(func(r runtime.ClientRequest, _ strfmt.Registry) error {
35
		encoded := base64.StdEncoding.EncodeToString([]byte(username + ":" + password))
36
		return r.SetHeaderParam(runtime.HeaderAuthorization, "Basic "+encoded)
37
	})
38
}
39

40
// APIKeyAuth provides an API key auth info writer
41
func APIKeyAuth(name, in, value string) runtime.ClientAuthInfoWriter {
42
	if in == "query" {
43
		return runtime.ClientAuthInfoWriterFunc(func(r runtime.ClientRequest, _ strfmt.Registry) error {
44
			return r.SetQueryParam(name, value)
45
		})
46
	}
47

48
	if in == "header" {
49
		return runtime.ClientAuthInfoWriterFunc(func(r runtime.ClientRequest, _ strfmt.Registry) error {
50
			return r.SetHeaderParam(name, value)
51
		})
52
	}
53
	return nil
54
}
55

56
// BearerToken provides a header based oauth2 bearer access token auth info writer
57
func BearerToken(token string) runtime.ClientAuthInfoWriter {
58
	return runtime.ClientAuthInfoWriterFunc(func(r runtime.ClientRequest, _ strfmt.Registry) error {
59
		return r.SetHeaderParam(runtime.HeaderAuthorization, "Bearer "+token)
60
	})
61
}
62

63
// Compose combines multiple ClientAuthInfoWriters into a single one.
64
// Useful when multiple auth headers are needed.
65
func Compose(auths ...runtime.ClientAuthInfoWriter) runtime.ClientAuthInfoWriter {
66
	return runtime.ClientAuthInfoWriterFunc(func(r runtime.ClientRequest, _ strfmt.Registry) error {
67
		for _, auth := range auths {
68
			if auth == nil {
69
				continue
70
			}
71
			if err := auth.AuthenticateRequest(r, nil); err != nil {
72
				return err
73
			}
74
		}
75
		return nil
76
	})
77
}
78

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.