Skip to content

Commit 9de3dfc

Browse files
authored
Merge pull request #1 from caberos/issue1485
add new email features, email detail and email edit
2 parents 1572d8c + 2a8637a commit 9de3dfc

File tree

11 files changed

+201
-6
lines changed

11 files changed

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

SoftLayer/CLI/email/edit.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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="Sets username for this account")
14+
@click.option('--email', help="Sets the contact email for this account")
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+
email_manager = EmailManager(env.client)
22+
23+
data = {}
24+
update = False
25+
if email:
26+
if email_manager.update_email(identifier, email):
27+
update = True
28+
else:
29+
raise exceptions.CLIAbort("Failed to Edit emailAddress account")
30+
if username:
31+
data['username'] = username
32+
if password:
33+
data['password'] = password
34+
if len(data) != 0:
35+
if email_manager.editObject(identifier, **data):
36+
update = True
37+
else:
38+
raise exceptions.CLIAbort("Failed to Edit email account")
39+
40+
if update:
41+
env.fout('Updated Successfully')

SoftLayer/CLI/email/list.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Get lists Email Delivery account Service """
1+
"""Lists Email Delivery Service """
22
# :license: MIT, see LICENSE for more details.
33

44
import click
@@ -36,25 +36,29 @@ def cli(env):
3636
table.add_row(['email_information', table_information])
3737
table.add_row(['email_overview', overview_table])
3838
for statistic in statistics:
39-
table.add_row(['statistics', _build_statistics_table(statistic)])
39+
table.add_row(['statistics', build_statistics_table(statistic)])
4040

4141
env.fout(table)
4242

4343

4444
def _build_overview_table(email_overview):
45-
table = formatting.Table(['credit_Allowed', 'credits_Remain', 'package', 'reputation', 'requests'])
45+
table = formatting.Table(
46+
['credit_allowed', 'credits_remain', 'credits_overage', 'credits_used',
47+
'package', 'reputation', 'requests'])
4648
table.align['name'] = 'r'
4749
table.align['value'] = 'l'
4850

4951
table.add_row([email_overview.get('creditsAllowed'), email_overview.get('creditsRemain'),
52+
email_overview.get('creditsOverage'), email_overview.get('creditsUsed'),
5053
email_overview.get('package'), email_overview.get('reputation'),
5154
email_overview.get('requests')])
5255

5356
return table
5457

5558

56-
def _build_statistics_table(statistics):
57-
table = formatting.Table(['delivered', 'requests', 'bounces', 'opens', 'clicks', 'spamReports'])
59+
def build_statistics_table(statistics):
60+
"""statistics records of Email Delivery account"""
61+
table = formatting.Table(['delivered', 'requests', 'bounces', 'opens', 'clicks', 'spam_reports'])
5862
table.align['name'] = 'r'
5963
table.align['value'] = 'l'
6064

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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,35 @@
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
59+
updateEmailAddress = True

SoftLayer/managers/email.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,41 @@ 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, 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 password:
72+
data['password'] = password
73+
74+
return self.client.call('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
75+
'editObject', data, id=identifier)
76+
77+
def update_email(self, identifier, email):
78+
"""Edit email address delivery account .
79+
80+
:param int identifier: The ID of the email account
81+
:param string email: email of the email account.
82+
83+
"""
84+
return self.client.call('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
85+
'updateEmailAddress', email, 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: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,23 @@
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')
30+
self.assert_called_with('SoftLayer_Network_Message_Delivery_Email_Sendgrid',
31+
'updateEmailAddress')

0 commit comments

Comments
 (0)