okta / okta-sdk-python

Apache License 2.0
234 stars 143 forks source link

Support ResourceSet - api/v1/iam/resource-sets #340

Closed exitcode0 closed 1 year ago

exitcode0 commented 1 year ago

the api/v1/iam/resource-sets API is a part of the Okta open API spec but has yet to be implemented into this SDK

gabrielsroka commented 1 year ago

some code u can run on your own (https://github.com/okta/okta-sdk-python/#call-other-api-endpoints)

import okta.client
import asyncio

async def main():
    # `async with` reuses the session, so it's much faster.
    async with Client() as client:
        async for resource_set in client.list_resource_sets():
            async for resource in client.list_resources(resource_set['id']):
                print(resource_set['label'], resource['orn'])

class Client(okta.client.Client):
    """A thin wrapper around the Okta SDK."""

    async def list_resource_sets(self):
        # see https://developer.okta.com/docs/reference/api/roles
        async for resource_set in self.get_iam_objects('/api/v1/iam/resource-sets', 'resource-sets'):
            yield resource_set

    async def list_resources(self, id):
        # see https://developer.okta.com/docs/reference/api/roles
        async for resource in self.get_iam_objects('/api/v1/iam/resource-sets/' + id + '/resources', 'resources'):
            yield resource

    async def get_iam_objects(self, url, key):
        # see https://github.com/okta/okta-sdk-python/#call-other-api-endpoints
        while url:
            exec = self.get_request_executor()
            req, _ = await exec.create_request('get', url)
            resp, _ = await exec.execute(req)
            page = resp.get_body()
            for obj in page[key]:
                yield obj
            url = page.get('_links', {}).get('next', {}).get('href')

asyncio.run(main())
bretterer commented 1 year ago

This endpoint was introduced in our Open API Spec v3. Currently, there are no plans to upgrade Python SDK to v3.

You can however use a tool such as openapi-generator.tech (our recommended OASv3 generator tooling) to build a custom SDK in Python.

exitcode0 commented 1 year ago

Hey @bretterer.

there are no plans to upgrade Python SDK to v3.

Any chance you can expand upon this?

Is this limited to the Python SDK or are all Okta SDKs not planning to support the Open API Spec v3? Was the Open API Spec v3 not intended for use with the SDks was it created for consumption by a different audience?

Having this API available natively is more of a want rather than a need for me That said, If the Open API Spec v3 will be supported in other SDKs, i'm happy to switch to using another 😄

bretterer commented 1 year ago

@exitcode0 currently, we have migrated our .NET, Java, and Golang SDK's to OASv3. As I mentioned, we do not have current plans to upgrade Python to this version.

We will be opening up the v3 spec into NPM in the future to allow for developers to build their own SDK with our spec. We recommend using openapi-generator.tech for doing this as this is the platform we use for our other languages.

gabrielsroka commented 1 year ago

https://github.com/okta/okta-sdk-python/issues/375