Skip to content

Commit

Permalink
Merge pull request #138 from sailpoint-oss/feature/pythonStarterCode
Browse files Browse the repository at this point in the history
Add command to initialize python example project
  • Loading branch information
tyler-mairose-sp authored Mar 13, 2024
2 parents 862857c + 1ace987 commit 2eff31a
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/sdk/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func newInitCommand() *cobra.Command {
newTypescriptCommand(),
newGolangCommand(),
newPowerShellCommand(),
newPythonCommand(),
newConfigCommand(),
)

Expand Down
44 changes: 44 additions & 0 deletions cmd/sdk/python.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2023, SailPoint Technologies, Inc. All rights reserved.
package sdk

import (
"embed"

"github.com/sailpoint-oss/sailpoint-cli/internal/initialize"
"github.com/spf13/cobra"
)

//go:embed python/*
var pyTemplateContents embed.FS

const pyTemplateDirName = "python"

func newPythonCommand() *cobra.Command {

cmd := &cobra.Command{
Use: "python",
Short: "Initialize a new python SDK project",
Long: "\nInitialize a new typescript SDK project\n\n",
Example: "sail sdk init python\nsail sdk init py example-project",
Aliases: []string{"py"},
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var projName string
var err error

if len(args) > 0 {
projName = args[0]
} else {
projName = "python-template"
}

err = initialize.InitializeProject(pyTemplateContents, pyTemplateDirName, projName)
if err != nil {
return err
}

return nil
},
}
return cmd
}
1 change: 1 addition & 0 deletions cmd/sdk/python/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sailpoint >= 1.0.0
63 changes: 63 additions & 0 deletions cmd/sdk/python/sdk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import sailpoint
import sailpoint.v3
import sailpoint.beta
from sailpoint.configuration import Configuration
from sailpoint.paginator import Paginator
from sailpoint.v3.models.search import Search
from pprint import pprint

configuration = Configuration()

# Enter a context with an instance of the API client
with sailpoint.v3.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = sailpoint.v3.TransformsApi(api_client)

# List transforms
try:
# List transforms
api_response = api_instance.list_transforms()
print("The response of TransformsApi->list_transforms:\n")
for transform in api_response:
pprint(transform.name)
except Exception as e:
print("Exception when calling TransformsApi->list_transforms: %s\n" % e)

# List Access Profiles
api_instance = sailpoint.v3.AccessProfilesApi(api_client)

try:
api_response = api_instance.list_access_profiles()
print("The response of AccessProfilesApi->list_access_profiles:\n")
for access_profile in api_response:
pprint(access_profile.name)
except Exception as e:
print(
"Exception when calling AccessProfilesApi->list_access_profiles: %s\n" % e
)

# Use the paginator with search

search = Search()
search.indices = ['identities']
search.query = { 'query': '*' }
search.sort = ['-name']

identities = Paginator.paginate_search(sailpoint.v3.SearchApi(api_client),search, 250, 1000)
for identity in identities:
print(identity['name'])



# Use the paginator to paginate 1000 accounts 100 at a time
accounts = Paginator.paginate(sailpoint.v3.AccountsApi(api_client).list_accounts, 1000, limit=100)
print(len(accounts))
for account in accounts:
print(account.name)


with sailpoint.beta.ApiClient(configuration) as api_client:

workgroups = sailpoint.beta.GovernanceGroupsApi(api_client).list_workgroups()
for workgroup in workgroups:
print(workgroup.name)

0 comments on commit 2eff31a

Please sign in to comment.