Skip to content

Commit

Permalink
feat(fossa): add fossa link account integration
Browse files Browse the repository at this point in the history
  • Loading branch information
vagrawal-newrelic committed Nov 22, 2024
1 parent a221c9e commit 0390cd0
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 1 deletion.
20 changes: 20 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.

72 changes: 72 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,75 @@ func TestCloudAccount_AzureMonitorIntegration(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, unlinkResponse)
}

func TestCloudAccount_FOSSALinkAccount(t *testing.T) {
t.Parallel()

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

a := newIntegrationTestClient(t)
// Reset everything
getResponse, err := a.GetLinkedAccounts("fossa")
//require.NoError(t, err)
if getResponse != nil {
for _, linkedAccount := range *getResponse {
if linkedAccount.NrAccountId == testAccountID {
a.CloudUnlinkAccount(testAccountID, []CloudUnlinkAccountsInput{
{
LinkedAccountId: linkedAccount.ID,
},
})
}
}
}

// Link the account
linkResponse, err := a.CloudLinkAccount(testAccountID, CloudLinkCloudAccountsInput{
Fossa: []CloudFossaLinkAccountInput{
{
APIKey: "f3ab70a3d29029c94ab8057f1b30838b",
Name: "DTK Integration Testing",
ExternalId: "test",
},
},
})
require.NoError(t, err)
//require.Nil(t, linkResponse.Errors)
require.NotNil(t, linkResponse.LinkedAccounts)

// Get the linked account
getResponse, err = a.GetLinkedAccounts("fossa")
require.NoError(t, err)

var linkedAccountID int
for _, linkedAccount := range *getResponse {
if linkedAccount.NrAccountId == testAccountID {
linkedAccountID = linkedAccount.ID
break
}
}
require.NotZero(t, linkedAccountID)

// Rename the account
newName := "NEW-DTK-NAME"
renameResponse, err := a.CloudRenameAccount(testAccountID, []CloudRenameAccountsInput{
{
LinkedAccountId: linkedAccountID,
Name: newName,
},
})
require.NoError(t, err)
require.NotNil(t, renameResponse)

// Unlink the account
unlinkResponse, err := a.CloudUnlinkAccount(testAccountID, []CloudUnlinkAccountsInput{
{
LinkedAccountId: linkedAccountID,
},
})
require.NoError(t, err)
require.NotNil(t, unlinkResponse)
}
38 changes: 38 additions & 0 deletions pkg/cloud/cloud_api_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ var (
]
}
}
}
`

testCreateFOSSALinkAccount = `
{
"data": {
"cloudLinkAccount": {
"linkedAccounts": [
{
"id": ` + linkedAccountID + `,
"name": "TEST_FOSSA_ACCOUNT",
"nrAccountId": ` + nrAccountID + `,
}
]
}
}
}
`
)
Expand Down Expand Up @@ -201,3 +217,25 @@ func TestUnitAzureLinkAccountUpdate(t *testing.T) {
assert.Equal(t, nrAccountID, strconv.Itoa(actual.LinkedAccounts[0].NrAccountId))

}

func TestUnitFOSSALinkAccountCreate(t *testing.T) {
t.Parallel()
createFOSSALinkAccountResponse := newMockResponse(t, testCreateFOSSALinkAccount, http.StatusOK)
NRAccountIDInt, _ := strconv.Atoi(nrAccountID)

createAccountInput := CloudLinkCloudAccountsInput{
Fossa: []CloudFossaLinkAccountInput{{
APIKey: "f3ab70a3d29028c94ab8057f1b30838b",
//ExternalId: "agjs-dha57-687hag-shgafshd-f79hh",
Name: "TEST_FOSSA_ACCOUNT",
}},
}

actual, err := createFOSSALinkAccountResponse.CloudLinkAccount(NRAccountIDInt, createAccountInput)

assert.NoError(t, err)
assert.NotNil(t, actual)
assert.Equal(t, linkedAccountID, strconv.Itoa(actual.LinkedAccounts[0].ID))
assert.Equal(t, "TEST_FOSSA_ACCOUNT", actual.LinkedAccounts[0].Name)
assert.Equal(t, "agjs-dha57-687hag-shgafshd-f79hh", actual.LinkedAccounts[0].ExternalId)
}
74 changes: 73 additions & 1 deletion pkg/cloud/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3263,6 +3263,8 @@ type CloudDisableIntegrationsInput struct {
AwsGovcloud CloudAwsGovcloudDisableIntegrationsInput `json:"awsGovcloud,omitempty"`
// Azure provider
Azure CloudAzureDisableIntegrationsInput `json:"azure,omitempty"`
// Fossa provider
Fossa CloudFossaDisableIntegrationsInput `json:"fossa,omitempty"`
// Gcp provider
Gcp CloudGcpDisableIntegrationsInput `json:"gcp,omitempty"`
}
Expand Down Expand Up @@ -3775,6 +3777,62 @@ type CloudEmrIntegrationInput struct {
TagValue string `json:"tagValue,omitempty"`
}

// CloudFossaDisableIntegrationsInput - List of integrations
type CloudFossaDisableIntegrationsInput struct {
// FOSSA Issues integration
FossaIssues []CloudDisableAccountIntegrationInput `json:"fossaIssues,omitempty"`
}

// CloudFossaIntegrationsInput - List of integrations
type CloudFossaIntegrationsInput struct {
// FOSSA Issues integration
FossaIssues []CloudFossaIssuesIntegrationInput `json:"fossaIssues,omitempty"`
}

// CloudFossaIssuesIntegration - FOSSA Issues Integration
type CloudFossaIssuesIntegration struct {
// The object creation date, in epoch (Unix) time
CreatedAt nrtime.EpochSeconds `json:"createdAt"`
// The cloud service integration identifier.
ID int `json:"id,omitempty"`
// [DEPRECATED] Multiple polling interval is no longer supported, use only metrics_polling_interval
InventoryPollingInterval int `json:"inventoryPollingInterval,omitempty"`
// The parent linked account identifier.
LinkedAccount CloudLinkedAccount `json:"linkedAccount,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 *CloudFossaIssuesIntegration) ImplementsCloudIntegration() {}

