Skip to content

Commit

Permalink
Update key names, instead of recreating them (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswuerbach authored and jianyuan committed Jan 22, 2017
1 parent 6c44592 commit 1539cfb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
12 changes: 12 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ type CreateKeyParams struct {
Name string `json:"name"`
}

type UpdateKeyParams struct {
Name string `json:"name"`
}

func (c *Client) GetKey(organizationSlug, projectSlug, keyID string) (*Key, *http.Response, error) {
var key Key

Expand Down Expand Up @@ -253,6 +257,14 @@ func (c *Client) CreateKey(organizationSlug, projectSlug string, params *CreateK
return &key, resp, relevantError(err, apiErr)
}

func (c *Client) UpdateKey(organizationSlug, projectSlug string, keyID string, params *UpdateKeyParams) (*Key, *http.Response, error) {
var key Key
apiErr := make(APIError)
path := fmt.Sprintf("0/projects/%s/%s/keys/%s/", organizationSlug, projectSlug, keyID)
resp, err := c.sling.New().Put(path).BodyJSON(params).Receive(&key, &apiErr)
return &key, resp, relevantError(err, apiErr)
}

func (c *Client) DeleteKey(organizationSlug, projectSlug, keyID string) (*http.Response, error) {
apiErr := make(APIError)
path := fmt.Sprintf("0/projects/%s/%s/keys/%s/", organizationSlug, projectSlug, keyID)
Expand Down
21 changes: 20 additions & 1 deletion resource_sentry_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func resourceSentryKey() *schema.Resource {
return &schema.Resource{
Create: resourceSentryKeyCreate,
Read: resourceSentryKeyRead,
Update: resourceSentryKeyUpdate,
Delete: resourceSentryKeyDelete,
Importer: &schema.ResourceImporter{
State: resourceKeyImporter,
Expand All @@ -33,7 +34,6 @@ func resourceSentryKey() *schema.Resource {
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The name of the key",
},
"dsn_secret": &schema.Schema{
Expand Down Expand Up @@ -94,6 +94,25 @@ func resourceSentryKeyRead(d *schema.ResourceData, meta interface{}) error {
return nil
}

func resourceSentryKeyUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Client)

id := d.Id()
org := d.Get("organization").(string)
project := d.Get("project").(string)
params := &UpdateKeyParams{
Name: d.Get("name").(string),
}

key, _, err := client.UpdateKey(org, project, id, params)
if err != nil {
return err
}

d.SetId(key.ID)
return resourceSentryKeyRead(d, meta)
}

func resourceSentryKeyDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*Client)

Expand Down

0 comments on commit 1539cfb

Please sign in to comment.