3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 class UserGen(object):
20 def __init__(self, roles_len):
21 self._roles_len = roles_len
24 def create_username(self, roles):
27 if len(roles) == self._roles_len:
29 return next(self._get_user_gen(sorted(roles)[0]))
31 def _get_user_gen(self, base):
32 if base not in self._usergens:
33 self._usergens[base] = self._user_gen(base)
34 return self._usergens[base]
38 for idx in itertools.count(): # pragma: no branch
39 yield '{base}{idx}'.format(base=base, idx=idx)