Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
28 changes: 28 additions & 0 deletions pkg/cloud/cloud_api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

155 changes: 155 additions & 0 deletions pkg/cloud/cloud_api_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,158 @@ func TestCloudAccount_AzureMonitorIntegration(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, unlinkResponse)
}

func TestCloudAccount_OciLinkAccount(t *testing.T) {
t.Parallel()
client := newIntegrationTestClient(t)

testAccountID, err := mock.GetTestAccountID()
if err != nil {
t.Skipf("%s", err)
}

// Check for required environment variables
ociCredentials := map[string]string{
"INTEGRATION_TESTING_OCI_TENANT_ID": os.Getenv("INTEGRATION_TESTING_OCI_TENANT_ID"),
"INTEGRATION_TESTING_OCI_COMPARTMENT_OCID": os.Getenv("INTEGRATION_TESTING_OCI_COMPARTMENT_OCID"),
"INTEGRATION_TESTING_OCI_CLIENT_ID": os.Getenv("INTEGRATION_TESTING_OCI_CLIENT_ID"),
"INTEGRATION_TESTING_OCI_CLIENT_SECRET": os.Getenv("INTEGRATION_TESTING_OCI_CLIENT_SECRET"),
"INTEGRATION_TESTING_OCI_DOMAIN_URL": os.Getenv("INTEGRATION_TESTING_OCI_DOMAIN_URL"),
"INTEGRATION_TESTING_OCI_HOME_REGION": os.Getenv("INTEGRATION_TESTING_OCI_HOME_REGION"),
"INTEGRATION_TESTING_OCI_SVC_USER_NAME": os.Getenv("INTEGRATION_TESTING_OCI_SVC_USER_NAME"),
"INTEGRATION_TESTING_OCI_INGEST_VAULT_OCID": os.Getenv("INTEGRATION_TESTING_OCI_INGEST_VAULT_OCID"),
"INTEGRATION_TESTING_OCI_USER_VAULT_OCID": os.Getenv("INTEGRATION_TESTING_OCI_USER_VAULT_OCID"),
}

var credentialsNotFound []string

for key, value := range ociCredentials {
if value == "" {
credentialsNotFound = append(credentialsNotFound, key)
}
}

if len(credentialsNotFound) != 0 {
t.Skipf("Skipping this test, as the following required OCI credentials do not exist in the environment: \n%s", strings.Join(credentialsNotFound[:], ", "))
}

// Clean up any existing OCI linked accounts
getResponse, err := client.GetLinkedAccounts("oci")
require.NoError(t, err)

for _, linkedAccount := range *getResponse {
if linkedAccount.NrAccountId == testAccountID {
_, unlinkErr := client.CloudUnlinkAccount(testAccountID, []CloudUnlinkAccountsInput{
{
LinkedAccountId: linkedAccount.ID,
},
})
require.NoError(t, unlinkErr)
}
}

// Prepare the link account input
linkInput := CloudOciLinkAccountInput{
Name: "Go SDK Integration Test OCI Account",
TenantId: ociCredentials["INTEGRATION_TESTING_OCI_TENANT_ID"],
CompartmentOcid: ociCredentials["INTEGRATION_TESTING_OCI_COMPARTMENT_OCID"],
OciClientId: ociCredentials["INTEGRATION_TESTING_OCI_CLIENT_ID"],
OciClientSecret: SecureValue(ociCredentials["INTEGRATION_TESTING_OCI_CLIENT_SECRET"]),
OciDomainURL: ociCredentials["INTEGRATION_TESTING_OCI_DOMAIN_URL"],
OciHomeRegion: ociCredentials["INTEGRATION_TESTING_OCI_HOME_REGION"],
OciSvcUserName: ociCredentials["INTEGRATION_TESTING_OCI_SVC_USER_NAME"],
IngestVaultOcid: ociCredentials["INTEGRATION_TESTING_OCI_INGEST_VAULT_OCID"],
UserVaultOcid: ociCredentials["INTEGRATION_TESTING_OCI_USER_VAULT_OCID"],
InstrumentationType: "METRICS", // Default for testing
}

// Link the OCI account
linkResponse, err := client.CloudLinkAccount(testAccountID, CloudLinkCloudAccountsInput{
Oci: []CloudOciLinkAccountInput{linkInput},
})
require.NoError(t, err)
require.NotNil(t, linkResponse)
require.Len(t, linkResponse.Errors, 0)
require.Greater(t, len(linkResponse.LinkedAccounts), 0)

// Get the linked account ID
linkedAccountID := linkResponse.LinkedAccounts[0].ID

// Verify the linked account exists
linkedAccount, err := client.GetLinkedAccount(testAccountID, linkedAccountID)
require.NoError(t, err)
require.NotNil(t, linkedAccount)
require.Equal(t, testAccountID, linkedAccount.NrAccountId)

// Optional fields - retrieve if available
testOciRegion := os.Getenv("INTEGRATION_TESTING_OCI_REGION")
testOciMetricStackOcid := os.Getenv("INTEGRATION_TESTING_OCI_METRIC_STACK_OCID")
testOciLoggingStackOcid := os.Getenv("INTEGRATION_TESTING_OCI_LOGGING_STACK_OCID")

// Test updating the account with optional fields if available
updateInput := CloudOciUpdateAccountInput{
LinkedAccountId: linkedAccountID,
Name: "Updated OCI Integration Test Account",
}

// Add optional fields if they were provided in environment variables
if testOciRegion != "" {
updateInput.OciRegion = testOciRegion
}
if testOciMetricStackOcid != "" {
updateInput.MetricStackOcid = testOciMetricStackOcid
}
if testOciLoggingStackOcid != "" {
updateInput.LoggingStackOcid = testOciLoggingStackOcid
}

updateResponse, err := client.CloudUpdateAccount(testAccountID, CloudUpdateCloudAccountsInput{
Oci: []CloudOciUpdateAccountInput{updateInput},
})
require.NoError(t, err)
require.NotNil(t, updateResponse)

// Verify the name was updated
updatedAccount, err := client.GetLinkedAccount(testAccountID, linkedAccountID)
require.NoError(t, err)
require.Equal(t, "Updated OCI Integration Test Account", updatedAccount.Name)

// Test OCI metadata and tags integration
integrationResponse, err := client.CloudConfigureIntegration(testAccountID, CloudIntegrationsInput{
Oci: CloudOciIntegrationsInput{
OciMetadataAndTags: []CloudOciMetadataAndTagsIntegrationInput{
{
LinkedAccountId: linkedAccountID,
},
},
},
})
require.NoError(t, err)
require.NotNil(t, integrationResponse)
require.Len(t, integrationResponse.Errors, 0)
require.Greater(t, len(integrationResponse.Integrations), 0)

// Disable the integration
disableResponse, err := client.CloudDisableIntegration(testAccountID, CloudDisableIntegrationsInput{
Oci: CloudOciDisableIntegrationsInput{
OciMetadataAndTags: []CloudDisableAccountIntegrationInput{
{
LinkedAccountId: linkedAccountID,
},
},
},
})
require.NoError(t, err)
require.NotNil(t, disableResponse)
require.Len(t, disableResponse.Errors, 0)

// Unlink the account
unlinkResponse, err := client.CloudUnlinkAccount(testAccountID, []CloudUnlinkAccountsInput{
{
LinkedAccountId: linkedAccountID,
},
})
require.NoError(t, err)
require.NotNil(t, unlinkResponse)
require.Len(t, unlinkResponse.Errors, 0)
}
126 changes: 126 additions & 0 deletions pkg/cloud/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3307,6 +3307,8 @@ type CloudDisableIntegrationsInput struct {
Azure CloudAzureDisableIntegrationsInput `json:"azure,omitempty"`
// Gcp provider
Gcp CloudGcpDisableIntegrationsInput `json:"gcp,omitempty"`
// OCI Provider
Oci CloudOciDisableIntegrationsInput `json:"oci,omitempty"`
}

