-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from ponkuma123/EUM_TERRAFORM_PROVIDER_BRANCH
Credential Profile Resource and Data Source.
- Loading branch information
Showing
20 changed files
with
907 additions
and
66 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
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,83 @@ | ||
package common | ||
|
||
import ( | ||
"github.com/site24x7/terraform-provider-site24x7/api" | ||
"github.com/site24x7/terraform-provider-site24x7/rest" | ||
) | ||
|
||
type CredentialProfile interface { | ||
Get(credentialProfileID string) (*api.CredentialProfile, error) | ||
Create(credentialProfile *api.CredentialProfile) (*api.CredentialProfile, error) | ||
Update(credentialProfile *api.CredentialProfile) (*api.CredentialProfile, error) | ||
Delete(credentialProfileID string) error | ||
ListWebCredentials() ([]*api.CredentialProfile, error) | ||
} | ||
|
||
type credentialprofile struct { | ||
client rest.Client | ||
} | ||
|
||
func NewCredentialProfile(client rest.Client) CredentialProfile { | ||
return &credentialprofile{ | ||
client: client, | ||
} | ||
} | ||
|
||
func (c *credentialprofile) Get(credentialProfileID string) (*api.CredentialProfile, error) { | ||
credentialProfile := &api.CredentialProfile{} | ||
err := c.client. | ||
Get(). | ||
Resource("credential_profile"). | ||
ResourceID(credentialProfileID). | ||
Do(). | ||
Parse(credentialProfile) | ||
|
||
return credentialProfile, err | ||
} | ||
|
||
func (c *credentialprofile) Create(credentialProfile *api.CredentialProfile) (*api.CredentialProfile, error) { | ||
newCredentialProfile := &api.CredentialProfile{} | ||
err := c.client. | ||
Post(). | ||
Resource("credential_profile"). | ||
AddHeader("Content-Type", "application/json;charset=UTF-8"). | ||
Body(credentialProfile). | ||
Do(). | ||
Parse(newCredentialProfile) | ||
|
||
return newCredentialProfile, err | ||
} | ||
|
||
func (c *credentialprofile) Update(credentialProfile *api.CredentialProfile) (*api.CredentialProfile, error) { | ||
updatedCredentialProfile := &api.CredentialProfile{} | ||
err := c.client. | ||
Put(). | ||
Resource("credential_profile"). | ||
ResourceID(credentialProfile.ID). | ||
AddHeader("Content-Type", "application/json;charset=UTF-8"). | ||
Body(credentialProfile). | ||
Do(). | ||
Parse(updatedCredentialProfile) | ||
|
||
return updatedCredentialProfile, err | ||
} | ||
|
||
func (c *credentialprofile) Delete(credentialProfileID string) error { | ||
return c.client. | ||
Delete(). | ||
Resource("credential_profile"). | ||
ResourceID(credentialProfileID). | ||
Do(). | ||
Err() | ||
} | ||
|
||
func (c *credentialprofile) ListWebCredentials() ([]*api.CredentialProfile, error) { | ||
credentialProfiles := []*api.CredentialProfile{} | ||
err := c.client. | ||
Get(). | ||
Resource("credential_profiles"). | ||
Do(). | ||
Parse(&credentialProfiles) | ||
|
||
return credentialProfiles, err | ||
} |
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,84 @@ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/site24x7/terraform-provider-site24x7/api" | ||
"github.com/site24x7/terraform-provider-site24x7/rest" | ||
"github.com/site24x7/terraform-provider-site24x7/validation" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRestApiMonitors(t *testing.T) { | ||
validation.RunTests(t, []*validation.EndpointTest{ | ||
{ | ||
Name: "Create credential profile", | ||
ExpectedVerb: "POST", | ||
ExpectedPath: "/credential_profiles", | ||
ExpectedBody: validation.Fixture(t, "requests/create_rest_api_monitor.json"), | ||
StatusCode: 200, | ||
ResponseBody: validation.JsonAPIResponseBody(t, nil), | ||
Fn: func(t *testing.T, c rest.Client) { | ||
credentialProfile := &api.CredentialProfile{ | ||
CredentialType: 3, | ||
CredentialName: "Creditial profile", | ||
UserName: "postman", | ||
Password: "test", | ||
} | ||
|
||
_, err := NewCredentialProfile(c).Create(credentialProfile) | ||
require.NoError(t, err) | ||
}, | ||
}, | ||
{ | ||
Name: "Get Credential profile", | ||
ExpectedVerb: "GET", | ||
ExpectedPath: "/credential_profiles/123", | ||
StatusCode: 200, | ||
ResponseBody: validation.Fixture(t, "responses/get_rest_api_monitor.json"), | ||
Fn: func(t *testing.T, c rest.Client) { | ||
credentialProfile, err := NewCredentialProfile(c).Get("123") | ||
require.NoError(t, err) | ||
|
||
expected := &api.CredentialProfile{ | ||
CredentialType: 3, | ||
CredentialName: "Creditial profile", | ||
UserName: "postman", | ||
Password: "test", | ||
} | ||
|
||
assert.Equal(t, expected, credentialProfile) | ||
}, | ||
}, | ||
{ | ||
Name: "Update Credential profile", | ||
ExpectedVerb: "PUT", | ||
ExpectedPath: "/credential_profiles/123", | ||
ExpectedBody: validation.Fixture(t, "requests/update_rest_api_monitor.json"), | ||
StatusCode: 200, | ||
ResponseBody: validation.JsonAPIResponseBody(t, nil), | ||
Fn: func(t *testing.T, c rest.Client) { | ||
credentialProfile := &api.CredentialProfile{ | ||
ID: "123", | ||
CredentialType: 3, | ||
CredentialName: "Creditial profile", | ||
UserName: "postman", | ||
Password: "test", | ||
} | ||
|
||
_, err := NewCredentialProfile(c).Update(credentialProfile) | ||
require.NoError(t, err) | ||
}, | ||
}, | ||
{ | ||
Name: "Delete Credential profile", | ||
ExpectedVerb: "DELETE", | ||
ExpectedPath: "/credential_profiles/123", | ||
StatusCode: 200, | ||
Fn: func(t *testing.T, c rest.Client) { | ||
require.NoError(t, NewCredentialProfile(c).Delete("123")) | ||
}, | ||
}, | ||
}) | ||
} |
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,42 @@ | ||
package fake | ||
|
||
import ( | ||
"github.com/site24x7/terraform-provider-site24x7/api" | ||
"github.com/site24x7/terraform-provider-site24x7/api/endpoints/common" | ||
"github.com/stretchr/testify/mock" | ||
) | ||
|
||
var _ common.CredentialProfile = &CredentialProfile{} | ||
|
||
type CredentialProfile struct { | ||
mock.Mock | ||
} | ||
|
||
func (e *CredentialProfile) Get(credentialProfileID string) (*api.CredentialProfile, error) { | ||
args := e.Called(credentialProfileID) | ||
if obj, ok := args.Get(0).(*api.CredentialProfile); ok { | ||
return obj, args.Error(1) | ||
} | ||
return nil, args.Error(1) | ||
} | ||
|
||
func (e *CredentialProfile) Create(credentialProfile *api.CredentialProfile) (*api.CredentialProfile, error) { | ||
args := e.Called(credentialProfile) | ||
if obj, ok := args.Get(0).(*api.CredentialProfile); ok { | ||
return obj, args.Error(1) | ||
} | ||
return nil, args.Error(1) | ||
} | ||
|
||
func (e *CredentialProfile) Update(credentialProfile *api.CredentialProfile) (*api.CredentialProfile, error) { | ||
args := e.Called(credentialProfile) | ||
if obj, ok := args.Get(0).(*api.CredentialProfile); ok { | ||
return obj, args.Error(1) | ||
} | ||
return nil, args.Error(1) | ||
} | ||
|
||
func (e *CredentialProfile) Delete(credentialProfileID string) error { | ||
args := e.Called(credentialProfileID) | ||
return args.Error(0) | ||
} |
6 changes: 6 additions & 0 deletions
6
api/endpoints/testdata/fixtures/requests/create_credential_profile.json
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,6 @@ | ||
{ | ||
"credential_type": 3, | ||
"credential_name": "Credential profile", | ||
"username": "UserName", | ||
"password": "password" | ||
} |
7 changes: 7 additions & 0 deletions
7
api/endpoints/testdata/fixtures/requests/update_credential_profile.json
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,7 @@ | ||
{ | ||
"credential_profile_id":"123", | ||
"credential_type": 3, | ||
"credential_name": "Credential profile", | ||
"username": "UserName", | ||
"password": "password" | ||
} |
12 changes: 12 additions & 0 deletions
12
api/endpoints/testdata/fixtures/responses/get_credential_profiles.json
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,12 @@ | ||
{ | ||
"code": 0, | ||
"message": "success", | ||
"data": { | ||
"credential_type": 3, | ||
"credential_name": "Credential profile", | ||
"credential_profile_id": "123", | ||
"username": "UserName", | ||
"password": "password", | ||
"is_credential_associated": false | ||
} | ||
} |
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
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,61 @@ | ||
--- | ||
layout: "site24x7" | ||
page_title: "Site24x7: site24x7_credential_profile" | ||
sidebar_current: "docs-site24x7-data-source-credential-profile" | ||
description: |- | ||
Get information about a Credential Profile in Site24x7. | ||
--- | ||
|
||
# Data Source: site24x7\_credential\_profile | ||
|
||
Use this data source to retrieve information about an existing Credential Profiles in Site24x7. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
// Data source to fetch an Credential Profile | ||
data "site24x7_credential_profile" "s247credentialprofile" { | ||
// (Required) Regular expression denoting the name of the Credential Profile. | ||
name_regex = "url" | ||
} | ||
// Displays the Credential Profile ID | ||
output "s247_credential_profile_id" { | ||
description = "Credential Profile ID : " | ||
value = data.site24x7_credential_profile.s247credentialprofile.id | ||
} | ||
// Displays the Credential Profile Name | ||
output "s247_credential_profile_name" { | ||
description = "Credential Profile name : " | ||
value = data.site24x7_credential_profile.s247credentialprofile.credential_name | ||
} | ||
// Displays the Credential Profile Type | ||
output "s247_credential_profile_type" { | ||
description = "Credential Profile type : " | ||
value = data.site24x7_credential_profile.s247credentialprofile.credential_type | ||
} | ||
// Displays the Credential Profile username | ||
output "s247_credential_profile_username" { | ||
description = "Credential Profile username: " | ||
value = data.site24x7_credential_profile.s247credentialprofile.username | ||
} | ||
``` | ||
|
||
## Attributes Reference | ||
|
||
### Required | ||
|
||
* `name_regex` (String) Regular expression denoting the name of the Credential Profile. | ||
|
||
### Read-Only | ||
|
||
* `id` (String) The ID of the matching Credential Profile. | ||
* `credential_type` (Integer) Type for the Credential Profile. | ||
* `credential_name` (String) Name for the Credential Profile. | ||
* `username` (String) Username for the Credential Profile. | ||
|
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,41 @@ | ||
--- | ||
layout: "site24x7" | ||
page_title: "Site24x7: site24x7_credential_profile" | ||
sidebar_current: "docs-site24x7-resource-credential-profile" | ||
description: |- | ||
Create and manage a Credential Profile monitor in Site24x7. | ||
--- | ||
|
||
# Resource: site24x7\_Credential\_Profile | ||
|
||
Use this resource to create, update and delete a Credential Profile in Site24x7. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
// Site24x7 Credential Profile API doc - https://www.site24x7.com/help/api/#credential-profile | ||
resource "site24x7_credential_profile" "credential_profile_us" { | ||
// (Required) Credential Profile Name. | ||
credential_name = "Credential profile - terraform" | ||
// (Required) Credential Profile Type. | ||
credential_type = 3 | ||
// (Required) Username for the Credential Profile. | ||
username = "Testing" | ||
// (Required) Password for the Credential Profile. | ||
password = "Test" | ||
} | ||
``` | ||
|
||
## Attributes Reference | ||
|
||
### Required | ||
|
||
* `credential_name` (String) Credential Profile Name. | ||
* `credential_type` (Integer) Credential Profile Type. | ||
* `username` (String) Username for the Credential Profile. | ||
* `password` (String) Password for the Credential Profile. | ||
|
||
|
||
Refer [API documentation](https://www.site24x7.com/help/api/#credential-profile) for more information about attributes. |
Oops, something went wrong.