Skip to content

Commit

Permalink
Merge pull request #238 from ns1/PENG-4484/remove_cmddi_code
Browse files Browse the repository at this point in the history
remove all ddi related code
  • Loading branch information
hmodi-ns1 authored Jul 24, 2024
2 parents 89eb799 + 83e1ed4 commit 72c28cb
Show file tree
Hide file tree
Showing 28 changed files with 19 additions and 2,512 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
FEATURES:

* Adds support for new split monitoring permissions create_jobs, update_jobs and delete_jobs
* Remove DDI (DHCP & IPAM) code

## 2.11.0 (May 23rd, 2024)

Expand Down
84 changes: 0 additions & 84 deletions rest/_examples/ddi_apikey.go

This file was deleted.

67 changes: 6 additions & 61 deletions rest/account_apikey.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,9 @@ func (s *APIKeysService) Create(a *account.APIKey) (*http.Response, error) {
err error
)

// If this is DDI then the permissions need to be transformed to DDI-compatible permissions.
if s.client.DDI && a != nil {
ddiAPIKey := apiKeyToDDIAPIKey(a)
req, err = s.client.NewRequest("PUT", "account/apikeys", ddiAPIKey)
if err != nil {
return nil, err
}
} else {
req, err = s.client.NewRequest("PUT", "account/apikeys", a)
if err != nil {
return nil, err
}
req, err = s.client.NewRequest("PUT", "account/apikeys", a)
if err != nil {
return nil, err
}

// Update account fields with data from api(ensure consistent)
Expand Down Expand Up @@ -106,18 +97,9 @@ func (s *APIKeysService) Update(a *account.APIKey) (*http.Response, error) {
err error
)

// If this is DDI then the permissions need to be transformed to DDI-compatible permissions.
if s.client.DDI && a != nil {
ddiAPIKey := apiKeyToDDIAPIKey(a)
req, err = s.client.NewRequest("POST", path, ddiAPIKey)
if err != nil {
return nil, err
}
} else {
req, err = s.client.NewRequest("POST", path, a)
if err != nil {
return nil, err
}
req, err = s.client.NewRequest("POST", path, a)
if err != nil {
return nil, err
}

// Update apikey fields with data from api(ensure consistent)
Expand Down Expand Up @@ -166,40 +148,3 @@ var (
// ErrKeyMissing bundles GET/POST/DELETE error.
ErrKeyMissing = errors.New("key does not exist")
)

func apiKeyToDDIAPIKey(k *account.APIKey) *ddiAPIKey {
ddiAPIKey := &ddiAPIKey{
ID: k.ID,
Key: k.Key,
LastAccess: k.LastAccess,
Name: k.Name,
TeamIDs: k.TeamIDs,
IPWhitelist: k.IPWhitelist,
IPWhitelistStrict: k.IPWhitelistStrict,
Permissions: ddiPermissionsMap{
DNS: k.Permissions.DNS,
Data: k.Permissions.Data,
Account: permissionsDDIAccount{
ManageUsers: k.Permissions.Account.ManageUsers,
ManageTeams: k.Permissions.Account.ManageTeams,
ManageApikeys: k.Permissions.Account.ManageApikeys,
ManageAccountSettings: k.Permissions.Account.ManageAccountSettings,
ViewActivityLog: k.Permissions.Account.ViewActivityLog,
},
},
}

if k.Permissions.Security != nil {
ddiAPIKey.Permissions.Security = permissionsDDISecurity(*k.Permissions.Security)
}

if k.Permissions.DHCP != nil {
ddiAPIKey.Permissions.DHCP = *k.Permissions.DHCP
}

if k.Permissions.IPAM != nil {
ddiAPIKey.Permissions.IPAM = *k.Permissions.IPAM
}

return ddiAPIKey
}
116 changes: 0 additions & 116 deletions rest/account_apikey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ func TestCreateAPIKey(t *testing.T) {
var k account.APIKey
require.NoError(t, json.Unmarshal(b, &k))
assert.Nil(t, k.Permissions.Security)
assert.Nil(t, k.Permissions.DHCP)
assert.Nil(t, k.Permissions.IPAM)
assert.False(t, k.Permissions.Monitoring.ManageJobs)
assert.False(t, k.Permissions.Monitoring.CreateJobs)
assert.False(t, k.Permissions.Monitoring.UpdateJobs)
Expand All @@ -44,117 +42,3 @@ func TestCreateAPIKey(t *testing.T) {
_, err := c.APIKeys.Create(k)
require.NoError(t, err)
}

func TestCreateDDIAPIKey(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
b, err := ioutil.ReadAll(r.Body)
require.NoError(t, err)

var k account.APIKey
require.NoError(t, json.Unmarshal(b, &k))
switch k.ID {
case "ddi-no-authtags":
assert.NotNil(t, k.Permissions.Security)
assert.NotNil(t, k.Permissions.DHCP)
assert.NotNil(t, k.Permissions.IPAM)
assert.NotNil(t, k.IPWhitelist)
assert.True(t, k.IPWhitelistStrict)
// ensure auth tag permissions are not included by default to maintain backwards compatibility
assert.Nil(t, k.Permissions.DHCP.TagsAllow)
assert.Nil(t, k.Permissions.DHCP.TagsDeny)
assert.Nil(t, k.Permissions.IPAM.TagsAllow)
assert.Nil(t, k.Permissions.IPAM.TagsDeny)
case "ddi-authtags":
assert.NotNil(t, k.Permissions.DHCP)
assert.NotNil(t, k.Permissions.IPAM)
assert.Equal(t, "auth:dhcpallow", (*k.Permissions.DHCP.TagsAllow)[0].Name)
assert.Equal(t, "", (*k.Permissions.DHCP.TagsAllow)[0].Value)
assert.Equal(t, "auth:dhcpdeny", (*k.Permissions.DHCP.TagsDeny)[0].Name)
assert.Equal(t, "denyme", (*k.Permissions.DHCP.TagsDeny)[0].Value)
assert.Equal(t, "auth:ipamallow", (*k.Permissions.IPAM.TagsAllow)[0].Name)
assert.Equal(t, "", (*k.Permissions.IPAM.TagsAllow)[0].Value)
assert.Equal(t, "auth:ipamdeny", (*k.Permissions.IPAM.TagsDeny)[0].Name)
assert.Equal(t, "denyme", (*k.Permissions.IPAM.TagsDeny)[0].Value)
case "ddi-empty-authtags":
assert.NotNil(t, k.Permissions.DHCP)
assert.NotNil(t, k.Permissions.IPAM)
assert.Equal(t, []account.AuthTag{}, *k.Permissions.DHCP.TagsAllow)
assert.Equal(t, []account.AuthTag{}, *k.Permissions.DHCP.TagsDeny)
assert.Equal(t, []account.AuthTag{}, *k.Permissions.IPAM.TagsAllow)
assert.Equal(t, []account.AuthTag{}, *k.Permissions.IPAM.TagsDeny)
}

_, err = w.Write(b)
require.NoError(t, err)
}))
defer ts.Close()
c := NewClient(nil, SetEndpoint(ts.URL), SetDDIAPI())

// Create a key without auth tags
k := &account.APIKey{
ID: "ddi-no-authtags",
Key: "key-1",
Name: "name-1",
IPWhitelist: []string{"1.1.1.1"},
IPWhitelistStrict: true,
Permissions: account.PermissionsMap{},
}

_, err := c.APIKeys.Create(k)
require.NoError(t, err)
// Create a key with auth tags
k = &account.APIKey{
ID: "ddi-authtags",
Key: "key-2",
Name: "name-2",
Permissions: account.PermissionsMap{
DHCP: &account.PermissionsDHCP{
TagsAllow: &[]account.AuthTag{
{
Name: "auth:dhcpallow",
Value: "",
},
},
TagsDeny: &[]account.AuthTag{
{
Name: "auth:dhcpdeny",
Value: "denyme",
},
},
},
IPAM: &account.PermissionsIPAM{
TagsAllow: &[]account.AuthTag{
{
Name: "auth:ipamallow",
Value: "",
},
},
TagsDeny: &[]account.AuthTag{
{
Name: "auth:ipamdeny",
Value: "denyme",
},
},
},
},
}
// Create a key with empty auth tags
k = &account.APIKey{
ID: "ddi-empty-authtags",
Key: "key-3",
Name: "name-3",
Permissions: account.PermissionsMap{
DHCP: &account.PermissionsDHCP{
TagsAllow: &[]account.AuthTag{},
TagsDeny: &[]account.AuthTag{},
},
IPAM: &account.PermissionsIPAM{
TagsAllow: &[]account.AuthTag{},
TagsDeny: &[]account.AuthTag{},
},
},
}

_, err = c.APIKeys.Create(k)
require.NoError(t, err)
}
63 changes: 6 additions & 57 deletions rest/account_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,9 @@ func (s *TeamsService) Create(t *account.Team) (*http.Response, error) {
err error
)

