Ejemplo n.º 1
0
 def login(self, team: str, username: str, passwd: str):
     login_url = self.routes.login()
     request_builder = AuthenticatedRequestBuilder(
         basic_auth_username=username,
         basic_auth_passwd=passwd,
         verify_ssl=self.verify_ssl)
     response = request_builder.get(login_url, return_type='json')
     self.auth_token = response['value']
     self.team = team
     self.request_builder = AuthenticatedRequestBuilder(
         auth_token=self.auth_token, verify_ssl=self.verify_ssl)
     return self.auth_token
Ejemplo n.º 2
0
def from_cfg(concourse_cfg: ConcourseConfig, team_name: str, verify_ssl=False):
    '''
    Factory method to get Concourse API object
    '''
    base_url = concourse_cfg.ingress_url()
    team_credentials = concourse_cfg.team_credentials(team_name)
    team_name = team_credentials.teamname()
    username = team_credentials.username()
    password = team_credentials.passwd()
    concourse_version = concourse_cfg.concourse_version()

    if concourse_version is ConcourseApiVersion.V4:
        routes = ConcourseApiRoutesV4(base_url=base_url, team=team_name)
        request_builder = AuthenticatedRequestBuilder(
            basic_auth_username=AUTH_TOKEN_REQUEST_USER,
            basic_auth_passwd=AUTH_TOKEN_REQUEST_PWD,
            verify_ssl=verify_ssl)
        concourse_api = ConcourseApiV4(
            routes=routes,
            request_builder=request_builder,
            verify_ssl=verify_ssl,
        )
    else:
        raise NotImplementedError("Concourse version {v} not supported".format(
            v=concourse_version.value))

    concourse_api.login(
        username=username,
        passwd=password,
    )
    return concourse_api
Ejemplo n.º 3
0
 def login(self, username: str, passwd: str):
     login_url = self.routes.login()
     form_data = "grant_type=password&password="******"&scope=openid+profile+email+federated%3Aid+groups&username="******"content-type": "application/x-www-form-urlencoded"})
     auth_token = response.json()['access_token']
     self.request_builder = AuthenticatedRequestBuilder(
         auth_token=auth_token, verify_ssl=self.verify_ssl)
     return auth_token
Ejemplo n.º 4
0
    def __init__(self, api_routes, basic_credentials, tls_verify=False):
        self._routes = not_none(api_routes)
        self._credentials = not_none(basic_credentials)
        self._auth = (basic_credentials.username(), basic_credentials.passwd())
        self._request_builder = AuthenticatedRequestBuilder(
            basic_auth_username=basic_credentials.username(),
            basic_auth_passwd=basic_credentials.passwd(),
            verify_ssl=tls_verify)

        self._get = partial(requests.get, verify=tls_verify)
        self._post = partial(requests.post, verify=tls_verify)
        self._put = partial(requests.put, verify=tls_verify)
Ejemplo n.º 5
0
    def login(self, username: str, passwd: str):
        login_url = self.routes.login()
        form_data = {
            'grant_type': 'password',
            'password': passwd,
            'scope': 'openid profile email federated:id groups',
            'username': username,
        }

        response = requests.post(
            url=login_url,
            data=form_data,
            auth=(AUTH_TOKEN_REQUEST_USER, AUTH_TOKEN_REQUEST_PWD),
            headers={'content-type': 'application/x-www-form-urlencoded'})
        auth_token = response.json()[self.AUTH_TOKEN_ATTRIBUTE_NAME]
        self.request_builder = AuthenticatedRequestBuilder(
            auth_token=auth_token, verify_ssl=self.verify_ssl)
        return auth_token
Ejemplo n.º 6
0
    def create_api(
        base_url: str,
        team_name: str,
        verify_ssl: str,
        concourse_api_version: ConcourseApiVersion,
    ):
        # disable logging output for now (breaks template in lss)
        # logger.info(f'created client w/ {base_url=}')

        request_builder = AuthenticatedRequestBuilder(
            basic_auth_username=AUTH_TOKEN_REQUEST_USER,
            basic_auth_passwd=AUTH_TOKEN_REQUEST_PWD,
            verify_ssl=verify_ssl)

        if concourse_api_version is ConcourseApiVersion.V5:
            routes = ConcourseApiRoutesV5(base_url=base_url, team=team_name)
            return ConcourseApiV5(
                routes=routes,
                request_builder=request_builder,
                verify_ssl=verify_ssl,
            )
        elif concourse_api_version is ConcourseApiVersion.V6_3_0:
            routes = ConcourseApiRoutesV6_3_0(base_url=base_url,
                                              team=team_name)
            return ConcourseApiV6_3_0(
                routes=routes,
                request_builder=request_builder,
                verify_ssl=verify_ssl,
            )
        elif concourse_api_version is ConcourseApiVersion.V6_5_1:
            routes = ConcourseApiRoutesV6_3_0(base_url=base_url,
                                              team=team_name)
            return ConcourseApiV6_5_1(
                routes=routes,
                request_builder=request_builder,
                verify_ssl=verify_ssl,
            )
        else:
            raise NotImplementedError(
                "Concourse version {v} not supported".format(
                    v=concourse_api_version.value))