Skip to content

Commit

Permalink
Adds support for private key path in config (#133)
Browse files Browse the repository at this point in the history
* Adds support for private key path in config
  • Loading branch information
vijetmahabaleshwar-okta authored Nov 18, 2020
1 parent c0ad1dd commit 0f3120d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion okta/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
package okta

import (
"io/ioutil"
"log"
"net/http"
"os"

"github.com/okta/okta-sdk-golang/v2/okta/cache"
)
Expand Down Expand Up @@ -180,8 +183,25 @@ func WithScopes(scopes []string) ConfigSetter {
}
}

// WithPrivateKey sets private key key. Can be either a path to a private key or private key itself.
func WithPrivateKey(privateKey string) ConfigSetter {
return func(c *config) {
c.Okta.Client.PrivateKey = privateKey
if fileExists(privateKey) {
content, err := ioutil.ReadFile(privateKey)
if err != nil {
log.Fatalf("failed to read from provided private key file path: %v", err)
}
c.Okta.Client.PrivateKey = string(content)
} else {
c.Okta.Client.PrivateKey = privateKey
}
}
}

func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}

0 comments on commit 0f3120d

Please sign in to comment.