-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cdb9d1f
commit 4f7d6d1
Showing
4 changed files
with
156 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package flagsmithapi | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func (c *Client) GetServerSideEnvKeys(environmentKey string) (*[]ServerSideEnvKey, error) { | ||
url := fmt.Sprintf("%s/environments/%s/api-keys/", c.baseURL, environmentKey) | ||
keys := []ServerSideEnvKey{} | ||
resp, err := c.client.R().SetResult(&keys).Get(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if !resp.IsSuccess() { | ||
return nil, fmt.Errorf("flagsmithapi: Error deleting identity: %v", resp) | ||
} | ||
return &keys, nil | ||
} | ||
func (c *Client) CreateServerSideEnvKey(environmentKey string, key *ServerSideEnvKey) error { | ||
url := fmt.Sprintf("%s/environments/%s/api-keys/", c.baseURL, environmentKey) | ||
|
||
resp, err := c.client.R().SetBody(key).SetResult(&key).Post(url) | ||
if err != nil { | ||
return err | ||
} | ||
if !resp.IsSuccess() { | ||
return fmt.Errorf("flagsmithapi: Error creating server side environment key: %s", resp) | ||
} | ||
return nil | ||
|
||
} | ||
func (c *Client) UpdateServerSideEnvKey(environmentKey string, key *ServerSideEnvKey) error { | ||
url := fmt.Sprintf("%s/environments/%s/api-keys/%d/", c.baseURL, environmentKey, key.ID) | ||
resp, err := c.client.R().SetBody(key).SetResult(&key).Put(url) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
if !resp.IsSuccess() { | ||
return fmt.Errorf("flagsmithapi: Error updating server side environment key: %s", resp) | ||
} | ||
return nil | ||
} | ||
func (c *Client) DeleteServerSideEnvKey(environmentKey string, keyID int64) error { | ||
url := fmt.Sprintf("%s/environments/%s/api-keys/%d/", c.baseURL, environmentKey, keyID) | ||
resp, err := c.client.R().Delete(url) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !resp.IsSuccess() { | ||
return fmt.Errorf("flagsmithapi: Error deleting server side environment key: %s", resp) | ||
} | ||
return nil | ||
|
||
} |
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,45 @@ | ||
package flagsmithapi | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func (c *Client) GetIdentity(environmentKey string, identityID int64) (*Identity, error) { | ||
url := fmt.Sprintf("%s/environments/%s/identities/%d/", c.baseURL, environmentKey, identityID) | ||
identity := Identity{} | ||
resp, err := c.client.R().SetResult(&identity).Get(url) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if !resp.IsSuccess() { | ||
return nil, fmt.Errorf("flagsmithapi: Error deleting identity: %v", resp) | ||
} | ||
return &identity, nil | ||
} | ||
func (c *Client) CreateIdentity(environmentKey string, identity *Identity) error { | ||
url := fmt.Sprintf("%s/environments/%s/identities/", c.baseURL, environmentKey) | ||
|
||
resp, err := c.client.R().SetBody(identity).SetResult(&identity).Post(url) | ||
if err != nil { | ||
return err | ||
} | ||
if !resp.IsSuccess() { | ||
return fmt.Errorf("flagsmithapi: Error creating identity: %s", resp) | ||
} | ||
return nil | ||
|
||
} | ||
func (c *Client) DeleteIdentity(environmentKey string, identityID int64) error { | ||
url := fmt.Sprintf("%s/environments/%s/identities/%d/", c.baseURL, environmentKey, identityID) | ||
resp, err := c.client.R().Delete(url) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !resp.IsSuccess() { | ||
return fmt.Errorf("flagsmithapi: Error deleting identity: %s", resp) | ||
} | ||
return nil | ||
|
||
} |
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