3

I enabled authentication on my opscenter node as per this . I've a python script that periodically invokes opscenter actions through the Opscenter REST APIs. From the REST API documentation, it looked like all I had to do was invoke these methods with basic HTTP auth (see this). But these calls always failed with a "user must be logged in" error.

After poking around the javascript that runs when I use the opscenter's web frontend, I figured that I must actually invoke the login method to create a session and use that session to invoke other methods, such as:

session = requests.Session()
login_body = '{"username": "%s", "password": "%s"}' % (opsc_uname, opsc_pwd)
login_resp = session.post("http://{url}/login".format(url=opsc_url), data=login_body).json()
clusterconf = session.get("http://{url}/cluster-configs".format(url=opsc_url)).json()

Is the api documentation (that claims to use basic http auth) wrong? Or am I doing something incorrectly? The opscenter version I'm using is 5.1.1

itzmebibin
  • 105
  • 4

2 Answers2

1

You figured it out correctly, OpsCenter 5.1 uses sessions instead of basic auth. You've been looking at 5.0 docs, that's why it wasn't documented. Here's a correct link.

itzmebibin
  • 105
  • 4
arre
  • 281
  • 1
  • 3
0

In addition to the documentation link the user "arre" has posted above when you implement that method ensure you dont include the { } curly braces, so for example use

curl -H 'opscenter-session: d6c5e198b9b5ffeab9fd8dea6fb012aa' http://127.0.0.1:8888/permissions/user

Instead of

curl -H 'opscenter-session: {d6c5e198b9b5ffeab9fd8dea6fb012aa}' http://127.0.0.1:8888/permissions/user
markc
  • 101
  • 2