Skip to content

Commit

Permalink
feat: support digest, ntlm & ntlmv2 (#932)
Browse files Browse the repository at this point in the history
* feat: support digest, ntlm & ntlmv2

[skip ci]

* chore: bump duty
  • Loading branch information
adityathebe authored Aug 2, 2024
1 parent 40adb55 commit f548e7a
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 27 deletions.
17 changes: 10 additions & 7 deletions connection/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ func (t TLSConfig) IsEmpty() bool {

// +kubebuilder:object:generate=true
type HTTPConnection struct {
ConnectionName string `json:"connection,omitempty" yaml:"connection,omitempty"`
types.Authentication `json:",inline"`
URL string `json:"url,omitempty" yaml:"url,omitempty"`
Bearer types.EnvVar `json:"bearer,omitempty" yaml:"bearer,omitempty"`
OAuth types.OAuth `json:"oauth,omitempty" yaml:"oauth,omitempty"`
TLS TLSConfig `json:"tls,omitempty" yaml:"tls,omitempty"`
ConnectionName string `json:"connection,omitempty" yaml:"connection,omitempty"`
types.HTTPBasicAuth `json:",inline"`
URL string `json:"url,omitempty" yaml:"url,omitempty"`
Bearer types.EnvVar `json:"bearer,omitempty" yaml:"bearer,omitempty"`
OAuth types.OAuth `json:"oauth,omitempty" yaml:"oauth,omitempty"`
TLS TLSConfig `json:"tls,omitempty" yaml:"tls,omitempty"`
}

func (h HTTPConnection) GetEndpoint() string {
Expand Down Expand Up @@ -114,8 +114,11 @@ func (h *HTTPConnection) Hydrate(ctx ConnectionContext, namespace string) (*HTTP
// CreateHTTPClient requires a hydrated connection
func CreateHTTPClient(ctx ConnectionContext, conn HTTPConnection) (*http.Client, error) {
client := http.NewClient()
if !conn.Authentication.IsEmpty() {
if !conn.HTTPBasicAuth.IsEmpty() {
client.Auth(conn.GetUsername(), conn.GetPassword())
client.Digest(conn.Digest)
client.NTLM(conn.NTLM)
client.NTLMV2(conn.NTLMV2)
} else if !conn.Bearer.IsEmpty() {
client.Header(echo.HeaderAuthorization, "Bearer "+conn.Bearer.ValueStatic)
} else if !conn.OAuth.IsEmpty() {
Expand Down
2 changes: 1 addition & 1 deletion connection/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ require (
github.com/eko/gocache/store/go_cache/v4 v4.2.2
github.com/exaring/otelpgx v0.5.2
github.com/fergusstrange/embedded-postgres v1.25.0
github.com/flanksource/commons v1.24.2
github.com/flanksource/gomplate/v3 v3.24.11
github.com/flanksource/commons v1.25.0
github.com/flanksource/gomplate/v3 v3.24.17
github.com/flanksource/kommons v0.31.4
github.com/flanksource/postq v0.1.3
github.com/google/cel-go v0.20.1
Expand Down Expand Up @@ -70,6 +70,7 @@ require (
github.com/AlekSi/pointer v1.1.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.1 // indirect
github.com/Snawoot/go-http-digest-auth-client v1.1.3 // indirect
github.com/TomOnTime/utfutil v0.0.0-20210710122150-437f72b26edf // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
Expand All @@ -86,7 +87,7 @@ require (
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/flanksource/is-healthy v1.0.18 // indirect
github.com/flanksource/is-healthy v1.0.21 // indirect
github.com/flanksource/kubectl-neat v1.0.4 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
Expand Down Expand Up @@ -217,4 +218,4 @@ require (
sigs.k8s.io/yaml v1.3.0 // indirect
)

// replace "github.com/flanksource/commons" => ../commons
// replace github.com/flanksource/commons => ../commons
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdko
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/RaveNoX/go-jsonmerge v1.0.0 h1:2e0nqnadoGUP8rAvcA0hkQelZreVO5X3BHomT2XMrAk=
github.com/RaveNoX/go-jsonmerge v1.0.0/go.mod h1:qYM/NA77LhO4h51JJM7Z+xBU3ovqrNIACZe+SkSNVFo=
github.com/Snawoot/go-http-digest-auth-client v1.1.3 h1:Xd/SNBuIUJqotzmxRpbXovBJxmlVZOT19IZZdMdrJ0Q=
github.com/Snawoot/go-http-digest-auth-client v1.1.3/go.mod h1:WiwNiPXTRGyjTGpBtSQJlM2wDPRRPpFGhMkMWpV4uqg=
github.com/TomOnTime/utfutil v0.0.0-20210710122150-437f72b26edf h1:+GdVyvpzTy3UFAS1+hbTqm9Mk0U1Xrocm28s/E2GWz0=
github.com/TomOnTime/utfutil v0.0.0-20210710122150-437f72b26edf/go.mod h1:FiuynIwe98RFhWI8nZ0dnsldPVsBy9rHH1hn2WYwme4=
github.com/WinterYukky/gorm-extra-clause-plugin v0.2.0 h1:s1jobT8PlSyG/FXczfoGSt4r46iPiT4ZShe35k5/2y4=
Expand Down Expand Up @@ -778,14 +780,14 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/fergusstrange/embedded-postgres v1.25.0 h1:sa+k2Ycrtz40eCRPOzI7Ry7TtkWXXJ+YRsxpKMDhxK0=
github.com/fergusstrange/embedded-postgres v1.25.0/go.mod h1:t/MLs0h9ukYM6FSt99R7InCHs1nW0ordoVCcnzmpTYw=
github.com/flanksource/commons v1.24.2 h1:9PZsmqRTignNu56W/ZoBbmNyeR2l12g7pUHe58t63vQ=
github.com/flanksource/commons v1.24.2/go.mod h1:gCg1cmwnLh3nqi9VmMH1MQ6dhFUGUS01wTduf4tHw6c=
github.com/flanksource/commons v1.25.0 h1:e1MLy+uABZAJ8KpNjarU/Hi5Gz/FlUqzhCtepaGr3j0=
github.com/flanksource/commons v1.25.0/go.mod h1:pBwcliLSsMn8ic5xRu6HC9PPBzZaBv8NbTJIwhbfeLE=
github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc=
github.com/flanksource/gomplate/v3 v3.24.11 h1:gGvWgoKwevbw6G52r37nGjXdNfM/Rx3hlRBPQ0mrAic=
github.com/flanksource/gomplate/v3 v3.24.11/go.mod h1:YTDFEQtaRPkE9KkUiON8kEjPinN1zuWx46r6jh4Pa7A=
github.com/flanksource/gomplate/v3 v3.24.17 h1:NPqVwiWnfRaV/ZywW91KOIBminOctPcTjbQWvDv7bUs=
github.com/flanksource/gomplate/v3 v3.24.17/go.mod h1:9clCoi3+mkkvr9V3J6Ue4YTNBTd4SVEPe9CfeRi7eD8=
github.com/flanksource/is-healthy v0.0.0-20230705092916-3b4cf510c5fc/go.mod h1:4pQhmF+TnVqJroQKY8wSnSp+T18oLson6YQ2M0qPHfQ=
github.com/flanksource/is-healthy v1.0.18 h1:ECOKpPZ6mPLDgQlnNm1XPB0QPxutESV760liBNVd5jo=
github.com/flanksource/is-healthy v1.0.18/go.mod h1:eRPXZShZqaz3Mz+QeoCNbL3857lt9BgCt67jOUQXLOU=
github.com/flanksource/is-healthy v1.0.21 h1:Icjjen+yOb/PWbyWNxdeJSLIZSCC9/WkrEBEfVFDhsM=
github.com/flanksource/is-healthy v1.0.21/go.mod h1:eRPXZShZqaz3Mz+QeoCNbL3857lt9BgCt67jOUQXLOU=
github.com/flanksource/kommons v0.31.4 h1:zksAgYjZuwPgS8XTejDIWEYB0nPSU1i3Jxcavm/vovI=
github.com/flanksource/kommons v0.31.4/go.mod h1:70BPMzjTvejsqRyVyAm/ZCeZ176toCvauaZjU03svnE=
github.com/flanksource/kubectl-neat v1.0.4 h1:t5/9CqgE84oEtB0KitgJ2+WIeLfD+RhXSxYrqb4X8yI=
Expand Down
6 changes: 3 additions & 3 deletions hack/migrate/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/flanksource/duty/hack/migrate
go 1.22.2

require (
github.com/flanksource/commons v1.24.2
github.com/flanksource/commons v1.25.0
github.com/flanksource/duty v1.0.180
github.com/spf13/cobra v1.8.0
)
Expand Down Expand Up @@ -38,8 +38,8 @@ require (
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/exaring/otelpgx v0.5.2 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/flanksource/gomplate/v3 v3.24.11 // indirect
github.com/flanksource/is-healthy v1.0.18 // indirect
github.com/flanksource/gomplate/v3 v3.24.17 // indirect
github.com/flanksource/is-healthy v1.0.21 // indirect
github.com/flanksource/kommons v0.31.4 // indirect
github.com/flanksource/kubectl-neat v1.0.4 // indirect
github.com/flanksource/postq v0.1.3 // indirect
Expand Down
12 changes: 6 additions & 6 deletions hack/migrate/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -772,14 +772,14 @@ github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5Kwzbycv
github.com/felixge/httpsnoop v1.0.1/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
github.com/flanksource/commons v1.24.2 h1:9PZsmqRTignNu56W/ZoBbmNyeR2l12g7pUHe58t63vQ=
github.com/flanksource/commons v1.24.2/go.mod h1:gCg1cmwnLh3nqi9VmMH1MQ6dhFUGUS01wTduf4tHw6c=
github.com/flanksource/commons v1.25.0 h1:e1MLy+uABZAJ8KpNjarU/Hi5Gz/FlUqzhCtepaGr3j0=
github.com/flanksource/commons v1.25.0/go.mod h1:pBwcliLSsMn8ic5xRu6HC9PPBzZaBv8NbTJIwhbfeLE=
github.com/flanksource/gomplate/v3 v3.20.4/go.mod h1:27BNWhzzSjDed1z8YShO6W+z6G9oZXuxfNFGd/iGSdc=
github.com/flanksource/gomplate/v3 v3.24.11 h1:gGvWgoKwevbw6G52r37nGjXdNfM/Rx3hlRBPQ0mrAic=
github.com/flanksource/gomplate/v3 v3.24.11/go.mod h1:YTDFEQtaRPkE9KkUiON8kEjPinN1zuWx46r6jh4Pa7A=
github.com/flanksource/gomplate/v3 v3.24.17 h1:NPqVwiWnfRaV/ZywW91KOIBminOctPcTjbQWvDv7bUs=
github.com/flanksource/gomplate/v3 v3.24.17/go.mod h1:9clCoi3+mkkvr9V3J6Ue4YTNBTd4SVEPe9CfeRi7eD8=
github.com/flanksource/is-healthy v0.0.0-20230705092916-3b4cf510c5fc/go.mod h1:4pQhmF+TnVqJroQKY8wSnSp+T18oLson6YQ2M0qPHfQ=
github.com/flanksource/is-healthy v1.0.18 h1:ECOKpPZ6mPLDgQlnNm1XPB0QPxutESV760liBNVd5jo=
github.com/flanksource/is-healthy v1.0.18/go.mod h1:eRPXZShZqaz3Mz+QeoCNbL3857lt9BgCt67jOUQXLOU=
github.com/flanksource/is-healthy v1.0.21 h1:Icjjen+yOb/PWbyWNxdeJSLIZSCC9/WkrEBEfVFDhsM=
github.com/flanksource/is-healthy v1.0.21/go.mod h1:eRPXZShZqaz3Mz+QeoCNbL3857lt9BgCt67jOUQXLOU=
github.com/flanksource/kommons v0.31.4 h1:zksAgYjZuwPgS8XTejDIWEYB0nPSU1i3Jxcavm/vovI=
github.com/flanksource/kommons v0.31.4/go.mod h1:70BPMzjTvejsqRyVyAm/ZCeZ176toCvauaZjU03svnE=
github.com/flanksource/kubectl-neat v1.0.4 h1:t5/9CqgE84oEtB0KitgJ2+WIeLfD+RhXSxYrqb4X8yI=
Expand Down
8 changes: 8 additions & 0 deletions types/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import (
"strings"
)

// +kubebuilder:object:generate=true
type HTTPBasicAuth struct {
Authentication `yaml:",inline" json:",inline"`
NTLM bool `yaml:"ntlm,omitempty" json:"ntlm,omitempty"`
NTLMV2 bool `yaml:"ntlmv2,omitempty" json:"ntlmv2,omitempty"`
Digest bool `yaml:"digest,omitempty" json:"digest,omitempty"`
}

// +kubebuilder:object:generate=true
type Authentication struct {
Username EnvVar `yaml:"username,omitempty" json:"username,omitempty"`
Expand Down
16 changes: 16 additions & 0 deletions types/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f548e7a

Please sign in to comment.