Ошибка создания арендатора - языковой стандарт не может быть нулевым - PullRequest
0 голосов
/ 18 декабря 2018

Это моя первая публикация в переполнение стека, спасибо за ваше терпение!

Я пытаюсь создать нового клиента в режиме повышенной безопасности и получаю эту ошибку:

An exception occurred when calling TenantsApi.create_tenant: (400)
Reason: 
HTTP response headers: HTTPHeaderDict({'X-Frame-Options': 'SAMEORIGIN', 'X-XSS-Protection': '1;mode=block', 'Cache-Control': 'no-cache,no-store', 'Pragma': 'no-cache', 'X-DSM-Version': 'Deep Security/11.2.225', 'Content-Type': 'application/json', 'Content-Length': '44', 'Date': 'Mon, 17 Dec 2018 23:39:16 GMT', 'Connection': 'close'})
HTTP response body: {"message":"Account locale cannot be null."}

Мне не хватает опции локали или чего-то еще?

#import, setup, authentication related info removed

tenant = deepsecurity.Tenant()
api_version = 'v1'
bypass_tenant_cache = False
confirmation_required = False
asynchronous = False

def create_tenant(client, configuration, api_version, api_exception, account_name):

    # Define the administrator account
    admin = client.Administrator()
    admin.username = "TenantAdmin"
    admin.password = "Pas$w0rd"
    admin.email_address = "example@email.com"
    admin.receive_notifications = "false"
    admin.role_id = 1
    admin.locale = "en_US"

    tenant = client.Tenant(administrator=admin)
    modules = client.Tenant.modules_visible = ["anti-malware", "firewall", "intrusion-prevention"]
    tenant.modules_visible = modules
    tenant.name = 'api-woot'
    tenant.locale = "en-US"
    tenant.description = "Test tenant."

    try:
        tenants_api = client.TenantsApi(client.ApiClient(configuration))
        return tenants_api.create_tenant(tenant, api_version, confirmation_required=False)

    except api_exception as e:
        return "Exception: " + str(e)
try:
        api_response = api_instance.create_tenant(tenant, api_version, bypass_tenant_cache=bypass_tenant_cache, confirmation_required=confirmation_required, asynchronous=asynchronous)
        pprint(api_response)
except ApiException as e:
        print("An exception occurred when calling TenantsApi.create_tenant: %s\n" % e)

Ответы [ 2 ]

0 голосов
/ 20 декабря 2018

Для всех, кто просматривает: Вот мой код, который работает.Сайт API не дал мне достаточно ясности, чтобы добавить переменные для арендатора и администратора, поэтому мне потребовалось некоторое время, чтобы выяснить,

вот две статьи, которые я использовал для справки:

https://automation.deepsecurity.trendmicro.com/article/11_2/api-reference?platform=aws#operation/createTenant

https://automation.deepsecurity.trendmicro.com/article/11_2/create-and-manage-tenants?platform=on-premise

Вам нужно добавить свои собственные элементы настройки и аутентификации вверху, затем:

# Initialization
# Set Any Required Values
api_instance = deepsecurity.TenantsApi(deepsecurity.ApiClient(configuration))
tenant = deepsecurity.Tenant()
tenant.locale = "en-US"
tenant.name = "api-woot"
tenant.description = "test tenant"

admin = deepsecurity.Administrator()
admin.username = "tenantadmin"
admin.role_id = 1
admin.password = "Pas$w0rd"
admin.full_name = "bob admin"
admin.email_address = "a@email.com"
admin.receive_notifications = "false"
tenant.administrator = admin

api_version = 'v1'
bypass_tenant_cache = False
confirmation_required = False
asynchronous = False

try:
        api_response = api_instance.create_tenant(tenant, api_version, bypass_tenant_cache=bypass_tenant_cache, confirmation_required=confirmation_required, asynchronous=asynchronous)
        pprint(api_response)
except ApiException as e:
        print("An exception occurred when calling TenantsApi.create_tenant: %s\n" % e)
0 голосов
/ 18 декабря 2018

Похоже, небольшая проблема с локальными опциями для меня.У вас есть «en_US» (подчеркивание) для локали клиента и «en-US» (тире) для локали администратора.

Исходя из Справочника по API, похоже, что для обоих он должен быть "en-US" (тире).См .: https://automation.deepsecurity.trendmicro.com/article/11_2/api-reference?platform=on-premise#operation/createTenant

Надеюсь, что эта ошибка решит за вас.
(К вашему сведению, я работаю в Trend Micro)

...