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

feat(authorizationmanagement): Add new authorizationmanagement pkg. #1099

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 18 additions & 0 deletions .tutone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,24 @@ packages:
- name: DateTime
field_type_override: nrtime.DateTime
skip_type_create: true

- name: authorizationmanagement
path: pkg/authorizationmanagement
import_path: github.com/newrelic/newrelic-client-go/v2/pkg/authorizationmanagement
generators:
- typegen
- nerdgraphclient
imports:
- github.com/newrelic/newrelic-client-go/v2/pkg/common
- github.com/newrelic/newrelic-client-go/v2/pkg/nrtime
queries: []
mutations:
- name: authorizationManagementGrantAccess
max_query_field_depth: 2
types:
- name: ID
field_type_override: string
skip_type_create: true
generators:
- name: typegen
fileName: "types.go"
Expand Down
111 changes: 57 additions & 54 deletions newrelic/newrelic.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/newrelic/newrelic-client-go/v2/pkg/alerts"
"github.com/newrelic/newrelic-client-go/v2/pkg/apiaccess"
"github.com/newrelic/newrelic-client-go/v2/pkg/apm"
"github.com/newrelic/newrelic-client-go/v2/pkg/authorizationmanagement"
"github.com/newrelic/newrelic-client-go/v2/pkg/changetracking"
"github.com/newrelic/newrelic-client-go/v2/pkg/cloud"
"github.com/newrelic/newrelic-client-go/v2/pkg/config"
Expand Down Expand Up @@ -37,33 +38,34 @@ import (

// NewRelic is a collection of New Relic APIs.
type NewRelic struct {
AccountManagement accountmanagement.Accountmanagement
AgentApplications agentapplications.AgentApplications
Accounts accounts.Accounts
Alerts alerts.Alerts
APIAccess apiaccess.APIAccess
APM apm.APM
ChangeTracking changetracking.Changetracking
Cloud cloud.Cloud
Dashboards dashboards.Dashboards
Edge edge.Edge
Entities entities.Entities
Events events.Events
EventsToMetrics eventstometrics.EventsToMetrics
InstallEvents installevents.Installevents
Logs logs.Logs
Logconfigurations logconfigurations.Logconfigurations
NerdGraph nerdgraph.NerdGraph
NerdStorage nerdstorage.NerdStorage
Notifications notifications.Notifications
Nrdb nrdb.Nrdb
Nrqldroprules nrqldroprules.Nrqldroprules
Plugins plugins.Plugins
ServiceLevel servicelevel.Servicelevel
Synthetics synthetics.Synthetics
UserManagement usermanagement.Usermanagement
Workflows workflows.Workflows
Workloads workloads.Workloads
AccountManagement accountmanagement.Accountmanagement
AgentApplications agentapplications.AgentApplications
AuthorizationManagement authorizationmanagement.Authorizationmanagement
Accounts accounts.Accounts
Alerts alerts.Alerts
APIAccess apiaccess.APIAccess
APM apm.APM
ChangeTracking changetracking.Changetracking
Cloud cloud.Cloud
Dashboards dashboards.Dashboards
Edge edge.Edge
Entities entities.Entities
Events events.Events
EventsToMetrics eventstometrics.EventsToMetrics
InstallEvents installevents.Installevents
Logs logs.Logs
Logconfigurations logconfigurations.Logconfigurations
NerdGraph nerdgraph.NerdGraph
NerdStorage nerdstorage.NerdStorage
Notifications notifications.Notifications
Nrdb nrdb.Nrdb
Nrqldroprules nrqldroprules.Nrqldroprules
Plugins plugins.Plugins
ServiceLevel servicelevel.Servicelevel
Synthetics synthetics.Synthetics
UserManagement usermanagement.Usermanagement
Workflows workflows.Workflows
Workloads workloads.Workloads

config config.Config
}
Expand All @@ -80,33 +82,34 @@ func New(opts ...ConfigOption) (*NewRelic, error) {
nr := &NewRelic{
config: cfg,

AccountManagement: accountmanagement.New(cfg),
AgentApplications: agentapplications.New(cfg),
Accounts: accounts.New(cfg),
Alerts: alerts.New(cfg),
APIAccess: apiaccess.New(cfg),
APM: apm.New(cfg),
ChangeTracking: changetracking.New(cfg),
Cloud: cloud.New(cfg),
Dashboards: dashboards.New(cfg),
Edge: edge.New(cfg),
Entities: entities.New(cfg),
Events: events.New(cfg),
EventsToMetrics: eventstometrics.New(cfg),
InstallEvents: installevents.New(cfg),
Logs: logs.New(cfg),
Logconfigurations: logconfigurations.New(cfg),
NerdGraph: nerdgraph.New(cfg),
NerdStorage: nerdstorage.New(cfg),
Notifications: notifications.New(cfg),
Nrdb: nrdb.New(cfg),
Nrqldroprules: nrqldroprules.New(cfg),
Plugins: plugins.New(cfg),
ServiceLevel: servicelevel.New(cfg),
Synthetics: synthetics.New(cfg),
UserManagement: usermanagement.New(cfg),
Workflows: workflows.New(cfg),
Workloads: workloads.New(cfg),
AccountManagement: accountmanagement.New(cfg),
AgentApplications: agentapplications.New(cfg),
AuthorizationManagement: authorizationmanagement.New(cfg),
Accounts: accounts.New(cfg),
Alerts: alerts.New(cfg),
APIAccess: apiaccess.New(cfg),
APM: apm.New(cfg),
ChangeTracking: changetracking.New(cfg),
Cloud: cloud.New(cfg),
Dashboards: dashboards.New(cfg),
Edge: edge.New(cfg),
Entities: entities.New(cfg),
Events: events.New(cfg),
EventsToMetrics: eventstometrics.New(cfg),
InstallEvents: installevents.New(cfg),
Logs: logs.New(cfg),
Logconfigurations: logconfigurations.New(cfg),
NerdGraph: nerdgraph.New(cfg),
NerdStorage: nerdstorage.New(cfg),
Notifications: notifications.New(cfg),
Nrdb: nrdb.New(cfg),
Nrqldroprules: nrqldroprules.New(cfg),
Plugins: plugins.New(cfg),
ServiceLevel: servicelevel.New(cfg),
Synthetics: synthetics.New(cfg),
UserManagement: usermanagement.New(cfg),
Workflows: workflows.New(cfg),
Workloads: workloads.New(cfg),
}

return nr, nil
Expand Down
26 changes: 26 additions & 0 deletions pkg/authorizationmanagement/authorizationmanagement.go

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

52 changes: 52 additions & 0 deletions pkg/authorizationmanagement/authorizationmanagement_api.go

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

21 changes: 21 additions & 0 deletions pkg/authorizationmanagement/authorizationmanagement_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package authorizationmanagement

import (
"testing"

mock "github.com/newrelic/newrelic-client-go/v2/pkg/testhelpers"
)

func newAuthorizationManagementTestClient(t *testing.T) Authorizationmanagement {
cfg := mock.NewIntegrationTestConfig(t)
client := New(cfg)

return client
}

func newMockResponse(t *testing.T, mockJSONResponse string, statusCode int) Authorizationmanagement {
ts := mock.NewMockServer(t, mockJSONResponse, statusCode)
tc := mock.NewTestConfig(t, ts)

return New(tc)
}
75 changes: 75 additions & 0 deletions pkg/authorizationmanagement/authorizationmanagement_unit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package authorizationmanagement

import (
"fmt"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
)

var (
testAuthorizationManagementCreateResponse = `{
"authorizationManagementGrantAccess": {
"roles": [
{
"accountId": 1111111,
"displayName": "All Product Admin",
"name": "all_product_admin",
"organizationId": null,
"roleId": 1254,
"type": "Role::V2::Standard"
},
{
"accountId": 1111112,
"displayName": "All Product Admin",
"name": "all_product_admin",
"organizationId": null,
"roleId": 1254,
"type": "Role::V2::Standard"
}
]
}
}`
)

func TestCreateAuthorizationManagement(t *testing.T) {
t.Parallel()
respJSON := fmt.Sprintf(`{ "data":%s }`, testAuthorizationManagementCreateResponse)
authorizationManagement := newMockResponse(t, respJSON, http.StatusCreated)

roleId := "1254"
accountId := 1111111
groupId := "1111112"

authorizationManagementGrantAccessInput := AuthorizationManagementGrantAccess{
AccountAccessGrants: []AuthorizationManagementAccountAccessGrant{
{
AccountID: accountId,
RoleId: roleId,
},
},
GroupId: groupId,
}

actual, err := authorizationManagement.AuthorizationManagementGrantAccess(authorizationManagementGrantAccessInput)

assert.NoError(t, err)
assert.NotNil(t, actual)
assert.GreaterOrEqual(t, len(actual.Roles), 1)

roleIdFound := false
accountIdFound := false

for _, role := range actual.Roles {
if fmt.Sprint(role.RoleId) == roleId {
roleIdFound = true
}
if role.AccountID == accountId {
accountIdFound = true
}
}

assert.True(t, roleIdFound, "Role not found")
assert.True(t, accountIdFound, "Account not found")
}
62 changes: 62 additions & 0 deletions pkg/authorizationmanagement/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Code generated by tutone: DO NOT EDIT
package authorizationmanagement

// AuthorizationManagementAccountAccessGrant - The Account and Role a Group should have access to
type AuthorizationManagementAccountAccessGrant struct {
// The Account ID the Role will grant access to
AccountID int `json:"accountId"`
// The Role ID that will define the access
RoleId string `json:"roleId"`
}

// AuthorizationManagementGrantAccess - The input object representing the access to grant for the group
type AuthorizationManagementGrantAccess struct {
// The Role and the Account the Target Group should have access to
AccountAccessGrants []AuthorizationManagementAccountAccessGrant `json:"accountAccessGrants,omitempty"`
// The Role and the Group the Target Group should have access to
GroupAccessGrants []AuthorizationManagementGroupAccessGrant `json:"groupAccessGrants,omitempty"`
// The Group ID that will have access granted
GroupId string `json:"groupId"`
// The Role and the Organization the Target Group should have access to
OrganizationAccessGrants []AuthorizationManagementOrganizationAccessGrant `json:"organizationAccessGrants,omitempty"`
}

// AuthorizationManagementGrantAccessPayload - Autogenerated return type of GrantAccess
type AuthorizationManagementGrantAccessPayload struct {
// the roles that were granted to this group
Roles []AuthorizationManagementGrantedRole `json:"roles"`
}

// AuthorizationManagementGrantedRole - A Granted Role represents the access given to a group.
type AuthorizationManagementGrantedRole struct {
// the account that this role grants access to
AccountID int `json:"accountId,omitempty"`
// the name of the object
DisplayName string `json:"displayName,omitempty"`
// the group that this role grants access to
GroupId string `json:"groupId,omitempty"`
// a value that uniquely identifies this object
ID string `json:"id"`
// the name of the object
Name string `json:"name"`
// the organization this role grants access to
OrganizationId string `json:"organizationId,omitempty"`
// the role that defines this access
RoleId int `json:"roleId"`
// the type of the role
Type string `json:"type"`
}

// AuthorizationManagementGroupAccessGrant - The Group and Role another Group should have access to
type AuthorizationManagementGroupAccessGrant struct {
// The Group ID the Role will grant access to
GroupId string `json:"groupId"`
// The Role ID that will define the access
RoleId string `json:"roleId"`
}

// AuthorizationManagementOrganizationAccessGrant - The Organization Role a Group should have access to
type AuthorizationManagementOrganizationAccessGrant struct {
// The Role ID that will define the Organization access
RoleId string `json:"roleId"`
}