IdentityClient.get_user() returns tenancy OCID in compartment_id field - oci-python-sdk

I have a piece of Python code like this:
oci_config = oci.config.from_file("config_file","profile_name")
identity = oci.identity.IdentityClient(oci_config)
user = identity.get_user(oci_config["user"]).data
The user object returned has an attribute "compartment_id" but it has a value of tenancy OCID "ocid1.tenancy.oc1..aaaaaaaa...." which is obviously wrong. I am hoping that I can get compartment ID of user for calling other APIs. Now I have to store it configuration file instead.
My SDK version is 2.18 on Python 3.8.3.
Does any one know where to file a bug report like this?
Thanks

Compartments can be nested under other compartments, and the root compartment is the same as the tenancy. So the root compartment and the tenancy have the same ID.
If you are getting the tenancy ID back in the compartment_id field for a resource, it means the resource is in the root compartment.
You can see the same documented here. As you can see in the image at this link, the tenancy is referred to also as the "root compartment".

Related

Azure AD graph API to filter users with onPremisesExtensionAttributes [extensionAttribute6]

I need to filter users with the onPremisesExtensionAttributes [extensionAttribute6] is there a graph API call for it?
As #Tinywa suggested in the comment:
onPremisesExtensionAttributes contains extensionAttributes 1-15 for
the user. Note that the individual extension attributes are neither
selectable nor filterable.
You can get all the results first and use your own code logic to filter them.
Or you can consider using extensionProperty as a workaround. Create the extensionProperty and assign value for the users, and then query users with filtering with this extensionProperty. For detailed steps to create extensionProperty and assign value for users, you can refer to this answer.
It looks like they've updated the BETA Graph API so that extension attributes (onPremisesExtensionAttributes) are now filterable.
Try the below in Graph Explorer. You'll need to change the extensionAttribute1 eq 'Employee' part to a query that will actually work in your active directory environment.
https://graph.microsoft.com/beta/users?$count=true&$filter=onPremisesExtensionAttributes/extensionAttribute1 eq 'Employee'&$orderBy=displayName&$select=displayName,mail,onPremisesExtensionAttributes
Please note that this is the BETA Graph API so I guess that means Microsoft hasn't finalized it, so it might change or never get fully released.
EDIT: I also just learned that if you're using this filter via the Graph API, you must add the following header or you'll an error:
client.DefaultRequestHeaders.Add("ConsistencyLevel", "eventual");
The Graph Explorer has this header by default, I guess.
Here's where I found this answer: Get Extended Properties on User using Microsoft Graph
Here's the error I was getting:
Property 'extensionAttribute1' does not exist as a declared property or extension property.

Issue in Developing Conceptual Model for My Website

I want to discuss a non-code related issue. Rather it's an issue with the concept or data model itself.
I am building a business directory website using Laravel.
I have made a packages table, implemented packages CRUD functionality for the back-end and implemented a packages list, with sign-up buttons for the front-end. When a sign-up button is pressed, the package ID is passed to the sign-up route.
I have added package_id as a foreign key to the users table. But the issue I have now, is that if a user goes directly to the sign-up route, there is no package ID. I therefore would like to sign the user up for a free package.
I can't use a LIKE query because of dynamic packages and can be changed the name and id as well if free package is deleted and again added and how to handle exception if free package was deleted.
Please help me with better methodology.
As you said using a text search to match records is a bad practise, there are lot of ways to correctly address the problem:
Add a boolean field is_free;
if you want to make it unique make it nullable, unique, and default null but remember the value should be null for non-free or true for the only free package or the unique constraint will fail (the field supports multiple null items but only one true or false)
Get the first package where the price equals to zero
Make a foreign key to package_groups and create a "free" group, a bit over-complicated if you do not need to separate packages into groups
Let's assume your package sign-up route is
/sign-up/{package_id?}
note the "?" after package_id, it tells the parameter may be missing.
The logic if i understood it correctly is :
if the package_id is specified sign-in for the package with that id
if the package_id is null register for a free package
The route should be like this:
Route::get('/sing-up/{package_id?}', 'PackageController#signUp');
And the controller should be doing something like this:
PackageController extends Controller{
//....
public signUp($id=null){
$package=($id==null)?Package::free()->first():Package::findOrFail();
//If $package is null there are currently no active free packages
///sign-up logic here...
}
}
Assuming Package::free() is a scope that filters the free packages, an example:
Package extends model{
//....
function scopeFree($query){
return $query->where('is_free',true); //for option 1.
}
}
When you post user data from sign up route then check if the package ID exists then fine use that otherwise get package ID of your free package and then use that to sign them up with package ID.
This is like saying user cannot sign up without a package ID but where do I get package ID when they come direct on sign up. When you post back you will not get package ID or get null or 0 whatever you have in postback or ajax sign up form. Use that to check if its a valid package ID or not then if its not then obtain ID of your free package (you can use any sql to obtain it from packages table only and once you have ID of free package then start signing up user and insert that ID into database and it wont complain). This way you are covered for both scenarios where no package ID is passed or someone try to send a wrong package ID.

