Skip to content

Commit

Permalink
fix(Activity Tracker v2): add message field Settings struct (#226)
Browse files Browse the repository at this point in the history
* a message field added to settings struct

* updated a test
  • Loading branch information
johnymathew committed Dec 19, 2022
1 parent fc273ba commit ccf59a3
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 96 deletions.
99 changes: 53 additions & 46 deletions atrackerv2/atracker_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,28 @@ func NewAtrackerV2(options *AtrackerV2Options) (service *AtrackerV2, err error)
// GetServiceURLForRegion returns the service URL to be used for the specified region
func GetServiceURLForRegion(region string) (string, error) {
var endpoints = map[string]string{
"us-south": "https://us-south.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the us-south region.
"us-south": "https://us-south.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the us-south region.
"private.us-south": "https://private.us-south.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the us-south region.
"us-east": "https://us-east.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the us-east region.
"private.us-east": "https://private.us-east.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the us-east region.
"eu-de": "https://eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the eu-de region.
"private.eu-de": "https://private.eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the eu-de region.
"eu-gb": "https://eu-gb.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the eu-gb region.
"private.eu-gb": "https://private.eu-gb.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the eu-gb region.
"au-syd": "https://au-syd.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the au-syd region.
"private.au-syd": "https://private.au-syd.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the au-syd region.
"ca-tor": "https://us-east.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for ca-tor points to the us-east region.
"private.ca-tor": "https://private.us-east.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for ca-tor points to the us-east region.
"br-sao": "https://us-south.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for br-sao points to the us-south region.
"private.br-sao": "https://private.us-south.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for br-sao points to the us-south region.
"eu-fr2": "https://eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for eu-fr2 points to the eu-de region.
"private.eu-fr2": "https://private.eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for eu-fr2 points to the eu-de region.
"jp-tok": "https://eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for jp-tok points to the eu-de region.
"private.jp-tok": "https://private.eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for jp-tok points to the eu-de region.
"jp-osa": "https://eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for jp-osa points to the eu-de region.
"private.jp-osa": "https://private.eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for jp-osa points to the eu-de region.
"in-che": "https://eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for in-che points to the eu-de region.
"private.in-che": "https://private.eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for in-che points to the eu-de region.
"us-east": "https://us-east.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the us-east region.
"private.us-east": "https://private.us-east.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the us-east region.
"eu-de": "https://eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the eu-de region.
"private.eu-de": "https://private.eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the eu-de region.
"eu-gb": "https://eu-gb.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the eu-gb region.
"private.eu-gb": "https://private.eu-gb.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the eu-gb region.
"au-syd": "https://au-syd.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the au-syd region.
"private.au-syd": "https://private.au-syd.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service in the au-syd region.
"ca-tor": "https://us-east.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for ca-tor points to the us-east region.
"private.ca-tor": "https://private.us-east.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for ca-tor points to the us-east region.
"br-sao": "https://us-south.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for br-sao points to the us-south region.
"private.br-sao": "https://private.us-south.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for br-sao points to the us-south region.
"eu-fr2": "https://eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for eu-fr2 points to the eu-de region.
"private.eu-fr2": "https://private.eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for eu-fr2 points to the eu-de region.
"jp-tok": "https://eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for jp-tok points to the eu-de region.
"private.jp-tok": "https://private.eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for jp-tok points to the eu-de region.
"jp-osa": "https://eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for jp-osa points to the eu-de region.
"private.jp-osa": "https://private.eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for jp-osa points to the eu-de region.
"in-che": "https://eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for in-che points to the eu-de region.
"private.in-che": "https://private.eu-de.atracker.cloud.ibm.com", // The server for IBM Cloud Activity Tracker Service for in-che points to the eu-de region.
}

if url, ok := endpoints[region]; ok {
Expand Down Expand Up @@ -1187,9 +1187,9 @@ type CosEndpointPrototype struct {
// NewCosEndpointPrototype : Instantiate CosEndpointPrototype (Generic Model Constructor)
func (*AtrackerV2) NewCosEndpointPrototype(endpoint string, targetCRN string, bucket string) (_model *CosEndpointPrototype, err error) {
_model = &CosEndpointPrototype{
Endpoint: core.StringPtr(endpoint),
Endpoint: core.StringPtr(endpoint),
TargetCRN: core.StringPtr(targetCRN),
Bucket: core.StringPtr(bucket),
Bucket: core.StringPtr(bucket),
}
err = core.ValidateStruct(_model, "required parameters")
return
Expand Down Expand Up @@ -1238,7 +1238,7 @@ type CreateRouteOptions struct {
// NewCreateRouteOptions : Instantiate CreateRouteOptions
func (*AtrackerV2) NewCreateRouteOptions(name string, rules []RulePrototype) *CreateRouteOptions {
return &CreateRouteOptions{
Name: core.StringPtr(name),
Name: core.StringPtr(name),
Rules: rules,
}
}
Expand Down Expand Up @@ -1293,14 +1293,14 @@ type CreateTargetOptions struct {
// cos_endpoint, logdna_endpoint or eventstreams_endpoint.
const (
CreateTargetOptionsTargetTypeCloudObjectStorageConst = "cloud_object_storage"
CreateTargetOptionsTargetTypeEventStreamsConst = "event_streams"
CreateTargetOptionsTargetTypeLogdnaConst = "logdna"
CreateTargetOptionsTargetTypeEventStreamsConst = "event_streams"
CreateTargetOptionsTargetTypeLogdnaConst = "logdna"
)

// NewCreateTargetOptions : Instantiate CreateTargetOptions
func (*AtrackerV2) NewCreateTargetOptions(name string, targetType string) *CreateTargetOptions {
return &CreateTargetOptions{
Name: core.StringPtr(name),
Name: core.StringPtr(name),
TargetType: core.StringPtr(targetType),
}
}
Expand Down Expand Up @@ -1460,9 +1460,9 @@ type EventstreamsEndpointPrototype struct {
func (*AtrackerV2) NewEventstreamsEndpointPrototype(targetCRN string, brokers []string, topic string, apiKey string) (_model *EventstreamsEndpointPrototype, err error) {
_model = &EventstreamsEndpointPrototype{
TargetCRN: core.StringPtr(targetCRN),
Brokers: brokers,
Topic: core.StringPtr(topic),
APIKey: core.StringPtr(apiKey),
Brokers: brokers,
Topic: core.StringPtr(topic),
APIKey: core.StringPtr(apiKey),
}
err = core.ValidateStruct(_model, "required parameters")
return
Expand Down Expand Up @@ -1656,7 +1656,7 @@ type LogdnaEndpointPrototype struct {
// NewLogdnaEndpointPrototype : Instantiate LogdnaEndpointPrototype (Generic Model Constructor)
func (*AtrackerV2) NewLogdnaEndpointPrototype(targetCRN string, ingestionKey string) (_model *LogdnaEndpointPrototype, err error) {
_model = &LogdnaEndpointPrototype{
TargetCRN: core.StringPtr(targetCRN),
TargetCRN: core.StringPtr(targetCRN),
IngestionKey: core.StringPtr(ingestionKey),
}
err = core.ValidateStruct(_model, "required parameters")
Expand Down Expand Up @@ -1693,13 +1693,13 @@ type Migration struct {
// Constants associated with the Migration.Status property.
// The overall status of the migration.
const (
MigrationStatusCanceledConst = "canceled"
MigrationStatusCompletedConst = "completed"
MigrationStatusFailedConst = "failed"
MigrationStatusInProgressConst = "in_progress"
MigrationStatusCanceledConst = "canceled"
MigrationStatusCompletedConst = "completed"
MigrationStatusFailedConst = "failed"
MigrationStatusInProgressConst = "in_progress"
MigrationStatusNotRequiredConst = "not_required"
MigrationStatusNotStartedConst = "not_started"
MigrationStatusPendingConst = "pending"
MigrationStatusNotStartedConst = "not_started"
MigrationStatusPendingConst = "pending"
)

// UnmarshalMigration unmarshals an instance of Migration from the specified map of raw messages.
Expand Down Expand Up @@ -1747,18 +1747,18 @@ type MigrationItem struct {
// The type of the resource being migrated.
const (
MigrationItemResourceTypePrivateEndpointConst = "private_endpoint"
MigrationItemResourceTypeRouteConst = "route"
MigrationItemResourceTypeTargetConst = "target"
MigrationItemResourceTypeRouteConst = "route"
MigrationItemResourceTypeTargetConst = "target"
)

// Constants associated with the MigrationItem.Status property.
// The status of the migration for this resource.
const (
MigrationItemStatusCompletedConst = "completed"
MigrationItemStatusFailedConst = "failed"
MigrationItemStatusCompletedConst = "completed"
MigrationItemStatusFailedConst = "failed"
MigrationItemStatusInProgressConst = "in_progress"
MigrationItemStatusNotStartedConst = "not_started"
MigrationItemStatusPendingConst = "pending"
MigrationItemStatusPendingConst = "pending"
)

// UnmarshalMigrationItem unmarshals an instance of MigrationItem from the specified map of raw messages.
Expand Down Expand Up @@ -1835,7 +1835,7 @@ type PutSettingsOptions struct {
// NewPutSettingsOptions : Instantiate PutSettingsOptions
func (*AtrackerV2) NewPutSettingsOptions(metadataRegionPrimary string, privateAPIEndpointOnly bool) *PutSettingsOptions {
return &PutSettingsOptions{
MetadataRegionPrimary: core.StringPtr(metadataRegionPrimary),
MetadataRegionPrimary: core.StringPtr(metadataRegionPrimary),
PrivateAPIEndpointOnly: core.BoolPtr(privateAPIEndpointOnly),
}
}
Expand Down Expand Up @@ -1895,8 +1895,8 @@ type ReplaceRouteOptions struct {
// NewReplaceRouteOptions : Instantiate ReplaceRouteOptions
func (*AtrackerV2) NewReplaceRouteOptions(id string, name string, rules []RulePrototype) *ReplaceRouteOptions {
return &ReplaceRouteOptions{
ID: core.StringPtr(id),
Name: core.StringPtr(name),
ID: core.StringPtr(id),
Name: core.StringPtr(name),
Rules: rules,
}
}
Expand Down Expand Up @@ -2163,6 +2163,9 @@ type Settings struct {

// The lowest API version of targets or routes that customer might have under his or her account.
APIVersion *int64 `json:"api_version" validate:"required"`

// An optional message containing information about the audit log locations.
Message *string `json:"message,omitempty"`
}

// UnmarshalSettings unmarshals an instance of Settings from the specified map of raw messages.
Expand Down Expand Up @@ -2192,6 +2195,10 @@ func UnmarshalSettings(m map[string]json.RawMessage, result interface{}) (err er
if err != nil {
return
}
err = core.UnmarshalPrimitive(m, "message", &obj.Message)
if err != nil {
return
}
reflect.ValueOf(result).Elem().Set(reflect.ValueOf(obj))
return
}
Expand Down Expand Up @@ -2243,7 +2250,7 @@ type Target struct {
// The type of the target.
const (
TargetTargetTypeCloudObjectStorageConst = "cloud_object_storage"
TargetTargetTypeLogdnaConst = "logdna"
TargetTargetTypeLogdnaConst = "logdna"
)

// UnmarshalTarget unmarshals an instance of Target from the specified map of raw messages.
Expand Down
48 changes: 24 additions & 24 deletions atrackerv2/atracker_v2_examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
. "github.com/onsi/gomega"
)

//
// This file provides an example of how to use the atracker service.
//
// The following configuration properties are assumed to be defined:
Expand All @@ -42,7 +41,6 @@ import (
// These configuration properties can be exported as environment variables, or stored
// in a configuration file and then:
// export IBM_CREDENTIALS_FILE=<name of configuration file>
//
var _ = Describe(`AtrackerV2 Examples Tests`, func() {

const externalConfigFile = "../atracker_v2.env"
Expand Down Expand Up @@ -145,7 +143,8 @@ var _ = Describe(`AtrackerV2 Examples Tests`, func() {
// begin-create_route

rulePrototypeModel := &atrackerv2.RulePrototype{
TargetIds: []string{"c3af557f-fb0e-4476-85c3-0889e7fe7bc4"},
TargetIds: []string{targetIDLink},
Locations: []string{"us-south"},
}

createRouteOptions := atrackerService.NewCreateRouteOptions(
Expand Down Expand Up @@ -303,7 +302,8 @@ var _ = Describe(`AtrackerV2 Examples Tests`, func() {
// begin-replace_route

rulePrototypeModel := &atrackerv2.RulePrototype{
TargetIds: []string{"c3af557f-fb0e-4476-85c3-0889e7fe7bc4"},
TargetIds: []string{targetIDLink},
Locations: []string{"us-south"},
}

replaceRouteOptions := atrackerService.NewReplaceRouteOptions(
Expand Down Expand Up @@ -409,47 +409,47 @@ var _ = Describe(`AtrackerV2 Examples Tests`, func() {
Expect(migration).ToNot(BeNil())

})
It(`DeleteTarget request example`, func() {
fmt.Println("\nDeleteTarget() result:")
// begin-delete_target
It(`DeleteRoute request example`, func() {
// begin-delete_route

deleteTargetOptions := atrackerService.NewDeleteTargetOptions(
targetIDLink,
deleteRouteOptions := atrackerService.NewDeleteRouteOptions(
routeIDLink,
)

warningReport, response, err := atrackerService.DeleteTarget(deleteTargetOptions)
response, err := atrackerService.DeleteRoute(deleteRouteOptions)
if err != nil {
panic(err)
}
b, _ := json.MarshalIndent(warningReport, "", " ")
fmt.Println(string(b))
if response.StatusCode != 204 {
fmt.Printf("\nUnexpected response status code received from DeleteRoute(): %d\n", response.StatusCode)
}

// end-delete_target
// end-delete_route

Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(200))
Expect(warningReport).ToNot(BeNil())
Expect(response.StatusCode).To(Equal(204))

})
It(`DeleteRoute request example`, func() {
// begin-delete_route
It(`DeleteTarget request example`, func() {
fmt.Println("\nDeleteTarget() result:")
// begin-delete_target

deleteRouteOptions := atrackerService.NewDeleteRouteOptions(
routeIDLink,
deleteTargetOptions := atrackerService.NewDeleteTargetOptions(
targetIDLink,
)

response, err := atrackerService.DeleteRoute(deleteRouteOptions)
warningReport, response, err := atrackerService.DeleteTarget(deleteTargetOptions)
if err != nil {
panic(err)
}
if response.StatusCode != 204 {
fmt.Printf("\nUnexpected response status code received from DeleteRoute(): %d\n", response.StatusCode)
}
b, _ := json.MarshalIndent(warningReport, "", " ")
fmt.Println(string(b))

// end-delete_route
// end-delete_target

Expect(err).To(BeNil())
Expect(response.StatusCode).To(Equal(204))
Expect(warningReport).To(BeNil())

})
})
Expand Down
25 changes: 12 additions & 13 deletions atrackerv2/atracker_v2_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var _ = Describe(`AtrackerV2 Integration Tests`, func() {

const notFoundTargetID = "ffffffff-1111-1111-1111-111111111111"

const notFoundRouteID = "ffffffff-2222-2222-2222-222222222222"
const notFoundRouteID = "ffffffff-2222-2222-2222-222222222222"

const badTargetType = "bad_target_type"

Expand Down Expand Up @@ -179,14 +179,14 @@ var _ = Describe(`AtrackerV2 Integration Tests`, 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"},
APIKey: core.StringPtr("xxxxxxxxxxx"),
Topic: core.StringPtr("my-test-topic"),
Brokers: []string{"kafka-x:9094"},
APIKey: core.StringPtr("xxxxxxxxxxx"),
}

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

Expand Down Expand Up @@ -421,14 +421,14 @@ var _ = Describe(`AtrackerV2 Integration Tests`, 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"},
APIKey: core.StringPtr("xxxxxxxxxxxxx"),
Topic: core.StringPtr("my-test-topic"),
Brokers: []string{"kafka-x:9094"},
APIKey: core.StringPtr("xxxxxxxxxxxxx"),
}

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

Expand All @@ -438,7 +438,6 @@ var _ = Describe(`AtrackerV2 Integration Tests`, func() {
Expect(target).ToNot(BeNil())
})


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

cosEndpointPrototypeModel := &atrackerv2.CosEndpointPrototype{
Expand Down Expand Up @@ -851,7 +850,7 @@ var _ = Describe(`AtrackerV2 Integration Tests`, func() {

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

Expand Down

0 comments on commit ccf59a3

Please sign in to comment.