Wlst how to assign output of listAppStripes() to grantAppRole()
Question: I'm new to Python and WLST. I'm trying to write a Python script that retrieves
the the Application Stripes for a deployed application and assigned it to
appStripes values in the grantAppRole.

For example:

  1. Connect to Admin Server
  2. Deploy the new application
  3. Determine the new application stripes for the deployed application listAppStripes()

Example:

    
    
    wls:/myapp_domain/serverRuntime> listAppStripes()
    
    MyApp#V14.1.0.0.17-b585_APP_75.111.73
    wls:/myapp_domain/serverRuntime>
    

  4. GrantAppRole permission. I need to be able to pass the Application Stripe output from Step #3 to this next command:
    
        grantAppRole(appStripe="MyApp#V14.1.0.0.17-b585_APP_75.111.73",appRoleName="ROLE_USER",principalClass="weblogic.security.principal.WLSGroupImpl",principalName="LDAP_ROLE_PROD",forceValidate="false")
    

Any feedback will be greatly appreciated!


Answer: Try storing the value in a variable and then using that variable in the
`grantAppRole()` function call -

    
    
    app_stripes = listAppStripes()
    

I think this might be returning an array , so try using `app_stripes[0]` , to
get the first element. You can test it out, what is the exact value returned
and use that accordingly.

    
    
    grantAppRole(appStripe=app_stripes[0],appRoleName="ROLE_USER",principalClass="weblogic.security.principal.WLSGroupImpl",principalName="LDAP_ROLE_PROD",forceValidate="false")
    

* * *

Seems like `listAppStripes()` is just printing the values and not returning
the value.

You can do one thing, which is to redirect the `stdout` to a string buffer
just before running the`listAppStripes()` , and then correctly redirect it
back. and then get your value from the string buffer. Example -

    
    
    from cStringIO import StringIO
    import sys
    oldstdout = sys.stdout
    sys.stdout = mystdout = StringIO()
    listAppStripes()
    sys.stdout = oldstdout
    app_stripes=mystdout.getvalue()
    app_stripes = app_stripes.replace('wls:/myapp_domain/domainRuntime> ','').strip().split()
    

After this, `app_stripes` would be a list of all the stripes , and you can use
the method given in the start to call `grantAppRole()` .