// CloudDynamodbIntegration - DynamoDB Integration
Expand Down Expand Up @@ -5051,6 +5053,8 @@ type CloudIntegrationsInput struct {
Azure CloudAzureIntegrationsInput `json:"azure,omitempty"`
// Gcp provider
Gcp CloudGcpIntegrationsInput `json:"gcp,omitempty"`
// OCI Provider
Oci CloudOciIntegrationsInput `json:"oci,omitempty"`
}

// CloudIotIntegration - IoT Integration
Expand Down Expand Up @@ -5251,6 +5255,8 @@ type CloudLinkCloudAccountsInput struct {
Azure []CloudAzureLinkAccountInput `json:"azure,omitempty"`
// Gcp provider
Gcp []CloudGcpLinkAccountInput `json:"gcp,omitempty"`
// OCI Provider
Oci []CloudOciLinkAccountInput `json:"oci,omitempty"`
}

// CloudLinkedAccount - A cloud account linked to a NewRelic account.
Expand Down Expand Up @@ -5390,6 +5396,114 @@ func (x *CloudLinkedAccount) UnmarshalJSON(b []byte) error {
return nil
}

// CloudOciDisableIntegrationsInput - List of integrations
type CloudOciDisableIntegrationsInput struct {
// Fetch Metadata for OCI integrations integration
OciMetadataAndTags []CloudDisableAccountIntegrationInput `json:"ociMetadataAndTags,omitempty"`
}