Get instances during serializer validation in DRF

I am starting to work with the Django REST framework for a mini-reddit project I already developed.
The problem is that I am stuck in this situation:
A Minisub is like a subreddit. It has, among others, a field named managers which is ManyToMany with User.
An Ad is an advertising which will be displayed on the minisub, and it has a field named minisubs which is ManyToMany with Minisub. It has also a author field, foreign key with User.
I would like to allow these managers to add some ads on their minisubs through a DRF API. It is actually working. But I want to check that they put in minisubs only minisubs where they are managers.
I found a way like that:
class AdSerializer(serializers.HyperlinkedModelSerializer):
# ...
def validate_minisubs(self, value):
for m in value:
if user not in m.managers.all():
raise serializers.ValidationError("...")
return value
My question is: How to get user ? I can't find a way to get the value Ad.author (this field is set automatically in the serial data according to the user authentication). Maybe I don't find a way because there is no ways ? The place to do this is somewhere else ?
Thanks in advance.
You may get it out of the serializer this way:
class YourModelSeializer(serializers.HyperlinkedModelSerializer):
class Meta:
model=YourModel
def validate_myfield(self):
instance = getattr(self, 'instance', None)
...
I believe that this is a job for the permissions, if you are performing CRUD operations for inserting that into a database then u can have a permission class returns True if the user is a manager.
a permissions instance has access to the request which u can use to get the user and check if he is a manager:
http://www.django-rest-framework.org/api-guide/permissions/#custom-permissions

CouchDB: limit action to logged users

I'm working with validate_doc_update function. I've heard about userCtx, but simply calling log(userCtx); helps no way: there's no records in the log.
How determine in validation is current user logged or not and maybe perform some checks to verify against user rights (which may be made by simple fields like role:editor in _users database)?
The user context is accessible under req.userCtx.
A common check of the loggedIn-status is if (req.userCtx.name !== null)
The access right roles of a user doc are accessible under req.userCtx.roles. The corresponding settings for a doc can be included hard-coded in the validate_doc_update function or in the doc itself.

Retrieve all groups for a member using Google Admin java sdk

I would like to retrieve all groups for a given member.
There is an api interface for this:
https://developers.google.com/admin-sdk/directory/v1/guides/manage-groups#get_all_member_groups
But unfortunately I can't figure out how to do that using java SDK as I was not able to find a method for this.
How can this problem be solved?
You don't need to add methods, you can use Directory.Groups.List and set the userKey parameter, something like
//... imports, initializations etc.
Directory service = new Directory.Builder(httpTransport, jsonFactory,
credential).build();
Groups userGroups = service.groups().list().setUserKey("member#domain.com")
.execute();
Add new method to class com.google.api.services.admin.directory.Directory class to query https://www.googleapis.com/admin/directory/v1/groups?userKey={userKey}. This way you can retrieve the member's groups.

Resources