Skip to content

Commit

Permalink
feat(repositories): Add conection options to repository manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
anmoel committed Dec 13, 2021
1 parent 28a7694 commit 316d4f1
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 58 deletions.
11 changes: 10 additions & 1 deletion docs/resources/repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,24 @@ The `http_client` object supports the following:
* `authentication` - (Optional) Authentication configuration of the HTTP client
* `auto_block` - (Optional) Whether to auto-block outbound connections if remote peer is detected as unreachable/unresponsive
* `blocked` - (Optional) Whether to block outbound connections on the repository
* `connection` - (Optional) Connection configuration of the HTTP client

The `authentication` object supports the following:

* `ntlm_domain` - (Optional) The ntlm domain to connect
* `ntlm_host` - (Optional) The ntlm host to connect
* `password` - (Optional) The password used by the proxy repository
* `type` - (Optional) Authentication type
* `type` - (Optional) Authentication type. Possible values: `ntlm`, `username` or `bearerToken`. Only npm supports bearerToken authentication
* `username` - (Optional) The username used by the proxy repository

The `connection` object supports the following:

* `enable_cookies` - (Optional) Whether to allow cookies to be stored and used
* `retries` - (Optional) Total retries if the initial connection attempt suffers a timeout
* `timeout` - (Optional) Seconds to wait for activity before stopping and retrying the connection
* `use_trust_store` - (Optional) Use certificates stored in the Nexus Repository Manager truststore to connect to external systems
* `user_agent_suffix` - (Optional) Custom fragment to append to User-Agent header in HTTP requests

The `maven` object supports the following:

* `layout_policy` - (Optional) Validate that all paths are maven artifact or metadata paths. Possible values: `PERMISSIVE` or `STRICT`
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/datadrivers/terraform-provider-nexus
go 1.17

require (
github.com/datadrivers/go-nexus-client v0.21.0
github.com/datadrivers/go-nexus-client v0.22.0
github.com/hashicorp/terraform-plugin-sdk v1.17.2
github.com/stretchr/testify v1.7.0
)
Expand All @@ -27,7 +27,7 @@ require (
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/golang/protobuf v1.4.2 // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/go-querystring v1.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
Expand All @@ -53,7 +53,7 @@ require (
github.com/imdario/mergo v0.3.12 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/jstemmer/go-junit-report v0.9.1 // indirect
github.com/klauspost/compress v1.11.2 // indirect
github.com/klauspost/compress v1.13.5 // indirect
github.com/mattn/go-colorable v0.1.1 // indirect
github.com/mattn/go-isatty v0.0.5 // indirect
github.com/mitchellh/cli v1.1.2 // indirect
Expand Down
18 changes: 10 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/datadrivers/go-nexus-client v0.21.0 h1:ftl47wVESxyzyx3xj8Dtr8o57fj/wPAQ8Gt0Ys24NzU=
github.com/datadrivers/go-nexus-client v0.21.0/go.mod h1:L0+iflpXkI2UbdFJ3VYGaZV359cr21YwOdcwkIqBsTU=
github.com/datadrivers/go-nexus-client v0.22.0 h1:gISvPKwhZezvZRrOFB/e8roWb0yinNoVVyhGD2gIpw4=
github.com/datadrivers/go-nexus-client v0.22.0/go.mod h1:yE2H94qBN5eiQZc+JUGQ7O5i9ZKSkRIF5yMkAIprUcw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -152,8 +152,8 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
Expand Down Expand Up @@ -250,8 +250,9 @@ github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 h1:DowS9hvgy
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/keybase/go-crypto v0.0.0-20161004153544-93f5b35093ba/go.mod h1:ghbZscTyKdM07+Fw3KSi0hcJm+AlEUWj8QLlPtijN/M=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.11.2 h1:MiK62aErc3gIiVEtyzKfeOHgW7atJb5g/KNX5m3c2nQ=
github.com/klauspost/compress v1.11.2/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.13.5 h1:9O69jUPDcsT9fEm74W92rZL9FQY7rCdaXVneq+yyzl4=
github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s=
github.com/klauspost/cpuid v1.3.1/go.mod h1:bYW4mA6ZgKPob1/Dlai2LviZJO7KGI3uoWLd42rAQw4=
Expand All @@ -276,8 +277,8 @@ github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/minio/md5-simd v1.1.0 h1:QPfiOqlZH+Cj9teu0t9b1nTBfPbyTl16Of5MeuShdK4=
github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw=
github.com/minio/minio-go/v7 v7.0.11 h1:7utSkCtMQPYYB1UB8FR3d0QSiOWE6F/JYXon29imYek=
github.com/minio/minio-go/v7 v7.0.11/go.mod h1:WoyW+ySKAKjY98B9+7ZbI8z8S3jaxaisdcvj9TGlazA=
github.com/minio/minio-go/v7 v7.0.18 h1:fncn6iacnK+i2uYfNc5aVPG7bEqQH0nU4yAGMSunY0w=
github.com/minio/minio-go/v7 v7.0.18/go.mod h1:SyQ1IFeJuaa+eV5yEDxW7hYE1s5VVq5sgImDe27R+zg=
github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU=
github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
github.com/mitchellh/cli v1.1.2 h1:PvH+lL2B7IQ101xQL63Of8yFS2y+aDlsFcsqNc+u/Kw=
Expand Down Expand Up @@ -379,8 +380,8 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand Down Expand Up @@ -502,6 +503,7 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210324051608-47abb6519492 h1:Paq34FxTluEPvVyayQqMPgHm+vTOrIifmcYxFBx9TLg=
golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
104 changes: 58 additions & 46 deletions nexus/resource_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,38 +315,44 @@ func resourceRepository() *schema.Resource {
Optional: true,
Type: schema.TypeBool,
},
// "connection": {
// Elem: &schema.Resource{
// Schema: map[string]*schema.Schema{
// "enable_cookies": {
// Default: false,
// Description: "Whether to allow cookies to be stored and used",
// Optional: true,
// Type: schema.TypeBool,
// },
// "retries": {
// Description: "Total retries if the initial connection attempt suffers a timeout",
// Optional: true,
// Type: schema.TypeInt,
// ValidateFunc: validation.IntBetween(0, 10),
// },
// "timeout": {
// Description: "Seconds to wait for activity before stopping and retrying the connection",
// Optional: true,
// Type: schema.TypeInt,
// ValidateFunc: validation.IntBetween(1, 3600),
// },
// "user_agent_suffix": {
// Description: "Custom fragment to append to User-Agent header in HTTP requests",
// Optional: true,
// Type: schema.TypeString,
// },
// },
// },
// MaxItems: 1,
// Optional: true,
// Type: schema.TypeList,
// },
"connection": {
Description: "Connection configuration of the HTTP client",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enable_cookies": {
Description: "Whether to allow cookies to be stored and used",
Optional: true,
Type: schema.TypeBool,
},
"retries": {
Description: "Total retries if the initial connection attempt suffers a timeout",
Optional: true,
Type: schema.TypeInt,
ValidateFunc: validation.IntBetween(0, 10),
},
"timeout": {
Description: "Seconds to wait for activity before stopping and retrying the connection",
Optional: true,
Type: schema.TypeInt,
ValidateFunc: validation.IntBetween(1, 3600),
},
"user_agent_suffix": {
Description: "Custom fragment to append to User-Agent header in HTTP requests",
Optional: true,
Type: schema.TypeString,
},
"use_trust_store": {
Description: "Use certificates stored in the Nexus Repository Manager truststore to connect to external systems",
Optional: true,
Default: false,
Type: schema.TypeBool,
},
},
},
MaxItems: 1,
Optional: true,
Type: schema.TypeList,
},
},
},
MaxItems: 1,
Expand Down Expand Up @@ -641,19 +647,20 @@ func getRepositoryFromResourceData(d *schema.ResourceData) nexus.Repository {
}
}