// CloudOciIntegrationsInput - List of integrations
type CloudOciIntegrationsInput struct {
// Metadata and Tags for OCI integrations
OciMetadataAndTags []CloudOciMetadataAndTagsIntegrationInput `json:"ociMetadataAndTags,omitempty"`
}

// CloudOciLinkAccountInput - Information required to link a OCI tenancy to a NewRelic account.
type CloudOciLinkAccountInput struct {
// The New Relic compartment OCID in OCI.
CompartmentOcid string `json:"compartmentOcid"`
// The OCI ingest secret OCID.
IngestVaultOcid string `json:"ingestVaultOcid"`
// Specifies the type of integration, such as metrics, logs, or a combination of logs and metrics.
InstrumentationType string `json:"instrumentationType,omitempty"`
// The linked account name.
Name string `json:"name"`
// The client ID for OCI WIF.
OciClientId string `json:"ociClientId"`
// The client secret for OCI WIF.
OciClientSecret SecureValue `json:"ociClientSecret"`
// The OCI domain URL for WIF.
OciDomainURL string `json:"ociDomainUrl"`
// The home region of the tenancy.
OciHomeRegion string `json:"ociHomeRegion"`
// The service user name for OCI WIF.
OciSvcUserName string `json:"ociSvcUserName"`
// The OCI tenant identifier.
TenantId string `json:"tenantId"`
// The user secret OCID.
UserVaultOcid string `json:"userVaultOcid"`
}

// CloudOciMetadataAndTagsIntegration - Fetch Metadata and Tags for OCI integrations Integration
type CloudOciMetadataAndTagsIntegration struct {
// The object creation date, in epoch (Unix) time
CreatedAt nrtime.EpochSeconds `json:"createdAt"`
// The cloud service integration identifier.
ID int `json:"id,omitempty"`
// Specifies the type of integration, such as metrics, logs, or a combination of logs and metrics.
InstrumentationType string `json:"instrumentationType,omitempty"`
// The parent linked account identifier.
LinkedAccount CloudLinkedAccount `json:"linkedAccount,omitempty"`
// The logging OCI stack IDs.
LoggingStacks []string `json:"loggingStacks,omitempty"`
// The metrics OCI stack IDs.
MetricStacks []string `json:"metricStacks,omitempty"`
// The data polling interval in seconds.
MetricsPollingInterval int `json:"metricsPollingInterval,omitempty"`
// The cloud service integration name.
Name string `json:"name,omitempty"`
// The parent NewRelic account identifier.
NrAccountId int `json:"nrAccountId"`
// The cloud service used in the integration.
Service CloudService `json:"service,omitempty"`
// The object last update date, in epoch (Unix) time
UpdatedAt nrtime.EpochSeconds `json:"updatedAt"`
}

