Skip to content

Commit

Permalink
split service for pipeline kinds
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpitman committed Sep 5, 2024
1 parent 6d2b6b0 commit 419294a
Show file tree
Hide file tree
Showing 7 changed files with 311 additions and 15 deletions.
70 changes: 70 additions & 0 deletions dynatrace/api/openpipeline/business_events_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package openpipeline

import (
"context"
"encoding/json"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api"
openpipeline "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/openpipeline/settings"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/rest"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/settings"
"github.com/dynatrace/dynatrace-configuration-as-code-core/clients"
caclib "github.com/dynatrace/dynatrace-configuration-as-code-core/clients/openpipeline"
"golang.org/x/oauth2/clientcredentials"
)

func BusinessEventsService(credentials *settings.Credentials) settings.CRUDService[*openpipeline.Configuration] {
return &businessEventsService{credentials}
}

type businessEventsService struct {
credentials *settings.Credentials
}

func (s *businessEventsService) client() *caclib.Client {
factory := clients.Factory().
WithUserAgent("Dynatrace Terraform Provider").
WithPlatformURL(s.credentials.Automation.EnvironmentURL).
WithOAuthCredentials(clientcredentials.Config{
ClientID: s.credentials.Automation.ClientID,
ClientSecret: s.credentials.Automation.ClientSecret,
TokenURL: s.credentials.Automation.TokenURL,
})

openPipelineClient, _ := factory.OpenPipelineClient()
return openPipelineClient

}

func (s businessEventsService) List(ctx context.Context) (api.Stubs, error) {
//TODO implement me
return api.Stubs{}, nil
}

func (s businessEventsService) Get(ctx context.Context, id string, v *openpipeline.Configuration) error {
response, err := s.client().Get(ctx, id)
if err != nil {
return err
}

if !response.IsSuccess() {
return rest.Envelope(response.Data, s.credentials.Automation.EnvironmentURL, "GET")
}

return json.Unmarshal(response.Data, &v)
}

func (s businessEventsService) SchemaID() string {
return "platform:openpipeline.events.business"
}

func (s businessEventsService) Create(_ context.Context, v *openpipeline.Configuration) (*api.Stub, error) {
return &api.Stub{ID: v.Kind}, nil
}

func (s businessEventsService) Update(_ context.Context, id string, v *openpipeline.Configuration) error {
return nil
}

func (s businessEventsService) Delete(_ context.Context, id string) error {
return nil
}
70 changes: 70 additions & 0 deletions dynatrace/api/openpipeline/events_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package openpipeline

import (
"context"
"encoding/json"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api"
openpipeline "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/openpipeline/settings"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/rest"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/settings"
"github.com/dynatrace/dynatrace-configuration-as-code-core/clients"
caclib "github.com/dynatrace/dynatrace-configuration-as-code-core/clients/openpipeline"
"golang.org/x/oauth2/clientcredentials"
)

func EventsService(credentials *settings.Credentials) settings.CRUDService[*openpipeline.Configuration] {
return &eventsService{credentials}
}

type eventsService struct {
credentials *settings.Credentials
}

func (s *eventsService) client() *caclib.Client {
factory := clients.Factory().
WithUserAgent("Dynatrace Terraform Provider").
WithPlatformURL(s.credentials.Automation.EnvironmentURL).
WithOAuthCredentials(clientcredentials.Config{
ClientID: s.credentials.Automation.ClientID,
ClientSecret: s.credentials.Automation.ClientSecret,
TokenURL: s.credentials.Automation.TokenURL,
})

openPipelineClient, _ := factory.OpenPipelineClient()
return openPipelineClient

}

func (s eventsService) List(ctx context.Context) (api.Stubs, error) {
//TODO implement me
return api.Stubs{}, nil
}

func (s eventsService) Get(ctx context.Context, id string, v *openpipeline.Configuration) error {
response, err := s.client().Get(ctx, id)
if err != nil {
return err
}

if !response.IsSuccess() {
return rest.Envelope(response.Data, s.credentials.Automation.EnvironmentURL, "GET")
}

return json.Unmarshal(response.Data, &v)
}

func (s eventsService) SchemaID() string {
return "platform:openpipeline.events"
}

func (s eventsService) Create(_ context.Context, v *openpipeline.Configuration) (*api.Stub, error) {
return &api.Stub{ID: v.Kind}, nil
}

func (s eventsService) Update(_ context.Context, id string, v *openpipeline.Configuration) error {
return nil
}

