Skip to content

Commit

Permalink
Add delete phone method (#20)
Browse files Browse the repository at this point in the history
Adds support for the Delete Phone API endpoint
  • Loading branch information
invliD authored Aug 26, 2020
1 parent f493462 commit 5d44843
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
20 changes: 19 additions & 1 deletion admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/url"
"strconv"

"github.com/duosecurity/duo_api_golang"
duoapi "github.com/duosecurity/duo_api_golang"
)

// Client provides access to Duo's admin API.
Expand Down Expand Up @@ -574,6 +574,24 @@ func (c *Client) GetPhone(phoneID string) (*GetPhoneResult, error) {
return result, nil
}

// DeletePhone calls DELETE /admin/v1/phones/:phone_id
// See https://duo.com/docs/adminapi#delete-phone
func (c *Client) DeletePhone(phoneID string) (*duoapi.StatResult, error) {
path := fmt.Sprintf("/admin/v1/phones/%s", phoneID)

_, body, err := c.SignedCall(http.MethodDelete, path, nil, duoapi.UseTimeout)
if err != nil {
return nil, err
}

result := &duoapi.StatResult{}
err = json.Unmarshal(body, result)
if err != nil {
return nil, err
}
return result, nil
}

// Token methods

// GetTokensTypeAndSerial sets the optional type and serial parameters for a GetTokens request.
Expand Down
24 changes: 24 additions & 0 deletions admin/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,30 @@ func TestGetPhone(t *testing.T) {
}
}

const deletePhoneResponse = `{
"stat": "OK",
"response": ""
}`

func TestDeletePhone(t *testing.T) {
ts := httptest.NewTLSServer(
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, deletePhoneResponse)
}),
)
defer ts.Close()

duo := buildAdminClient(ts.URL, nil)

result, err := duo.DeletePhone("DPFZRS9FB0D46QFTM899")
if err != nil {
t.Errorf("Unexpected error from DeletePhone call %v", err.Error())
}
if result.Stat != "OK" {
t.Errorf("Expected OK, but got %s", result.Stat)
}
}

const getTokensResponse = `{
"stat": "OK",
"response": [{
Expand Down

0 comments on commit 5d44843

Please sign in to comment.