-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.go
103 lines (84 loc) · 3.2 KB
/
configuration.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
Copyright 2022 Keyfactor
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
thespecific language governing permissions and limitations under the
License.
EJBCA REST Interface
API reference documentation.
API version: 1.0
*/
// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
package ejbca
import (
"fmt"
"net/http"
"os"
)
// contextKeys are used to identify the type of value in the context.
// Since these are string, it is possible to get a short description of the
// context key for logging and debugging using key.String().
type contextKey string
func (c contextKey) String() string {
return "auth " + string(c)
}
var (
// ContextAccessToken takes a string oauth2 access token as authentication for the request.
ContextAccessToken = contextKey("accesstoken")
)
// BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth
type BasicAuth struct {
UserName string `json:"userName,omitempty"`
Password string `json:"password,omitempty"`
}
// APIKey provides API key based authentication to a request passed via context using ContextAPIKey
type APIKey struct {
Key string
Prefix string
}
// Configuration stores the configuration of the API client
type Configuration struct {
Host string `json:"host,omitempty"`
DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
UserAgent string `json:"userAgent,omitempty"`
Debug bool `json:"debug,omitempty"`
ClientCertificatePath string `json:"clientCertificatePath,omitempty"`
ClientCertificateKeyPath string `json:"clientCertificateKeyPath,omitempty"`
HTTPClient *http.Client
}
// NewConfiguration returns a new Configuration object
func NewConfiguration() *Configuration {
cfg := &Configuration{
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
}
// Get hostname from environment variable
hostname := os.Getenv("EJBCA_HOSTNAME")
if hostname != "" {
if hostname, err := cleanHostname(hostname); err == nil {
cfg.Host = hostname
} else {
fmt.Errorf("EJBCA_HOSTNAME is not a valid URL: %s", err)
}
}
// Get client certificate path from environment variable
clientCertPath := os.Getenv("EJBCA_CLIENT_CERT_PATH")
if clientCertPath != "" {
cfg.ClientCertificatePath = clientCertPath
}
// Get client certificate key path from environment variable
clientCertKeyPath := os.Getenv("EJBCA_CLIENT_CERT_KEY_PATH")
if clientCertKeyPath != "" {
cfg.ClientCertificateKeyPath = clientCertKeyPath
}
return cfg
}
// AddDefaultHeader adds a new HTTP header to the default header in the request
func (c *Configuration) AddDefaultHeader(key string, value string) {
c.DefaultHeader[key] = value
}