-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add oauth type * chore: address review comments
- Loading branch information
1 parent
95abb71
commit 081f8aa
Showing
8 changed files
with
143 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package types | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/flanksource/commons/collections" | ||
) | ||
|
||
// +kubebuilder:object:generate=true | ||
type OAuth struct { | ||
ClientID EnvVar `json:"clientID,omitempty"` | ||
ClientSecret EnvVar `json:"clientSecret,omitempty"` | ||
Scopes []string `json:"scope,omitempty" yaml:"scope,omitempty"` | ||
TokenURL string `json:"tokenURL,omitempty" yaml:"tokenURL,omitempty"` | ||
Params map[string]string `json:"params,omitempty" yaml:"params,omitempty"` | ||
} | ||
|
||
func (o OAuth) IsEmpty() bool { | ||
return o.ClientID.IsEmpty() || o.ClientSecret.IsEmpty() || o.TokenURL == "" | ||
} | ||
|
||
// PopulateFromProperties needs properties to be hydrated | ||
func (o *OAuth) PopulateFromProperties(props map[string]string) error { | ||
o.ClientID.ValueStatic = props["clientID"] | ||
o.ClientSecret.ValueStatic = props["clientSecret"] | ||
o.TokenURL = props["tokenURL"] | ||
if props["scope"] != "" { | ||
if err := json.Unmarshal([]byte(props["scopes"]), &o.Scopes); err != nil { | ||
return fmt.Errorf("error unmarshaling scopes:%s in oauth: %w", props["scopes"], err) | ||
} | ||
} | ||
if props["params"] != "" { | ||
if err := json.Unmarshal([]byte(props["params"]), &o.Params); err != nil { | ||
return fmt.Errorf("error unmarshaling params:%s in oauth: %w", props["params"], err) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (o OAuth) AsProperties() JSONStringMap { | ||
var scopes, params string | ||
if o.Scopes != nil { | ||
scopes, _ = collections.StructToJSON(o.Scopes) | ||
} | ||
if o.Params != nil { | ||
params, _ = collections.StructToJSON(o.Params) | ||
} | ||
return map[string]string{ | ||
"clientID": o.ClientID.String(), | ||
"clientSecret": o.ClientSecret.String(), | ||
"tokenURL": o.TokenURL, | ||
"scopes": scopes, | ||
"params": params, | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.