func (x *CloudOciMetadataAndTagsIntegration) ImplementsCloudIntegration() {}

// CloudOciMetadataAndTagsIntegrationInput - Fetch Metadata and Tags for OCI integrations
type CloudOciMetadataAndTagsIntegrationInput struct {
// The linked account identifier.
LinkedAccountId int `json:"linkedAccountId"`
}

// CloudOciUpdateAccountInput - Information required to update a AWS account to a NewRelic account.
type CloudOciUpdateAccountInput struct {
// The New Relic compartment OCID in OCI.
CompartmentOcid string `json:"compartmentOcid,omitempty"`
// Disable the linked account.
Disabled bool `json:"disabled,omitempty"`
// The OCI ingest secret OCID.
IngestVaultOcid string `json:"ingestVaultOcid,omitempty"`
// Specifies the type of integration, such as metrics, logs, or a combination of logs and metrics.
InstrumentationType string `json:"instrumentationType,omitempty"`
// The linked account identifier.
LinkedAccountId int `json:"linkedAccountId"`
// The Logging stack identifier for the OCI account.
LoggingStackOcid string `json:"loggingStackOcid,omitempty"`
// The metric stack identifier for the OCI account.
MetricStackOcid string `json:"metricStackOcid,omitempty"`
// The linked account new name.
Name string `json:"name,omitempty"`
// The client ID for OCI WIF.
OciClientId string `json:"ociClientId,omitempty"`
// The client secret for OCI WIF.
OciClientSecret SecureValue `json:"ociClientSecret,omitempty"`
// The domain URL for OCI WIF.
OciDomainURL string `json:"ociDomainUrl,omitempty"`
// The home region of the tenancy.
OciHomeRegion string `json:"ociHomeRegion,omitempty"`
// The OCI region for the account.
OciRegion string `json:"ociRegion,omitempty"`
// The service user name for OCI WIF.
OciSvcUserName string `json:"ociSvcUserName,omitempty"`
// The OCI tenant (used to fetch data).
TenantId string `json:"tenantId,omitempty"`
// The OCI user secret OCID.
UserVaultOcid string `json:"userVaultOcid,omitempty"`
}

// CloudProvider - A cloud services provider.
type CloudProvider struct {
// The object creation date, in epoch (Unix) time
Expand Down Expand Up @@ -5930,6 +6044,8 @@ type CloudUpdateCloudAccountsInput struct {
Fossa []CloudFossaUpdateAccountInput `json:"fossa,omitempty"`
// Gcp provider
Gcp []CloudGcpUpdateAccountInput `json:"gcp,omitempty"`
// OCI Provider
Oci []CloudOciUpdateAccountInput `json:"oci,omitempty"`
}

// CloudVpcIntegration - VPC Integration
Expand Down Expand Up @@ -7094,6 +7210,16 @@ func UnmarshalCloudIntegrationInterface(b []byte) (*CloudIntegrationInterface, e

var xxx CloudIntegrationInterface = &interfaceType

return &xxx, nil
case "CloudOciMetadataAndTagsIntegration":
var interfaceType CloudOciMetadataAndTagsIntegration
err = json.Unmarshal(b, &interfaceType)
if err != nil {
return nil, err
}

var xxx CloudIntegrationInterface = &interfaceType

return &xxx, nil
case "CloudRdsIntegration":
var interfaceType CloudRdsIntegration
Expand Down
Loading