// CloudFossaIssuesIntegrationInput - FOSSA Issues
type CloudFossaIssuesIntegrationInput struct {
// [DEPRECATED] Multiple polling interval is no longer supported, use only metrics_polling_interval
InventoryPollingInterval int `json:"inventoryPollingInterval,omitempty"`
// The linked account identifier.
LinkedAccountId int `json:"linkedAccountId"`
// The data polling interval in seconds.
MetricsPollingInterval int `json:"metricsPollingInterval,omitempty"`
}

// CloudFossaLinkAccountInput - Information required to link a Fossa account to a NewRelic account.
type CloudFossaLinkAccountInput struct {
// The Fossa account application api key(bearer token).
APIKey SecureValue `json:"apiKey"`
// The Fossa account identifier.
ExternalId string `json:"externalId,omitempty"`
// The linked account name.
Name string `json:"name"`
}

// CloudFossaUpdateAccountInput - Information required to update a Fossa account to a NewRelic account.
type CloudFossaUpdateAccountInput struct {
// The Fossa account application api key(bearer token).
Expand Down Expand Up @@ -5007,6 +5065,8 @@ type CloudIntegrationsInput struct {
AwsGovcloud CloudAwsGovcloudIntegrationsInput `json:"awsGovcloud,omitempty"`
// Azure provider
Azure CloudAzureIntegrationsInput `json:"azure,omitempty"`
// Fossa provider
Fossa CloudFossaIntegrationsInput `json:"fossa,omitempty"`
// Gcp provider
Gcp CloudGcpIntegrationsInput `json:"gcp,omitempty"`
}
Expand Down Expand Up @@ -5207,12 +5267,14 @@ type CloudLinkCloudAccountsInput struct {
AwsGovcloud []CloudAwsGovCloudLinkAccountInput `json:"awsGovcloud,omitempty"`
// Azure provider
Azure []CloudAzureLinkAccountInput `json:"azure,omitempty"`
// Fossa provider
Fossa []CloudFossaLinkAccountInput `json:"fossa,omitempty"`
// Gcp provider
Gcp []CloudGcpLinkAccountInput `json:"gcp,omitempty"`
}

// CloudLinkedAccount - A cloud account linked to a NewRelic account.
type CloudLinkedAccount struct {
type CloudLinkedAccount struct {
// The credential. This is a Role ARN for AWS, an application ID for Azure and a service account ID or user account email for GCP.
AuthLabel string `json:"authLabel"`
// The object creation date, in epoch (Unix) time
Expand Down Expand Up @@ -6714,6 +6776,16 @@ func UnmarshalCloudIntegrationInterface(b []byte) (*CloudIntegrationInterface, e

var xxx CloudIntegrationInterface = &interfaceType

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

var xxx CloudIntegrationInterface = &interfaceType

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

0 comments on commit 0390cd0

Please sign in to comment.