Merge "Add support for Avi auth token retrieval"
This commit is contained in:
commit
4c6d36cfaa
|
@ -0,0 +1,37 @@
|
|||
# Copyright 2021 VMware, Inc.
|
||||
# All Rights Reserved
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
from unittest import mock
|
||||
|
||||
from vmware_nsxlib.tests.unit.v3.policy import test_resources
|
||||
from vmware_nsxlib.v3.policy import core_defs
|
||||
|
||||
|
||||
class TestAlbAuthTokenProvider(test_resources.NsxPolicyLibTestCase):
|
||||
|
||||
def test_get_avi_lb_auth_token(self):
|
||||
avi_api = self.policy_lib.alb_token_provider
|
||||
with mock.patch.object(self.policy_lib.client, 'update') as update:
|
||||
avi_api.get_avi_lb_auth_token('avi_user')
|
||||
update.assert_called_with('infra/alb-auth-token',
|
||||
{'username': 'avi_user', 'hours': 1})
|
||||
|
||||
def test_get_avi_endpoint_info(self):
|
||||
avi_api = self.policy_lib.alb_token_provider
|
||||
with mock.patch.object(self.policy_lib.client, 'get') as get:
|
||||
avi_api.get_avi_endpoint_info()
|
||||
get.assert_called_with(
|
||||
(core_defs.AVI_ENDPOINT_PATTERN % 'infra'))
|
|
@ -25,6 +25,7 @@ from vmware_nsxlib.v3 import lib
|
|||
from vmware_nsxlib.v3 import nsx_constants
|
||||
from vmware_nsxlib.v3 import utils as lib_utils
|
||||
|
||||
from vmware_nsxlib.v3.policy import alb_auth_token_provider
|
||||
from vmware_nsxlib.v3.policy import core_defs
|
||||
from vmware_nsxlib.v3.policy import core_resources
|
||||
from vmware_nsxlib.v3.policy import ipsec_vpn_resources
|
||||
|
@ -149,6 +150,8 @@ class NsxPolicyLib(lib.NsxLibBase):
|
|||
self.global_config = core_resources.NsxPolicyGlobalConfig(*args)
|
||||
self.object_permission = (
|
||||
core_resources.NsxPolicyObjectRolePermissionGroupApi(*args))
|
||||
self.alb_token_provider = alb_auth_token_provider.AlbAuthTokenProvider(
|
||||
self.client)
|
||||
|
||||
def get_nsxlib_passthrough(self):
|
||||
return self.nsx_api
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
# Copyright 2021 VMware, Inc.
|
||||
# All Rights Reserved
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
from vmware_nsxlib.v3.policy import core_defs
|
||||
|
||||
AVI_AUTH_TOKEN_PATH = "infra/alb-auth-token"
|
||||
|
||||
|
||||
class AlbAuthTokenProvider(object):
|
||||
|
||||
def __init__(self, policy_api):
|
||||
self.policy_api = policy_api
|
||||
|
||||
def get_avi_lb_auth_token(self, username, hours=1):
|
||||
body = {'username': username, 'hours': hours}
|
||||
return self.policy_api.update(AVI_AUTH_TOKEN_PATH, body)
|
||||
|
||||
def get_avi_endpoint_info(self):
|
||||
enforcement_point_path = (core_defs.AVI_ENDPOINT_PATTERN % 'infra')
|
||||
return self.policy_api.get(enforcement_point_path)
|
|
@ -41,6 +41,7 @@ ENFORCEMENT_POINT_PATTERN = (TENANTS_PATH_PATTERN +
|
|||
"sites/default/enforcement-points/")
|
||||
TRANSPORT_ZONE_PATTERN = ENFORCEMENT_POINT_PATTERN + "%s/transport-zones/"
|
||||
EDGE_CLUSTER_PATTERN = ENFORCEMENT_POINT_PATTERN + "%s/edge-clusters/"
|
||||
AVI_ENDPOINT_PATTERN = ENFORCEMENT_POINT_PATTERN + "alb-endpoint"
|
||||
|
||||
SEGMENT_SECURITY_PROFILES_PATH_PATTERN = (TENANTS_PATH_PATTERN +
|
||||
"segment-security-profiles/")
|
||||
|
|
Loading…
Reference in New Issue