-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* moved contents to a package * saving create * final changes * added reference in main.go * fixed comments * resolved cyclic * updated with singleton ref
- Loading branch information
1 parent
2aeea09
commit c6d7902
Showing
12 changed files
with
312 additions
and
116 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
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
65 changes: 65 additions & 0 deletions
65
...telephony_providers_edges_trunk/genesyscloud_telephony_providers_edges_trunk_init_test.go
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,65 @@ | ||
package telephony_providers_edges_trunk | ||
|
||
import ( | ||
"sync" | ||
gcloud "terraform-provider-genesyscloud/genesyscloud" | ||
|
||
telephony "terraform-provider-genesyscloud/genesyscloud/telephony" | ||
edgeSite "terraform-provider-genesyscloud/genesyscloud/telephony_providers_edges_site" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
var providerDataSources map[string]*schema.Resource | ||
var providerResources map[string]*schema.Resource | ||
|
||
type registerTestInstance struct { | ||
resourceMapMutex sync.RWMutex | ||
datasourceMapMutex sync.RWMutex | ||
} | ||
|
||
func (r *registerTestInstance) registerTestResources() { | ||
|
||
r.resourceMapMutex.Lock() | ||
defer r.resourceMapMutex.Unlock() | ||
|
||
providerResources["genesyscloud_telephony_providers_edges_trunkbasesettings"] = telephony.ResourceTrunkBaseSettings() | ||
providerResources["genesyscloud_telephony_providers_edges_trunk"] = ResourceTrunk() | ||
|
||
// external package dependencies | ||
providerResources["genesyscloud_telephony_providers_edges_site"] = edgeSite.ResourceSite() | ||
|
||
providerResources["genesyscloud_location"] = gcloud.ResourceLocation() | ||
|
||
} | ||
|
||
func (r *registerTestInstance) registerTestDataSources() { | ||
|
||
r.datasourceMapMutex.Lock() | ||
defer r.datasourceMapMutex.Unlock() | ||
|
||
providerDataSources["genesyscloud_telephony_providers_edges_trunkbasesettings"] = telephony.DataSourceTrunkBaseSettings() | ||
providerDataSources["genesyscloud_telephony_providers_edges_trunk"] = DataSourceTrunk() | ||
// external package dependencies | ||
providerDataSources["genesyscloud_telephony_providers_edges_site"] = edgeSite.DataSourceSite() | ||
|
||
} | ||
|
||
func initTestResources() { | ||
providerDataSources = make(map[string]*schema.Resource) | ||
providerResources = make(map[string]*schema.Resource) | ||
|
||
regInstance := ®isterTestInstance{} | ||
|
||
regInstance.registerTestDataSources() | ||
regInstance.registerTestResources() | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
// Run setup function before starting the test suite | ||
initTestResources() | ||
|
||
// Run the test suite | ||
m.Run() | ||
} |
119 changes: 119 additions & 0 deletions
119
...oud/telephony_providers_edges_trunk/genesyscloud_telephony_providers_edges_trunk_proxy.go
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,119 @@ | ||
package telephony_providers_edges_trunk | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/mypurecloud/platform-client-sdk-go/v116/platformclientv2" | ||
) | ||
|
||
//generate a proxy for telephony_providers_edges_trunk | ||
|
||
// internalProxy holds a proxy instance that can be used throughout the package | ||
var internalProxy *trunkProxy | ||
|
||
// Type definitions for each func on our proxy so we can easily mock them out later | ||
|
||
type getTrunkByIdFunc func(ctx context.Context, p *trunkProxy, id string) (*platformclientv2.Trunk, *platformclientv2.APIResponse, error) | ||
type getAllTrunksFunc func(ctx context.Context, p *trunkProxy, pageNum int, pageSize int) (*platformclientv2.Trunkentitylisting, *platformclientv2.APIResponse, error) | ||
type getTrunkBaseSettingsFunc func(ctx context.Context, p *trunkProxy, trunkBaseSettingsId string) (*platformclientv2.Trunkbase, *platformclientv2.APIResponse, error) | ||
type getEdgeFunc func(ctx context.Context, p *trunkProxy, edgeId string) (*platformclientv2.Edge, *platformclientv2.APIResponse, error) | ||
type putEdgeFunc func(ctx context.Context, p *trunkProxy, edgeId string, edge platformclientv2.Edge) (*platformclientv2.Edge, *platformclientv2.APIResponse, error) | ||
type getEdgeGroupFunc func(ctx context.Context, p *trunkProxy, edgeGroupId string) (*platformclientv2.Edgegroup, *platformclientv2.APIResponse, error) | ||
type putEdgeGroupFunc func(ctx context.Context, p *trunkProxy, edgeGroupId string, edgeGroup platformclientv2.Edgegroup) (*platformclientv2.Edgegroup, *platformclientv2.APIResponse, error) | ||
|
||
// Proxy contains all of the methods that call genesys cloud APIs. | ||
type trunkProxy struct { | ||
clientConfig *platformclientv2.Configuration | ||
edgesApi *platformclientv2.TelephonyProvidersEdgeApi | ||
|
||
getTrunkByIdAttr getTrunkByIdFunc | ||
getAllTrunksAttr getAllTrunksFunc | ||
getTrunkBaseSettingsAttr getTrunkBaseSettingsFunc | ||
getEdgeAttr getEdgeFunc | ||
putEdgeAttr putEdgeFunc | ||
getEdgeGroupAttr getEdgeGroupFunc | ||
putEdgeGroupAttr putEdgeGroupFunc | ||
} | ||
|
||
// initializes the proxy with all of the data needed to communicate with Genesys Cloud | ||
func newTrunkProxy(clientConfig *platformclientv2.Configuration) *trunkProxy { | ||
edgesApi := platformclientv2.NewTelephonyProvidersEdgeApiWithConfig(clientConfig) | ||
return &trunkProxy{ | ||
clientConfig: clientConfig, | ||
edgesApi: edgesApi, | ||
getTrunkByIdAttr: getTrunkByIdFn, | ||
getAllTrunksAttr: getAllTrunksFn, | ||
getEdgeAttr: getEdgeFn, | ||
putEdgeAttr: putEdgeFn, | ||
getEdgeGroupAttr: getEdgeGroupFn, | ||
putEdgeGroupAttr: putEdgeGroupFn, | ||
getTrunkBaseSettingsAttr: getTrunkBaseSettingsFn, | ||
} | ||
} | ||
|
||
// getTeamProxy acts as a singleton to for the internalProxy. It also ensures | ||
// that we can still proxy our tests by directly setting internalProxy package variable | ||
func getTrunkProxy(clientConfig *platformclientv2.Configuration) *trunkProxy { | ||
if internalProxy == nil { | ||
internalProxy = newTrunkProxy(clientConfig) | ||
} | ||
|
||
return internalProxy | ||
} | ||
|
||
func (p *trunkProxy) getEdge(ctx context.Context, edgeId string) (*platformclientv2.Edge, *platformclientv2.APIResponse, error) { | ||
return p.getEdgeAttr(ctx, p, edgeId) | ||
} | ||
|
||
func (p *trunkProxy) putEdge(ctx context.Context, edgeId string, edge platformclientv2.Edge) (*platformclientv2.Edge, *platformclientv2.APIResponse, error) { | ||
return p.putEdgeAttr(ctx, p, edgeId, edge) | ||
} | ||
|
||
func (p *trunkProxy) getEdgeGroup(ctx context.Context, edgeGroupId string) (*platformclientv2.Edgegroup, *platformclientv2.APIResponse, error) { | ||
return p.getEdgeGroupAttr(ctx, p, edgeGroupId) | ||
} | ||
|
||
func (p *trunkProxy) putEdgeGroup(ctx context.Context, edgeGroupId string, edgeGroup platformclientv2.Edgegroup) (*platformclientv2.Edgegroup, *platformclientv2.APIResponse, error) { | ||
return p.putEdgeGroupAttr(ctx, p, edgeGroupId, edgeGroup) | ||
} | ||
|
||
func (p *trunkProxy) getTrunkBaseSettings(ctx context.Context, trunkBaseSettingsId string) (*platformclientv2.Trunkbase, *platformclientv2.APIResponse, error) { | ||
return p.getTrunkBaseSettingsAttr(ctx, p, trunkBaseSettingsId) | ||
} | ||
|
||
func (p *trunkProxy) getTrunkById(ctx context.Context, id string) (*platformclientv2.Trunk, *platformclientv2.APIResponse, error) { | ||
return p.getTrunkByIdAttr(ctx, p, id) | ||
} | ||
|
||
func (p *trunkProxy) getAllTrunks(ctx context.Context, pageNum int, pageSize int) (*platformclientv2.Trunkentitylisting, *platformclientv2.APIResponse, error) { | ||
return p.getAllTrunksAttr(ctx, p, pageNum, pageSize) | ||
} | ||
|
||
func getEdgeFn(ctx context.Context, p *trunkProxy, edgeId string) (*platformclientv2.Edge, *platformclientv2.APIResponse, error) { | ||
return p.edgesApi.GetTelephonyProvidersEdge(edgeId, nil) | ||
} | ||
|
||
func putEdgeFn(ctx context.Context, p *trunkProxy, edgeId string, edge platformclientv2.Edge) (*platformclientv2.Edge, *platformclientv2.APIResponse, error) { | ||
return p.edgesApi.PutTelephonyProvidersEdge(edgeId, edge) | ||
} | ||
|
||
func getEdgeGroupFn(ctx context.Context, p *trunkProxy, edgeGroupId string) (*platformclientv2.Edgegroup, *platformclientv2.APIResponse, error) { | ||
return p.edgesApi.GetTelephonyProvidersEdgesEdgegroup(edgeGroupId, nil) | ||
} | ||
|
||
func putEdgeGroupFn(ctx context.Context, p *trunkProxy, edgeGroupId string, edgeGroup platformclientv2.Edgegroup) (*platformclientv2.Edgegroup, *platformclientv2.APIResponse, error) { | ||
return p.edgesApi.PutTelephonyProvidersEdgesEdgegroup(edgeGroupId, edgeGroup) | ||
} | ||
|
||
func getTrunkBaseSettingsFn(ctx context.Context, p *trunkProxy, trunkBaseSettingsId string) (*platformclientv2.Trunkbase, *platformclientv2.APIResponse, error) { | ||
return p.edgesApi.GetTelephonyProvidersEdgesTrunkbasesetting(trunkBaseSettingsId, true) | ||
} | ||
|
||
func getTrunkByIdFn(ctx context.Context, p *trunkProxy, trunkBaseSettingsId string) (*platformclientv2.Trunk, *platformclientv2.APIResponse, error) { | ||
return p.edgesApi.GetTelephonyProvidersEdgesTrunk(trunkBaseSettingsId) | ||
} | ||
|
||
func getAllTrunksFn(ctx context.Context, p *trunkProxy, pageNum int, pageSize int) (*platformclientv2.Trunkentitylisting, *platformclientv2.APIResponse, error) { | ||
|
||
return p.edgesApi.GetTelephonyProvidersEdgesTrunks(pageNum, pageSize, "", "", "", "", "") | ||
} |
70 changes: 70 additions & 0 deletions
70
...ud/telephony_providers_edges_trunk/genesyscloud_telephony_providers_edges_trunk_schema.go
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,70 @@ | ||
package telephony_providers_edges_trunk | ||
|
||
import ( | ||
gcloud "terraform-provider-genesyscloud/genesyscloud" | ||
registrar "terraform-provider-genesyscloud/genesyscloud/resource_register" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
const resourceName = "genesyscloud_telephony_providers_edges_did" | ||
|
||
func SetRegistrar(l registrar.Registrar) { | ||
l.RegisterDataSource("genesyscloud_telephony_providers_edges_trunk", DataSourceTrunk()) | ||
l.RegisterResource("genesyscloud_telephony_providers_edges_trunk", ResourceTrunk()) | ||
l.RegisterExporter("genesyscloud_telephony_providers_edges_trunk", TrunkExporter()) | ||
} | ||
|
||
func DataSourceTrunk() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Data source for Genesys Cloud Trunk. Select a trunk by name", | ||
ReadContext: gcloud.ReadWithPooledClient(dataSourceTrunkRead), | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Description: "Trunk name.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func ResourceTrunk() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Genesys Cloud Trunk. Created by assigning a trunk base settings to an edge or edge group", | ||
|
||
CreateContext: gcloud.CreateWithPooledClient(createTrunk), | ||
ReadContext: gcloud.ReadWithPooledClient(readTrunk), | ||
UpdateContext: gcloud.UpdateWithPooledClient(updateTrunk), | ||
DeleteContext: gcloud.DeleteWithPooledClient(deleteTrunk), | ||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
SchemaVersion: 1, | ||
Schema: map[string]*schema.Schema{ | ||
"trunk_base_settings_id": { | ||
Description: "The trunk base settings reference", | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"edge_group_id": { | ||
Description: "The edge group associated with this trunk. Either this or \"edge_id\" must be set", | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"edge_id": { | ||
Description: "The edge associated with this trunk. Either this or \"edge_group_id\" must be set", | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
"name": { | ||
Description: "The name of the trunk. This property is read only and populated with the auto generated name.", | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} |
Oops, something went wrong.