Skip to content

Commit

Permalink
[TT-6933] Implement introspection cache OAS conversion (TykTechnologi…
Browse files Browse the repository at this point in the history
…es#4369)

* Implement introspection cache OAS conversion

* Make caching omittable
  • Loading branch information
furkansenharputlu authored Oct 27, 2022
1 parent 0f0b158 commit 2dd015b
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions apidef/oas/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,12 @@ func (j *JWTValidation) ExtractTo(jwt *apidef.JWTValidation) {
}

type Introspection struct {
Enabled bool `bson:"enabled" json:"enabled"`
URL string `bson:"url" json:"url"`
ClientID string `bson:"clientId" json:"clientId"`
ClientSecret string `bson:"clientSecret" json:"clientSecret"`
IdentityBaseField string `bson:"identityBaseField,omitempty" json:"identityBaseField,omitempty"`
Enabled bool `bson:"enabled" json:"enabled"`
URL string `bson:"url" json:"url"`
ClientID string `bson:"clientId" json:"clientId"`
ClientSecret string `bson:"clientSecret" json:"clientSecret"`
IdentityBaseField string `bson:"identityBaseField,omitempty" json:"identityBaseField,omitempty"`
Cache *IntrospectionCache `bson:"cache,omitempty" json:"cache,omitempty"`
}

func (i *Introspection) Fill(intros apidef.Introspection) {
Expand All @@ -425,6 +426,15 @@ func (i *Introspection) Fill(intros apidef.Introspection) {
i.ClientID = intros.ClientID
i.ClientSecret = intros.ClientSecret
i.IdentityBaseField = intros.IdentityBaseField

if i.Cache == nil {
i.Cache = &IntrospectionCache{}
}

i.Cache.Fill(intros.Cache)
if ShouldOmit(i.Cache) {
i.Cache = nil
}
}

func (i *Introspection) ExtractTo(intros *apidef.Introspection) {
Expand All @@ -433,6 +443,25 @@ func (i *Introspection) ExtractTo(intros *apidef.Introspection) {
intros.ClientID = i.ClientID
intros.ClientSecret = i.ClientSecret
intros.IdentityBaseField = i.IdentityBaseField

if i.Cache != nil {
i.Cache.ExtractTo(&intros.Cache)
}
}

type IntrospectionCache struct {
Enabled bool `bson:"enabled" json:"enabled"`
Timeout int64 `bson:"timeout" json:"timeout"`
}

func (c *IntrospectionCache) Fill(cache apidef.IntrospectionCache) {
c.Enabled = cache.Enabled
c.Timeout = cache.Timeout
}

func (c *IntrospectionCache) ExtractTo(cache *apidef.IntrospectionCache) {
cache.Enabled = c.Enabled
cache.Timeout = c.Timeout
}

type ExternalOAuth struct {
Expand Down

0 comments on commit 2dd015b

Please sign in to comment.