// If this is DDI then the permissions need to be transformed to DDI-compatible permissions.
if s.client.DDI && t != nil {
ddiTeam := teamToDDITeam(t)
req, err = s.client.NewRequest("PUT", "account/teams", ddiTeam)
if err != nil {
return nil, err
}
} else {
req, err = s.client.NewRequest("PUT", "account/teams", t)
if err != nil {
return nil, err
}
req, err = s.client.NewRequest("PUT", "account/teams", t)
if err != nil {
return nil, err
}

// Update team fields with data from api(ensure consistent)
Expand Down Expand Up @@ -104,18 +95,9 @@ func (s *TeamsService) Update(t *account.Team) (*http.Response, error) {
err error
)

// If this is DDI then the permissions need to be transformed to DDI-compatible permissions.
if s.client.DDI && t != nil {
ddiTeam := teamToDDITeam(t)
req, err = s.client.NewRequest("POST", path, ddiTeam)
if err != nil {
return nil, err
}
} else {
req, err = s.client.NewRequest("POST", path, t)
if err != nil {
return nil, err
}
req, err = s.client.NewRequest("POST", path, t)
if err != nil {
return nil, err
}

// Update team fields with data from api(ensure consistent)
Expand Down Expand Up @@ -164,36 +146,3 @@ var (
// ErrTeamMissing bundles GET/POST/DELETE error.
ErrTeamMissing = errors.New("team does not exist")
)

func teamToDDITeam(t *account.Team) *ddiTeam {
ddiTeam := &ddiTeam{
ID: t.ID,
Name: t.Name,
IPWhitelist: t.IPWhitelist,
Permissions: ddiPermissionsMap{
DNS: t.Permissions.DNS,
Data: t.Permissions.Data,
Account: permissionsDDIAccount{
ManageUsers: t.Permissions.Account.ManageUsers,
ManageTeams: t.Permissions.Account.ManageTeams,
ManageApikeys: t.Permissions.Account.ManageApikeys,
ManageAccountSettings: t.Permissions.Account.ManageAccountSettings,
ViewActivityLog: t.Permissions.Account.ViewActivityLog,
},
},
}

if t.Permissions.Security != nil {
ddiTeam.Permissions.Security = permissionsDDISecurity(*t.Permissions.Security)
}

if t.Permissions.DHCP != nil {
ddiTeam.Permissions.DHCP = *t.Permissions.DHCP
}

if t.Permissions.IPAM != nil {
ddiTeam.Permissions.IPAM = *t.Permissions.IPAM
}

return ddiTeam
}
Loading

0 comments on commit 72c28cb

Please sign in to comment.