@@ -21,12 +21,15 @@ var (
2121 EnvCommandUsername = "KEYFACTOR_USERNAME"
2222 EnvCommandPassword = "KEYFACTOR_PASSWORD"
2323 EnvCommandDomain = "KEYFACTOR_DOMAIN"
24+ EnvCommandAPI = "KEYFACTOR_API_PATH"
25+ DefaultAPIPath = "KeyfactorAPI"
2426)
2527
2628type Client struct {
2729 hostname string
2830 httpClient * http.Client
2931 basicAuthString string
32+ apiPath string
3033}
3134
3235// AuthConfig is a struct holding all necessary client configuration data
@@ -37,6 +40,7 @@ type AuthConfig struct {
3740 Username string
3841 Password string
3942 Domain string
43+ APIPath string
4044}
4145
4246// NewKeyfactorClient creates a new Keyfactor client instance. A configured Client is returned with methods used to
@@ -61,6 +65,14 @@ func loginToKeyfactor(auth *AuthConfig) (*Client, error) {
6165 return nil , fmt .Errorf ("%s is required" , EnvCommandHostname )
6266 }
6367 }
68+ if auth .APIPath == "" {
69+ envAPIPath := os .Getenv (EnvCommandAPI )
70+ if envAPIPath != "" {
71+ auth .APIPath = envAPIPath
72+ } else {
73+ auth .APIPath = DefaultAPIPath
74+ }
75+ }
6476 if auth .Username == "" {
6577 envUsername := os .Getenv (EnvCommandUsername )
6678 if envUsername != "" {
@@ -103,6 +115,7 @@ func loginToKeyfactor(auth *AuthConfig) (*Client, error) {
103115 hostname : auth .Hostname ,
104116 httpClient : & http.Client {Timeout : 10 * time .Second },
105117 basicAuthString : buildBasicAuthString (auth ),
118+ apiPath : auth .APIPath ,
106119 }
107120
108121 _ , err := c .sendRequest (keyfactorAPIStruct )
@@ -129,7 +142,7 @@ func (c *Client) sendRequest(request *request) (*http.Response, error) {
129142 if u .Scheme != "https" {
130143 u .Scheme = "https"
131144 }
132- endpoint := "KeyfactorAPI/" + request .Endpoint
145+ endpoint := fmt . Sprintf ( "%s/" , strings . Trim ( c . apiPath , "/" )) + request .Endpoint
133146 u .Path = path .Join (u .Path , endpoint ) // Attach enroll endpoint
134147
135148 // Set request query
0 commit comments