func (s eventsService) Delete(_ context.Context, id string) error {
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (
"golang.org/x/oauth2/clientcredentials"
)

func Service(credentials *settings.Credentials) settings.CRUDService[*openpipeline.Configuration] {
return &service{credentials}
func LogsService(credentials *settings.Credentials) settings.CRUDService[*openpipeline.Configuration] {
return &logsService{credentials}
}

type service struct {
type logsService struct {
credentials *settings.Credentials
}

func (s *service) client() *caclib.Client {
func (s *logsService) client() *caclib.Client {
factory := clients.Factory().
WithUserAgent("Dynatrace Terraform Provider").
WithPlatformURL(s.credentials.Automation.EnvironmentURL).
Expand All @@ -35,12 +35,12 @@ func (s *service) client() *caclib.Client {

}

func (s service) List(ctx context.Context) (api.Stubs, error) {
func (s logsService) List(ctx context.Context) (api.Stubs, error) {
//TODO implement me
return api.Stubs{}, nil
}

func (s service) Get(ctx context.Context, id string, v *openpipeline.Configuration) error {
func (s logsService) Get(ctx context.Context, id string, v *openpipeline.Configuration) error {
response, err := s.client().Get(ctx, id)
if err != nil {
return err
Expand All @@ -53,18 +53,18 @@ func (s service) Get(ctx context.Context, id string, v *openpipeline.Configurati
return json.Unmarshal(response.Data, &v)
}

func (s service) SchemaID() string {
return "platform:openpipeline"
func (s logsService) SchemaID() string {
return "platform:openpipeline.logs"
}

func (s service) Create(_ context.Context, v *openpipeline.Configuration) (*api.Stub, error) {
func (s logsService) Create(_ context.Context, v *openpipeline.Configuration) (*api.Stub, error) {
return &api.Stub{ID: v.Kind}, nil
}

func (s service) Update(_ context.Context, id string, v *openpipeline.Configuration) error {
func (s logsService) Update(_ context.Context, id string, v *openpipeline.Configuration) error {
return nil
}

func (s service) Delete(_ context.Context, id string) error {
func (s logsService) Delete(_ context.Context, id string) error {
return nil
}
70 changes: 70 additions & 0 deletions dynatrace/api/openpipeline/sdlc_events_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package openpipeline

import (
"context"
"encoding/json"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api"
openpipeline "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/openpipeline/settings"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/rest"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/settings"
"github.com/dynatrace/dynatrace-configuration-as-code-core/clients"
caclib "github.com/dynatrace/dynatrace-configuration-as-code-core/clients/openpipeline"
"golang.org/x/oauth2/clientcredentials"
)

func SDLCEventsService(credentials *settings.Credentials) settings.CRUDService[*openpipeline.Configuration] {
return &sdlcEventsService{credentials}
}

type sdlcEventsService struct {
credentials *settings.Credentials
}

func (s *sdlcEventsService) client() *caclib.Client {
factory := clients.Factory().
WithUserAgent("Dynatrace Terraform Provider").
WithPlatformURL(s.credentials.Automation.EnvironmentURL).
WithOAuthCredentials(clientcredentials.Config{
ClientID: s.credentials.Automation.ClientID,
ClientSecret: s.credentials.Automation.ClientSecret,
TokenURL: s.credentials.Automation.TokenURL,
})

openPipelineClient, _ := factory.OpenPipelineClient()
return openPipelineClient

}

func (s sdlcEventsService) List(ctx context.Context) (api.Stubs, error) {
//TODO implement me
return api.Stubs{}, nil
}

func (s sdlcEventsService) Get(ctx context.Context, id string, v *openpipeline.Configuration) error {
response, err := s.client().Get(ctx, id)
if err != nil {
return err
}

if !response.IsSuccess() {
return rest.Envelope(response.Data, s.credentials.Automation.EnvironmentURL, "GET")
}

return json.Unmarshal(response.Data, &v)
}

func (s sdlcEventsService) SchemaID() string {
return "platform:openpipeline.events.sdlc"
}

func (s sdlcEventsService) Create(_ context.Context, v *openpipeline.Configuration) (*api.Stub, error) {
return &api.Stub{ID: v.Kind}, nil
}

func (s sdlcEventsService) Update(_ context.Context, id string, v *openpipeline.Configuration) error {
return nil
}

func (s sdlcEventsService) Delete(_ context.Context, id string) error {
return nil
}
70 changes: 70 additions & 0 deletions dynatrace/api/openpipeline/security_events_service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package openpipeline

import (
"context"
"encoding/json"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api"
openpipeline "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/openpipeline/settings"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/rest"
"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/settings"
"github.com/dynatrace/dynatrace-configuration-as-code-core/clients"
caclib "github.com/dynatrace/dynatrace-configuration-as-code-core/clients/openpipeline"
"golang.org/x/oauth2/clientcredentials"
)

func SecurityEventsService(credentials *settings.Credentials) settings.CRUDService[*openpipeline.Configuration] {
return &securityEventsService{credentials}
}

type securityEventsService struct {
credentials *settings.Credentials
}

func (s *securityEventsService) client() *caclib.Client {
factory := clients.Factory().
WithUserAgent("Dynatrace Terraform Provider").
WithPlatformURL(s.credentials.Automation.EnvironmentURL).
WithOAuthCredentials(clientcredentials.Config{
ClientID: s.credentials.Automation.ClientID,
ClientSecret: s.credentials.Automation.ClientSecret,
TokenURL: s.credentials.Automation.TokenURL,
})

openPipelineClient, _ := factory.OpenPipelineClient()
return openPipelineClient

}

func (s securityEventsService) List(ctx context.Context) (api.Stubs, error) {
//TODO implement me
return api.Stubs{}, nil
}

func (s securityEventsService) Get(ctx context.Context, id string, v *openpipeline.Configuration) error {
response, err := s.client().Get(ctx, id)
if err != nil {
return err
}

if !response.IsSuccess() {
return rest.Envelope(response.Data, s.credentials.Automation.EnvironmentURL, "GET")
}

return json.Unmarshal(response.Data, &v)
}

func (s securityEventsService) SchemaID() string {
return "platform:openpipeline.events.security"
}

func (s securityEventsService) Create(_ context.Context, v *openpipeline.Configuration) (*api.Stub, error) {
return &api.Stub{ID: v.Kind}, nil
}

func (s securityEventsService) Update(_ context.Context, id string, v *openpipeline.Configuration) error {
return nil
}

func (s securityEventsService) Delete(_ context.Context, id string) error {
return nil
}
12 changes: 10 additions & 2 deletions dynatrace/export/enums.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,11 @@ var ResourceTypes = struct {
InfraOpsAppSettings ResourceType
DiskEdgeAnomalyDetectors ResourceType
Reports ResourceType
OpenPipeline ResourceType
OpenPipelineLogs ResourceType
OpenPipelineEvents ResourceType
OpenPipelineSecurityEvents ResourceType
OpenPipelineBusinessEvents ResourceType
OpenPipelineSDLCEvents ResourceType
}{
"dynatrace_autotag",
"dynatrace_autotag_v2",
Expand Down Expand Up @@ -744,7 +748,11 @@ var ResourceTypes = struct {
"dynatrace_infraops_app_settings",
"dynatrace_disk_edge_anomaly_detectors",
"dynatrace_report",
"dynatrace_openpipeline",
"dynatrace_openpipeline_logs",
"dynatrace_openpipeline_events",
"dynatrace_openpipeline_security_events",
"dynatrace_openpipeline_business_events",
"dynatrace_openpipeline_sdlc_events",
}

func (me ResourceType) GetFolderName(override string) string {
Expand Down
12 changes: 10 additions & 2 deletions dynatrace/export/resource_descriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,16 @@ var AllResources = map[ResourceType]ResourceDescriptor{
ResourceTypes.DirectShares: NewResourceDescriptor(
directshares.Service,
),
ResourceTypes.OpenPipeline: NewResourceDescriptor(
openpipeline.Service),
ResourceTypes.OpenPipelineLogs: NewResourceDescriptor(
openpipeline.LogsService),
ResourceTypes.OpenPipelineEvents: NewResourceDescriptor(
openpipeline.EventsService),
ResourceTypes.OpenPipelineSecurityEvents: NewResourceDescriptor(
openpipeline.SecurityEventsService),
ResourceTypes.OpenPipelineBusinessEvents: NewResourceDescriptor(
openpipeline.BusinessEventsService),
ResourceTypes.OpenPipelineSDLCEvents: NewResourceDescriptor(
openpipeline.SDLCEventsService),
ResourceTypes.JSONDashboard: NewChildResourceDescriptor(
jsondashboards.Service,
ResourceTypes.JSONDashboardBase,
Expand Down

0 comments on commit 419294a

Please sign in to comment.