Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with event hub authenticate #36

Open
BLaurent opened this issue Jun 25, 2018 · 5 comments
Open

Issue with event hub authenticate #36

BLaurent opened this issue Jun 25, 2018 · 5 comments

Comments

@BLaurent
Copy link
Contributor

BLaurent commented Jun 25, 2018

Hi, I've apply the patch from @ThisWillGoWell,
But I am stuck just after..
Here is the sample code I am using:

Exception in thread Thread-25:
Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/Users/laurentbenoit/.local/share/virtualenvs/result-poster-JQntJH7S/lib/python2.7/site-packages/predix/data/eventhub/grpc_manager.py", line 49, in _grpc_rx_receiver
    for m in msgs:
  File "/Users/laurentbenoit/.local/share/virtualenvs/result-poster-JQntJH7S/lib/python2.7/site-packages/grpc/_channel.py", line 351, in next
    return self._next()
  File "/Users/laurentbenoit/.local/share/virtualenvs/result-poster-JQntJH7S/lib/python2.7/site-packages/grpc/_channel.py", line 342, in _next
    raise self
_Rendezvous: <_Rendezvous of RPC that terminated with (StatusCode.UNKNOWN, Could not authenticate request)>
import json
import requests
import os
import fnmatch
import logging

import predix.app
from predix.data.eventhub.publisher import PublisherConfig


matches = []

for root, dirnames, filenames in os.walk('../'):
  for filename in fnmatch.filter(filenames, 'env.json'):
    matches.append(os.path.join(root, filename))


if len(matches) == 1:
  with open(matches[0], 'r') as config :
    readConfig = config.read()
    print readConfig
    jconfig = json.loads(readConfig)

    print jconfig
    target = jconfig['target']

jservices = {}
services = os.getenv('VCAP_SERVICES')
if services != None :
  jservices = json.loads(services)

jservices['predix-event-hub'] = jconfig['predix-event-hub']
jservices['predix-uaa'] = jconfig['predix-uaa']

os.environ['VCAP_SERVICES'] = json.dumps(jservices)
os.environ['PREDIX_APP_CLIENT_ID'] = jconfig['credentials']['PREDIX_APP_CLIENT_ID']
os.environ['PREDIX_APP_CLIENT_SECRET'] = jconfig['credentials']['PREDIX_APP_CLIENT_SECRET']

logging.basicConfig(level=logging.DEBUG)
app = predix.app.Manifest()
pub_config = PublisherConfig()
pub_config.publish_type = PublisherConfig.Type.SYNC

uaa = app.get_uaa()
client_id = predix.config.get_env_value(predix.app.Manifest, 'client_id')
client_secret = predix.config.get_env_value(predix.app.Manifest, 'client_secret')
if client_id and client_secret:
  logging.info("Automatically authenticated as %s" % (client_id))
  uaa.authenticate(client_id, client_secret)

print(uaa.get_scopes())


eh = app.get_eventhub(publish_config=pub_config)

count = 0
message_id = "id-" + str(count)

acks = eh.publisher.add_message(message_id, str(count)).publish_queue()
print(acks)

The service is up I am getting the health ping, and my token is ok, both sub and pub test in golang work.

Thanks in advance
Regards
B

@ThisWillGoWell
Copy link

Looking into it now

@ThisWillGoWell
Copy link

Can you post your admin code?

@BLaurent
Copy link
Contributor Author

You mean client and service creation ?

@BLaurent
Copy link
Contributor Author

BLaurent commented Jun 26, 2018

I am using this client:

 {
  "client_id": "event-hub-client",
  "scope": [
   "uaa.none"
  ],
  "resource_ids": [
   "none"
  ],
  "authorized_grant_types": [
   "client_credentials"
  ],
  "authorities": [
   "predix-event-hub.zones.af591838-8d22-474d-bcea-0953cc9d2ca0.user",
   "predix-event-hub.zones.af591838-8d22-474d-bcea-0953cc9d2ca0.topic.grpc.subscribe",
   "predix-event-hub.zones.af591838-8d22-474d-bcea-0953cc9d2ca0.grpc.subscribe",
   "uaa.resource",
   "predix-event-hub.zones.af591838-8d22-474d-bcea-0953cc9d2ca0.wss.publish",
   "predix-event-hub.zones.af591838-8d22-474d-bcea-0953cc9d2ca0.grpc.publish"
  ],
  "allowedproviders": [
   "uaa"
  ],
  "access_token_validity": 3000
 },

@BLaurent
Copy link
Contributor Author

BLaurent commented Jun 26, 2018

Also in VCAP, event-hub protocol_details is an array, I think the parser get confused

instead of

services['predix-event-hub'][0]['credentials']['publish']['protocol_details']['uri']

it should be I think
services['predix-event-hub'][0]['credentials']['publish']['protocol_details'][0]['uri']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants