Ocean Chang
11/08/2024, 2:23 AMv1/auth/login
API call or the Client
from SDK. They are successful with 200. Login API call returns the token
and token_expiration
However, when subsequently trying to call /api/v1/repositories
, I m getting 401 error authenticating request
Question: Do I need to attach the login token being returned in order to make subsequent calls? If so, how?Ocean Chang
11/08/2024, 2:28 AMdef login_to_lakefs():
"""Authenticate with LakeFS and return the access token and response."""
login_url = "<https://url/api/v1/auth/login>"
credentials = {
"access_key_id": "xxx",
"secret_access_key": "yyy"
}
try:
response = <http://requests.post|requests.post>(login_url, json=credentials)
...
def get_repositories(access_token):
"""Fetch repositories using the provided access token."""
repos_url = "<https://lakefs.us-east-1.devfangmik.data-catalog.nile.amazon.dev/api/v1/repositories>"
# How do I attach the login token as header here????
headers = {
"Authorization": f"Bearer {access_token}"
}
try:
<http://st.info|st.info>("Fetching repositories...")
response = requests.get(repos_url, headers=headers)
Ocean Chang
11/08/2024, 2:30 AMimport streamlit as st
import lakefs
from lakefs.client import Client
def initialize_lakefs_client():
"""Initialize the lakeFS client with credentials."""
try:
client = Client(
host="<https://url>",
username="xxx",
password="yyy"
)
return client
except Exception as e:
st.error(f"Failed to initialize lakeFS client: {str(e)}")
return None
def main():
st.title("LakeFS Repository Explorer")
# Initialize client
with st.spinner("Connecting to LakeFS..."):
client = initialize_lakefs_client()
if client:
st.success("Successfully connected to LakeFS!")
try:
# List repositories
st.subheader("Available Repositories")
<http://st.info|st.info>(f"repo call resp: {lakefs.repositories(client=client)}")
repos = list(lakefs.repositories(client=client))
Itai Admi
11/08/2024, 6:31 AMMike Fang
11/08/2024, 7:15 AMMike Fang
11/08/2024, 7:19 AMtime="2024-11-08T06:09:27Z" level=info msg="Failed to authenticate user" func=pkg/auth.ChainAuthenticator.AuthenticateUser file="lakeFS/pkg/auth/authenticator.go:43" error="1 error occurred:\n\t* built in authenticator: credentials not found\n\n" host=lakefs.us-east-1.data-catalog.test.dev method=GET operation_id=GetRepository path=/api/v1/repositories/test username="mO%B?&_[=P96+/xl-R-b(0id{"
time="2024-11-08T06:09:27Z" level=error msg=authenticate func=pkg/api.userByAuth file="lakeFS/pkg/api/auth_middleware.go:409" error="1 error occurred:\n\t* built in authenticator: credentials not found\n\n" host=lakefs.us-east-1.data-catalog.test.dev method=GET operation_id=GetRepository path=/api/v1/repositories/test service=api_gateway user="mO%B?&_[=P96+/xl-R-b(0id{"
Itai Admi
11/08/2024, 7:20 AMMike Fang
11/08/2024, 7:21 AMMike Fang
11/08/2024, 7:21 AMlogging.info("Checking LakeFS Setup State")
internal_api = lakefs_sdk.InternalApi(api)
setup_state = internal_api.get_setup_state()
logging.info(f"The current state of the LakeFS instance is {setup_state}")
if setup_state.state == "not_initialized":
logging.info(f"LakeFS not initialized, setting up initial LakeFS Admin Account")
setup_params = lakefs_sdk.Setup.from_dict({
"username": "admin",
"key": {
"access_key_id": helper.download_secret_value(os.environ.get("LAKEFS_ADMIN_ACCESS_KEY_ID_SECRET_ARN")),
"secret_access_key": helper.download_secret_value(os.environ.get("LAKEFS_ADMIN_SECRET_KEY_ID_SECRET_ARN"))
}
})
setup_response = internal_api.setup(setup_params)
logging.info(f"The setup was successful: {setup_response}")
Itai Admi
11/08/2024, 7:27 AMItai Admi
11/08/2024, 7:30 AMMike Fang
11/08/2024, 7:30 AMMike Fang
11/08/2024, 7:32 AMINFO:root:The
setup was successful:
access_key_id='^K1y:.Il&_bfd_,k;\\V12P3Rg3&S9Je+'
secret_access_key='#eN_ry5$v~L^R*8mGp)!p5lSc=yZ"\'M|'
creation_date=1730914328
Itai Admi
11/08/2024, 7:34 AMOk so if I pass nothing to the setup endpoint lakeFS will autogenerate in the default format?Yes
Itai Admi
11/08/2024, 7:34 AM'
near the end.Mike Fang
11/08/2024, 7:35 AMOcean Chang
11/08/2024, 8:05 AMAuthorization: Basic <base64 encoded access_key_id:secret_access_key>
Mike Fang
11/08/2024, 8:29 AMOcean Chang
11/08/2024, 8:32 AMimport lakefs
from lakefs.client import Client
clt = Client(
host="<http://localhost:8000>",
username="AKIAIOSFODNN7EXAMPLE",
password="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
)
lakefs.repositories():
still getting 401 error from the lakefs.repositories():
Itai Admi
11/08/2024, 8:38 AMOcean Chang
11/08/2024, 8:41 AMcredentials = f"{access_key_id}:{secret_access_key}"
encoded_credentials = base64.b64encode(credentials.encode('utf-8')).decode('utf-8')
Ocean Chang
11/08/2024, 8:48 AMimport lakefs_client
from lakefs_client.client import LakeFSClient
lakefs_config = lakefs_client.Configuration()
lakefs_config.username = 'xxx'
lakefs_config.password = 'yyy'
lakefs_config.host = 'host url'
lakefs = LakeFSClient(lakefs_config)
lakefs_api_client = lakefs_client.ApiClient(lakefs_config)
repo=lakefs.repositories.list_repositories().results[0]
UnauthorizedException: (401) Reason: Unauthorized HTTP response headers: HTTPHeaderDict({'Date': 'Fri, 08 Nov 2024 08:45:42 GMT', 'Content-Type': 'application/json', 'Content-Length': '43', 'Connection': 'keep-alive', 'X-Content-Type-Options': 'nosniff', 'X-Request-Id': 'xxx'}) HTTP response body: {"message":"error authenticating request"}
Itai Admi
11/08/2024, 8:50 AMIddo Avneri
11/08/2024, 2:34 PMMike Fang
11/08/2024, 4:02 PM