// if v, ok := httpClientConfig["connection"]; ok {
// connList := v.([]interface{})
// if len(connList) == 1 && connList[0] != nil {
// connConfig := connList[0].(map[string]interface{})

// repo.RepositoryHTTPClient.Connection = &nexus.RepositoryHTTPClientConnection{
// EnableCookies: connConfig["enable_cookis"].(bool),
// Retries: connConfig["retries"].(*int),
// Timeout: connConfig["timeout"].(*int),
// UserAgentSuffix: connConfig["user_agent_suffix"].(*string),
// }
// }
// }
if v, ok := httpClientConfig["connection"]; ok {
connList := v.([]interface{})
if len(connList) == 1 && connList[0] != nil {
connConfig := connList[0].(map[string]interface{})

repo.RepositoryHTTPClient.Connection = &nexus.RepositoryHTTPClientConnection{
EnableCookies: connConfig["enable_cookies"].(*bool),
Retries: connConfig["retries"].(*int),
Timeout: connConfig["timeout"].(*int),
UserAgentSuffix: connConfig["user_agent_suffix"].(string),
UseTrustStore: connConfig["use_trust_store"].(*bool),
}
}
}
}

if _, ok := d.GetOk("maven"); ok {
Expand Down Expand Up @@ -932,15 +939,20 @@ func flattenRepositoryHTTPClientConnection(conn *nexus.RepositoryHTTPClientConne
return nil
}
data := map[string]interface{}{
"enable_cookies": conn.EnableCookies,
"user_agent_suffix": conn.UserAgentSuffix,
}
if conn.EnableCookies != nil {
data["enable_cookies"] = *conn.EnableCookies
}
if conn.Retries != nil {
data["retries"] = *conn.Retries
}
if conn.Timeout != nil {
data["timeout"] = *conn.Timeout
}
if conn.UseTrustStore != nil {
data["use_trust_store"] = *conn.UseTrustStore
}
return []map[string]interface{}{data}
}

Expand Down
4 changes: 4 additions & 0 deletions nexus/resource_repository_apt_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ func testAccResourceRepositoryAptProxy() nexus.Repository {
Distribution: "bionic",
Flat: true,
}
useTrustStore := true
repo.RepositoryProxy.RemoteURL = "https://remote.repository.com"
repo.RepositoryHTTPClient.Connection = &nexus.RepositoryHTTPClientConnection{
UseTrustStore: &useTrustStore,
}
return repo
}

Expand Down

0 comments on commit 316d4f1

Please sign in to comment.