Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Activity Tracker): Added support for event streams targets in Atracker v2 API #206

Merged
merged 4 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 126 additions & 6 deletions atrackerv2/atracker_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

/*
* IBM OpenAPI SDK Code Generator Version: 3.51.0-5b8b699d-20220613-200818
* IBM OpenAPI SDK Code Generator Version: 3.55.1-b24c7487-20220831-201343
*/

// Package atrackerv2 : Operations and models for the AtrackerV2 service
Expand All @@ -35,7 +35,7 @@ import (
)

// AtrackerV2 : IBM Cloud Activity Tracker allows you to configure how auditing events are collected and stored in each
// region in your account. Events can be sent to Cloud Object Storage bucket or Logdna.
// region in your account. Events can be sent to Cloud Object Storage bucket, Logdna or Event Streams.
//
// API Version: 2.0.0
type AtrackerV2 struct {
Expand Down Expand Up @@ -228,6 +228,9 @@ func (atracker *AtrackerV2) CreateTargetWithContext(ctx context.Context, createT
if createTargetOptions.LogdnaEndpoint != nil {
body["logdna_endpoint"] = createTargetOptions.LogdnaEndpoint
}
if createTargetOptions.EventstreamsEndpoint != nil {
body["eventstreams_endpoint"] = createTargetOptions.EventstreamsEndpoint
}
if createTargetOptions.Region != nil {
body["region"] = createTargetOptions.Region
}
Expand Down Expand Up @@ -423,6 +426,9 @@ func (atracker *AtrackerV2) ReplaceTargetWithContext(ctx context.Context, replac
if replaceTargetOptions.LogdnaEndpoint != nil {
body["logdna_endpoint"] = replaceTargetOptions.LogdnaEndpoint
}
if replaceTargetOptions.EventstreamsEndpoint != nil {
body["eventstreams_endpoint"] = replaceTargetOptions.EventstreamsEndpoint
}
_, err = builder.SetBodyContentJSON(body)
if err != nil {
return
Expand Down Expand Up @@ -1249,8 +1255,8 @@ type CreateTargetOptions struct {
// than `(space) - . _ :`. Do not include any personal identifying information (PII) in any resource names.
Name *string `json:"name" validate:"required"`

// The type of the target. It can be cloud_object_storage or logdna. Based on this type you must include cos_endpoint
// or logdna_endpoint.
// The type of the target. It can be cloud_object_storage, logdna or event_streams. Based on this type you must include
// cos_endpoint, logdna_endpoint or eventstreams_endpoint.
TargetType *string `json:"target_type" validate:"required"`

// Property values for a Cloud Object Storage Endpoint in requests.
Expand All @@ -1259,6 +1265,9 @@ type CreateTargetOptions struct {
// Property values for a LogDNA Endpoint in requests.
LogdnaEndpoint *LogdnaEndpointPrototype `json:"logdna_endpoint,omitempty"`

// Property values for a Event Streams Endpoint in requests.
EventstreamsEndpoint *EventstreamsEndpointPrototype `json:"eventstreams_endpoint,omitempty"`

// Include this optional field if you want to create a target in a different region other than the one you are
// connected.
Region *string `json:"region,omitempty"`
Expand All @@ -1268,10 +1277,11 @@ type CreateTargetOptions struct {
}

// Constants associated with the CreateTargetOptions.TargetType property.
// The type of the target. It can be cloud_object_storage or logdna. Based on this type you must include cos_endpoint or
// logdna_endpoint.
// The type of the target. It can be cloud_object_storage, logdna or event_streams. Based on this type you must include
// cos_endpoint, logdna_endpoint or eventstreams_endpoint.
const (
CreateTargetOptionsTargetTypeCloudObjectStorageConst = "cloud_object_storage"
CreateTargetOptionsTargetTypeEventStreamsConst = "event_streams"
CreateTargetOptionsTargetTypeLogdnaConst = "logdna"
)

Expand Down Expand Up @@ -1307,6 +1317,12 @@ func (_options *CreateTargetOptions) SetLogdnaEndpoint(logdnaEndpoint *LogdnaEnd
return _options
}

// SetEventstreamsEndpoint : Allow user to set EventstreamsEndpoint
func (_options *CreateTargetOptions) SetEventstreamsEndpoint(eventstreamsEndpoint *EventstreamsEndpointPrototype) *CreateTargetOptions {
_options.EventstreamsEndpoint = eventstreamsEndpoint
return _options
}

// SetRegion : Allow user to set Region
func (_options *CreateTargetOptions) SetRegion(region string) *CreateTargetOptions {
_options.Region = core.StringPtr(region)
Expand Down Expand Up @@ -1375,6 +1391,94 @@ func (options *DeleteTargetOptions) SetHeaders(param map[string]string) *DeleteT
return options
}

// EventstreamsEndpoint : Property values for a Event Streams Endpoint in responses.
type EventstreamsEndpoint struct {
// The CRN of the event streams instance.
TargetCRN *string `json:"target_crn" validate:"required"`

// list of broker endpoints.
Brokers []string `json:"brokers" validate:"required"`

// The messsage hub topic defined in the event streams instance.
Topic *string `json:"topic" validate:"required"`

// The messsage hub topic's user password specified in the event streams instance (the apikey).
Password *string `json:"password" validate:"required"`
}

// UnmarshalEventstreamsEndpoint unmarshals an instance of EventstreamsEndpoint from the specified map of raw messages.
func UnmarshalEventstreamsEndpoint(m map[string]json.RawMessage, result interface{}) (err error) {
obj := new(EventstreamsEndpoint)
err = core.UnmarshalPrimitive(m, "target_crn", &obj.TargetCRN)
if err != nil {
return
}
err = core.UnmarshalPrimitive(m, "brokers", &obj.Brokers)
if err != nil {
return
}
err = core.UnmarshalPrimitive(m, "topic", &obj.Topic)
if err != nil {
return
}
err = core.UnmarshalPrimitive(m, "password", &obj.Password)
if err != nil {
return
}
reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj))
return
}

// EventstreamsEndpointPrototype : Property values for a Event Streams Endpoint in requests.
type EventstreamsEndpointPrototype struct {
// The CRN of the event streams instance.
TargetCRN *string `json:"target_crn" validate:"required"`

// list of broker endpoints.
Brokers []string `json:"brokers" validate:"required"`

// The messsage hub topic defined in the event streams instance.
Topic *string `json:"topic" validate:"required"`

// The messsage hub topic's user password specified in the event streams instance (the apikey).
Password *string `json:"password" validate:"required"`
}

// NewEventstreamsEndpointPrototype : Instantiate EventstreamsEndpointPrototype (Generic Model Constructor)
func (*AtrackerV2) NewEventstreamsEndpointPrototype(targetCRN string, brokers []string, topic string, password string) (_model *EventstreamsEndpointPrototype, err error) {
_model = &EventstreamsEndpointPrototype{
TargetCRN: core.StringPtr(targetCRN),
Brokers: brokers,
Topic: core.StringPtr(topic),
Password: core.StringPtr(password),
}
err = core.ValidateStruct(_model, "required parameters")
return
}

// UnmarshalEventstreamsEndpointPrototype unmarshals an instance of EventstreamsEndpointPrototype from the specified map of raw messages.
func UnmarshalEventstreamsEndpointPrototype(m map[string]json.RawMessage, result interface{}) (err error) {
obj := new(EventstreamsEndpointPrototype)
err = core.UnmarshalPrimitive(m, "target_crn", &obj.TargetCRN)
if err != nil {
return
}
err = core.UnmarshalPrimitive(m, "brokers", &obj.Brokers)
if err != nil {
return
}
err = core.UnmarshalPrimitive(m, "topic", &obj.Topic)
if err != nil {
return
}
err = core.UnmarshalPrimitive(m, "password", &obj.Password)
if err != nil {
return
}
reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj))
return
}

// GetMigrationOptions : The GetMigration options.
type GetMigrationOptions struct {

Expand Down Expand Up @@ -1824,6 +1928,9 @@ type ReplaceTargetOptions struct {
// Property values for a LogDNA Endpoint in requests.
LogdnaEndpoint *LogdnaEndpointPrototype `json:"logdna_endpoint,omitempty"`

// Property values for a Event Streams Endpoint in requests.
EventstreamsEndpoint *EventstreamsEndpointPrototype `json:"eventstreams_endpoint,omitempty"`

// Allows users to set headers on API requests
Headers map[string]string
}
Expand Down Expand Up @@ -1859,6 +1966,12 @@ func (_options *ReplaceTargetOptions) SetLogdnaEndpoint(logdnaEndpoint *LogdnaEn
return _options
}

// SetEventstreamsEndpoint : Allow user to set EventstreamsEndpoint
func (_options *ReplaceTargetOptions) SetEventstreamsEndpoint(eventstreamsEndpoint *EventstreamsEndpointPrototype) *ReplaceTargetOptions {
_options.EventstreamsEndpoint = eventstreamsEndpoint
return _options
}

// SetHeaders : Allow user to set Headers
func (options *ReplaceTargetOptions) SetHeaders(param map[string]string) *ReplaceTargetOptions {
options.Headers = param
Expand Down Expand Up @@ -2095,6 +2208,9 @@ type Target struct {
// Property values for a LogDNA Endpoint in responses.
LogdnaEndpoint *LogdnaEndpoint `json:"logdna_endpoint,omitempty"`

// Property values for a Event Streams Endpoint in responses.
EventstreamsEndpoint *EventstreamsEndpoint `json:"eventstreams_endpoint,omitempty"`

// The status of the write attempt to the target with the provided endpoint parameters.
WriteStatus *WriteStatus `json:"write_status" validate:"required"`

Expand Down Expand Up @@ -2149,6 +2265,10 @@ func UnmarshalTarget(m map[string]json.RawMessage, result interface{}) (err erro
if err != nil {
return
}
err = core.UnmarshalModel(m, "eventstreams_endpoint", &obj.EventstreamsEndpoint, UnmarshalEventstreamsEndpoint)
if err != nil {
return
}
err = core.UnmarshalModel(m, "write_status", &obj.WriteStatus, UnmarshalWriteStatus)
if err != nil {
return
Expand Down
58 changes: 58 additions & 0 deletions atrackerv2/atracker_v2_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var _ = Describe(`AtrackerV2 Integration Tests`, func() {
routeIDLink string
targetIDLink string
targetIDLink2 string
targetIDLink3 string
)

var shouldSkipTest = func() {
Expand Down Expand Up @@ -174,6 +175,31 @@ var _ = Describe(`AtrackerV2 Integration Tests`, func() {
fmt.Fprintf(GinkgoWriter, "Saved logdna targetIDLink value: %v\n", targetIDLink)
})

It(`CreateTarget(createTargetOptions *CreateTargetOptions)`, func() {

eventstreamsEndpointPrototypeModel := &atrackerv2.EventstreamsEndpointPrototype{
TargetCRN: core.StringPtr("crn:v1:bluemix:public:messagehub:us-south:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"),
Topic: core.StringPtr("my-test-topic"),
Brokers: []string{"kafka-x:9094"},
Password: core.StringPtr("xxxxxxxxxxx"),
}

createTargetOptions := &atrackerv2.CreateTargetOptions{
Name: core.StringPtr("my-ies-target"),
TargetType: core.StringPtr("event_streams"),
EventstreamsEndpoint: eventstreamsEndpointPrototypeModel,
}

target, response, err := atrackerService.CreateTarget(createTargetOptions)

Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(201))
Expect(target).ToNot(BeNil())

targetIDLink3 = *target.ID
fmt.Fprintf(GinkgoWriter, "Saved event streams targetIDLink value: %v\n", targetIDLink)
})

It(`Returns 400 when backend input validation fails`, func() {
cosEndpointPrototypeModel := &atrackerv2.CosEndpointPrototype{
Endpoint: core.StringPtr("s3.private.us-east.cloud-object-storage.appdomain.cloud"),
Expand Down Expand Up @@ -391,6 +417,28 @@ var _ = Describe(`AtrackerV2 Integration Tests`, func() {
Expect(target).ToNot(BeNil())
})

It(`ReplaceTarget(replaceTargetOptions *ReplaceTargetOptions) for event streams type of target`, func() {

eventstreamsEndpointPrototypeModel := &atrackerv2.EventstreamsEndpointPrototype{
TargetCRN: core.StringPtr("crn:v1:bluemix:public:messagehub:us-south:a/11111111111111111111111111111111:22222222-2222-2222-2222-222222222222::"),
Topic: core.StringPtr("my-test-topic"),
Brokers: []string{"kafka-x:9094"},
Password: core.StringPtr("xxxxxxxxxxxxx"),
}

replaceTargetOptions := &atrackerv2.ReplaceTargetOptions{
ID: &targetIDLink3,
Name: core.StringPtr("my-ies-target-modified"),
EventstreamsEndpoint: eventstreamsEndpointPrototypeModel,
}

target, response, err := atrackerService.ReplaceTarget(replaceTargetOptions)
Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(200))
Expect(target).ToNot(BeNil())
})


It(`Returns 404 when target id is not found`, func() {

cosEndpointPrototypeModel := &atrackerv2.CosEndpointPrototype{
Expand Down Expand Up @@ -801,6 +849,16 @@ var _ = Describe(`AtrackerV2 Integration Tests`, func() {
ID: &targetIDLink2,
}

_, response, err := atrackerService.DeleteTarget(deleteTargetOptions)
Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(200))
})
It(`DeleteTarget(deleteTargetOptions *DeleteTargetOptions)`, func() {

deleteTargetOptions := &atrackerv2.DeleteTargetOptions{
ID: &targetIDLink3,
}

_, response, err := atrackerService.DeleteTarget(deleteTargetOptions)
Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(200))
Expand Down
Loading