Skip to content

Commit

Permalink
add godocs
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffy-mathew committed Oct 1, 2024
1 parent 808b3b9 commit e818bc5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
18 changes: 14 additions & 4 deletions apidef/api_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -767,19 +767,29 @@ type APIDefinition struct {
UpstreamAuth UpstreamAuth `bson:"upstream_auth" json:"upstream_auth"`
}

// UpstreamAuth holds the configurations related to upstream API authentication.
type UpstreamAuth struct {
Enabled bool `bson:"enabled" json:"enabled"`
// Enabled enables upstream API authentication.
Enabled bool `bson:"enabled" json:"enabled"`
// BasicAuth holds the basic authentication configuration for upstream API authentication.
BasicAuth UpstreamBasicAuth `bson:"basic_auth" json:"basic_auth"`
}

// IsEnabled checks if UpstreamAuthentication is enabled for the API.
func (u *UpstreamAuth) IsEnabled() bool {
return u.Enabled && u.BasicAuth.Enabled
}

// UpstreamBasicAuth holds upstream basic authentication configuration.
type UpstreamBasicAuth struct {
Enabled bool `bson:"enabled" json:"enabled,omitempty"`
Username string `bson:"username" json:"username"`
Password string `bson:"password" json:"password"`
// Enabled enables upstream basic authentication.
Enabled bool `bson:"enabled" json:"enabled,omitempty"`
// Username is the username to be used for upstream basic authentication.
Username string `bson:"username" json:"username"`
// Password is the password to be used for upstream basic authentication.
Password string `bson:"password" json:"password"`
// HeaderName is the custom header name to be used for upstream basic authentication.
// Defaults to `Authorization`.
HeaderName string `bson:"auth_header_name" json:"authHeaderName"`
}

Expand Down
17 changes: 13 additions & 4 deletions apidef/oas/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,11 @@ func (r *RateLimitEndpoint) ExtractTo(meta *apidef.RateLimitMeta) {
meta.Per = r.Per.Seconds()
}

// UpstreamAuth holds the configurations related to upstream API authentication.
type UpstreamAuth struct {
Enabled bool `bson:"enabled" json:"enabled"`
// Enabled enables upstream API authentication.
Enabled bool `bson:"enabled" json:"enabled"`
// BasicAuth holds the basic authentication configuration for upstream API authentication.
BasicAuth *UpstreamBasicAuth `bson:"basicAuth,omitempty" json:"basicAuth,omitempty"`
}

Expand Down Expand Up @@ -584,11 +587,17 @@ func (u *UpstreamAuth) ExtractTo(api *apidef.UpstreamAuth) {
u.BasicAuth.ExtractTo(&api.BasicAuth)
}

// UpstreamBasicAuth holds upstream basic authentication configuration.
type UpstreamBasicAuth struct {
Enabled bool `bson:"enabled" json:"enabled"`
// Enabled enables upstream basic authentication.v
Enabled bool `bson:"enabled" json:"enabled"`
// Username is the username to be used for upstream basic authentication.
HeaderName string `bson:"headerName" json:"headerName"`
Username string `bson:"username" json:"username"`
Password string `bson:"password" json:"password"`
// Password is the password to be used for upstream basic authentication.
Username string `bson:"username" json:"username"`
// HeaderName is the custom header name to be used for upstream basic authentication.
// Defaults to `Authorization`.
Password string `bson:"password" json:"password"`
}

// Fill fills *UpstreamBasicAuth from apidef.UpstreamBasicAuth.
Expand Down

0 comments on commit e818bc5

Please sign in to comment.