Python Data Layer scopes

Hi all.

In this example is shown how to create a Data Layer scope for a specific node written in C++: How-to-provide-API-in-the-Data-Layer-for-your-app .

Is there a way to do the exact thing but in Python? I could not find the CreateScopeDirect method in python.

Thank you,

Criss.

Best reply by nickH

Hi Chriss, 

If you take a closer look into the Scope.py you can see, that the permissions in this Flatbuffer are not Strings but Vector of Strings. Here is how I got it working. 

            builder = flatbuffers.Builder(1024)
            permissionsRW = builder.CreateString('test-node/**')
            Scope.StartPermissionsRwVector(builder, 1)
            builder.PrependSOffsetTRelative(permissionsRW)
            permissionsRWVector = builder.EndVector()
            description = builder.CreateString("Allow to read and write")
            name = builder.CreateString("Test-node RW permission")
            identifier = builder.CreateString("datalayer.test-node.rw")

            Scope.ScopeStart(builder)
            Scope.ScopeAddIdentifier(builder, identifier)
            Scope.ScopeAddName(builder, name)
            Scope.ScopeAddDescription(builder, description)
            Scope.ScopeAddPermissionsRw(builder, permissionsRWVector)
   
            scope = Scope.ScopeEnd(builder)
            builder.Finish(scope)

            variant = Variant()
            variant_result = variant.set_flatbuffers(builder.Output())
            if variant_result is not Result.OK:
                print("ERROR: creating variant flatbuffer: ", variant_result, flush=True)
            result, var= datalayer_client.create_sync("datalayer/security/scopes", variant)
            if result is not Result.OK:
                print("ERROR: create scope failed: ", result, flush=True)

 

Best regards, 

Nick

View original
4 replies