Skip to content

Commit 7b826af

Browse files
author
caberos
committed
add new email features, email detail and email edit
1 parent 1572d8c commit 7b826af

File tree

10 files changed

+159
-1
lines changed

10 files changed

+159
-1
lines changed

SoftLayer/CLI/email/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Network Delivery account"""

SoftLayer/CLI/email/detail.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""Display details for a specified email."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
from SoftLayer.CLI import environment
6+
from SoftLayer.CLI import formatting
7+
from SoftLayer.managers.email import EmailManager
8+
from SoftLayer import utils
9+
10+
11+
@click.command()
12+
@click.argument('identifier')
13+
@environment.pass_env
14+
def cli(env, identifier):
15+
"""Display details for a specified email."""
16+
17+
email_manager = EmailManager(env.client)
18+
result = email_manager.get_instance(identifier)
19+
20+
table = formatting.KeyValueTable(['name', 'value'])
21+
table.align['name'] = 'r'
22+
table.align['value'] = 'l'
23+
24+
table.add_row(['id', result.get('id')])
25+
table.add_row(['username', result.get('username')])
26+
table.add_row(['create_date', result.get('createDate')])
27+
table.add_row(['categoryCode', utils.lookup(result, 'billingItem', 'categoryCode')])
28+
table.add_row(['description', utils.lookup(result, 'billingItem', 'description')])
29+
table.add_row(['type_description', utils.lookup(result, 'type', 'description')])
30+
table.add_row(['type', utils.lookup(result, 'type', 'keyName')])
31+
table.add_row(['vendor', utils.lookup(result, 'vendor', 'keyName')])
32+
33+
env.fout(table)

SoftLayer/CLI/email/edit.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""Edit details of an Delivery email account."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
from SoftLayer.CLI import environment
7+
from SoftLayer.CLI import exceptions
8+
from SoftLayer.managers.email import EmailManager
9+
10+
11+
@click.command()
12+
@click.argument('identifier')
13+
@click.option('--username', help="username account")
14+
@click.option('--email', help="Additional note for the image")
15+
@click.option('--password',
16+
help="Password must be between 8 and 20 characters "
17+
"and must contain one letter and one number.")
18+
@environment.pass_env
19+
def cli(env, identifier, username, email, password):
20+
"""Edit details of an email delivery account."""
21+
data = {}
22+
if username:
23+
data['username'] = username
24+
if email:
25+
data['emailAddress'] = email
26+
if password:
27+
data['password'] = password
28+
29+
email_manager = EmailManager(env.client)
30+
31+
if not email_manager.editObject(identifier, data):
32+
raise exceptions.CLIAbort("Failed to Edit email account")

SoftLayer/CLI/routes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@
121121

122122
('email', 'SoftLayer.CLI.email'),
123123
('email:list', 'SoftLayer.CLI.email.list:cli'),
124+
('email:detail', 'SoftLayer.CLI.email.detail:cli'),
125+
('email:edit', 'SoftLayer.CLI.email.edit:cli'),
124126

125127
('event-log', 'SoftLayer.CLI.event_log'),
126128
('event-log:get', 'SoftLayer.CLI.event_log.get:cli'),

SoftLayer/fixtures/SoftLayer_Network_Message_Delivery_Email_Sendgrid.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,34 @@
2525
"uniqueOpens": 0,
2626
"unsubscribes": 0
2727
}]
28+
29+
getObject = {
30+
"accountId": 123456,
31+
"createDate": "2020-07-06T10:29:11-06:00",
32+
"id": 1232123,
33+
"password": "Test123456789",
34+
"typeId": 21,
35+
"username": "techsupport3@ie.ibm.com",
36+
"vendorId": 1,
37+
"billingItem": {
38+
"categoryCode": "network_message_delivery",
39+
"description": "Free Package",
40+
"id": 695735054,
41+
"notes": "techsupport3@ie.ibm.com",
42+
},
43+
"type": {
44+
"description": "Delivery of messages through e-mail",
45+
"id": 21,
46+
"keyName": "EMAIL",
47+
"name": "Email"
48+
},
49+
"vendor": {
50+
"id": 1,
51+
"keyName": "SENDGRID",
52+
"name": "SendGrid"
53+
},
54+
"emailAddress": "techsupport3@ie.ibm.com",
55+
"smtpAccess": "1"
56+
}
57+
58+
editObject = True

SoftLayer/managers/email.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,33 @@ def get_statistics(self, identifier, days=30):
4545

4646
return self.client.call('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
4747
'getStatistics', id=identifier, *body)
48+
49+
def get_instance(self, identifier):
50+
"""Gets the Network_Message_Delivery_Email_Sendgrid instance
51+
52+
:return: Network_Message_Delivery_Email_Sendgrid
53+
"""
54+
55+
_mask = """emailAddress,type,billingItem,vendor"""
56+
57+
return self.client.call('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
58+
'getObject', id=identifier, mask=_mask)
59+
60+
def editObject(self, identifier, username=None, emailAddress=None, password=None):
61+
"""Edit email delivery account related details.
62+
63+
:param int identifier: The ID of the email account
64+
:param string username: username of the email account.
65+
:param string email: email of the email account.
66+
:param string password: password of the email account to be updated to.
67+
"""
68+
data = {}
69+
if username:
70+
data['username'] = username
71+
if emailAddress:
72+
data['emailAddress'] = emailAddress
73+
if password:
74+
data['password'] = password
75+
76+
return self.client.call('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
77+
'editObject', data, id=identifier)

docs/cli.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ To discover the available commands, simply type `slcli`.
7979
config CLI configuration.
8080
dedicatedhost Dedicated Host.
8181
dns Domain Name System.
82+
email Email Deliviry Network
8283
event-log Event Logs.
8384
file File Storage.
8485
firewall Firewalls.

docs/cli/email.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,12 @@ Email Commands
66

77
.. click:: SoftLayer.CLI.email.list:cli
88
:prog: email list
9+
:show-nested:
10+
11+
.. click:: SoftLayer.CLI.email.detail:cli
12+
:prog: email detail
13+
:show-nested:
14+
15+
.. click:: SoftLayer.CLI.email.edit:cli
16+
:prog: email edit
917
:show-nested:

tests/CLI/modules/email_tests.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,21 @@
99

1010
class EmailCLITests(testing.TestCase):
1111

12-
def test_detail(self):
12+
def test_list(self):
1313
result = self.run_command(['email', 'list'])
1414
self.assert_no_fail(result)
1515
self.assert_called_with('SoftLayer_Account', 'getNetworkMessageDeliveryAccounts')
16+
17+
def test_detail(self):
18+
result = self.run_command(['email', 'detail', '1232123'])
19+
self.assert_no_fail(result)
20+
self.assert_called_with('SoftLayer_Network_Message_Delivery_Email_Sendgrid', 'getObject')
21+
22+
def test_edit(self):
23+
result = self.run_command(['email', 'edit', '1232123',
24+
'--username=test@ibm.com',
25+
'--email=test@ibm.com',
26+
'--password=test123456789'])
27+
self.assert_no_fail(result)
28+
self.assert_called_with('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
29+
'editObject')

tests/managers/email_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,9 @@ def test_get_statistics(self):
2121
self.manager.get_statistics(1232123, 6)
2222
self.assert_called_with('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
2323
'getStatistics')
24+
25+
def test_get_object(self):
26+
self.manager = EmailManager(self.client)
27+
self.manager.get_instance(1232123)
28+
self.assert_called_with('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
29+
'getObject')

0 commit comments

Comments
 (0)