packethost / packet-python

A Python client for the Equinix Metal API
http://metal.equinix.com/
GNU Lesser General Public License v3.0
40 stars 50 forks source link

Receiving HTTP 403 errors against api.packet.net #135

Open mristok opened 1 year ago

mristok commented 1 year ago

I am encountering HTTP 403 with a verified valid token against the client package default API endpoint api.packet.net. I suspected that this is due to deprecation of the endpoint in favor of api.equinix.com. Testing with the client endpoint changed (overridden) to api.equinix.com/metal/v1 indeed results is successful API calls with the client, however my testing was fairly limited in scope.

Please review if the api.packet.net endpoint is in fact deprecated, and make all necessary adjustments to account for (if necessary) the new appropriate endpoint.

displague commented 1 year ago

@mristok api.equinix.com should be used, it is used in other integrations including ClusterAPI, Terraform, MetalCLI and the new Ansible Equinix collection.

In the Ansible Equinix collection we are using https://github.com/equinix-labs/metal-python/ (v0.1.0) / https://pypi.org/project/equinix-metal/.

This package is generated from the API spec so it is much more complete than packet-python.

displague commented 1 year ago

Using the following local helper script, I didn't run into problems using api.packet.net:

#!/usr/bin/env bash
# emget: helper to GET Metal API requests. uses Metal CLI for auth defaults.

eval $(metal env)
P="$1"
DATA="$2"
METAL_API_URL="${METAL_API_URL:-https://api.equinix.com/metal/v1}"
CURL_OPT="${CURL_OPT:--s}"

curl ${CURL_OPT} -X GET \
    -H "X-Auth-Token: $METAL_AUTH_TOKEN" \
    -H "Content-Type: application/json" \
    "${METAL_API_URL}/$P" | jq .
$ METAL_API_URL=https://api.packet.net CURL_OPT="-s -v" emget /projects
...
> GET //projects HTTP/2
> Host: api.packet.net
> user-agent: curl/7.87.0
> accept: */*
> x-auth-token: ...
> content-type: application/json
>
* Connection state changed (MAX_CONCURRENT_STREAMS == 256)!
< HTTP/2 200
...
displague commented 1 year ago

All that aside, packet-python should get an update to api.equinix.com/metal/v1 and perhaps an environment variable way to override that ahead of any deprecation.