Skip to content

Commit e02f6bc

Browse files
authored
Merge pull request #315 from dabio/client-cert-key
Provide a way to specify client cert and key
2 parents 57fb170 + a2fcc6d commit e02f6bc

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

gitlab/config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ type Config struct {
1616
BaseURL string
1717
Insecure bool
1818
CACertFile string
19+
ClientCert string
20+
ClientKey string
1921
}
2022

2123
// Client returns a *gitlab.Client to interact with the configured gitlab instance
@@ -40,6 +42,15 @@ func (c *Config) Client() (interface{}, error) {
4042
tlsConfig.InsecureSkipVerify = true
4143
}
4244

45+
// add client cert and key to connection
46+
if c.ClientCert != "" && c.ClientKey != "" {
47+
clientPair, err := tls.LoadX509KeyPair(c.ClientCert, c.ClientKey)
48+
if err != nil {
49+
return nil, err
50+
}
51+
tlsConfig.Certificates = []tls.Certificate{clientPair}
52+
}
53+
4354
t := http.DefaultTransport.(*http.Transport).Clone()
4455
t.TLSClientConfig = tlsConfig
4556
t.MaxIdleConnsPerHost = 100

gitlab/provider.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ func Provider() terraform.ResourceProvider {
3939
Default: false,
4040
Description: descriptions["insecure"],
4141
},
42+
"client_cert": {
43+
Type: schema.TypeString,
44+
Optional: true,
45+
Default: "",
46+
Description: descriptions["client_cert"],
47+
},
48+
"client_key": {
49+
Type: schema.TypeString,
50+
Optional: true,
51+
Default: "",
52+
Description: descriptions["client_key"],
53+
},
4254
},
4355

4456
DataSourcesMap: map[string]*schema.Resource{
@@ -89,6 +101,10 @@ func init() {
89101
"cacert_file": "A file containing the ca certificate to use in case ssl certificate is not from a standard chain",
90102

91103
"insecure": "Disable SSL verification of API calls",
104+
105+
"client_cert": "File path to client certificate when GitLab instance is behind company proxy. File must contain PEM encoded data.",
106+
107+
"client_key": "File path to client key when GitLab instance is behind company proxy. File must contain PEM encoded data.",
92108
}
93109
}
94110

@@ -98,6 +114,8 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
98114
BaseURL: d.Get("base_url").(string),
99115
CACertFile: d.Get("cacert_file").(string),
100116
Insecure: d.Get("insecure").(bool),
117+
ClientCert: d.Get("client_cert").(string),
118+
ClientKey: d.Get("client_key").(string),
101119
}
102120

103121
return config.Client()

website/docs/index.html.markdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,7 @@ The following arguments are supported in the `provider` block:
7878

7979
* `insecure` - (Optional; boolean, defaults to false) When set to true this disables SSL verification of the connection to the
8080
GitLab instance.
81+
82+
* `client_cert` - (Optional) File path to client certificate when GitLab instance is behind company proxy. File must contain PEM encoded data.
83+
84+
* `client_key` - (Optional) File path to client key when GitLab instance is behind company proxy. File must contain PEM encoded data. Required when `client_cert` is set.

0 commit comments

Comments
 (0)