Jira-Python project key - python

I'm using jira-python to access jira projects.
I'm trying to pass a numeric key (which is not the project id) as a parameter.
myProject = jira.project("100")
However, I get the following error:
response text = {"errorMessages":["No project could be found with id '100'."],"errors":{}}
I'm not trying to pass an id, so is there a way to differentiate between a numeric key and an id.
I was doing some testing and it seems like an alphanumeric key is accepted e.g. key = Test1

According to Jira Rest API documentation, Jira client always expects to receive a projectIdOrKey parameter as string. And it seems so, that the only way for it to determine, whether a Project Key or a Project ID was passed, is to check whether a string is numeric or not. That would mean that there is no way for Jira to recognise that you are using a Project Key instead of a Project ID, if you are passing a numerical value.
I checked that the source code of Jira API client in Python does indeed convert any input into string. Unfortunately, I can't check whether Jira API server indeed decides on whether it received an ID or a key in a way I suppose it does because it is not open source.
If my hypothesis is correct, then the only solution would seem to be not to use numerical values as project keys, instead always using a key that contains letters as well.

You could not create a project in Jira with the key beginning with the number.
Project keys must start with an uppercase letter, followed by one or more uppercase alphanumeric characters.
https://support.atlassian.com/jira-work-management/docs/work-with-issues-in-jira-cloud/#Workingwithissues-Projectkeys
Project admins can create and assign their project's key when they create a new project. Based on the project's name, Jira suggests a recognizable key. If you're a project admin, you can customize this while creating a project by selecting Advanced options. You can also update it in the project's settings. They must be at least 2 characters long and start with an uppercase letter. Read more about editing a project's details.

Related

How do I extract only the key from a Google Cloud Datastore entity

I am working on a project using the gcloud cli tools. I am using Python + Flask for developing the application. My main reference points have been the Google Datastore documentation as well this How-to tutorial guide.
I have some entities in my Datastore and these entities have some properties. Entities are created in the application, with the Key set to the default Key (a.k.a incomplete key).
I am able to access the entities alright. And using projection, I can also access the properties of each entity. However, is there a way to only extract the Key from an entity? Example:
>>> print(list(user_query.fetch()))
[<Entity('User', 5097358505279488) {...}>]
This works alright when I want to access the properties. However, I cannot access the key 509... I have also tried:
>>> for user in user_query.fetch():
print(user.key)
...
>>> <Key('User', 5097358505279488), project=...>
While it returns the whole Key object, I couldn't find a way to extract only the key. I have scoured the documentation for a solution, but it hasn't returned anything so. I am wondering if this is even possible at this point.
It sounds like you are trying to get a projection of key.id. Unfortunately, this is not possible. You can do a keys-only query that returns the keys, then you can use a list comprehension to get the data you want, e.g. [key.id_or_name for key in key_only_query.fetch_page()]
You use this to get id
print(user.key.id)
You can call the .id property on a datastore entity to get the key as an integer value.
for user in user_query.fetch():
print(user.id)

How to check if an specific Grakn instance already exists before trying to insert it into the KG?

Let's assume that a Grakn KG contains entities of type 'product' and that they are uniquely identified by the key 'id_prod'. As I understand it, the attempt to insert an instance of product with a repeated id_prod will generate an error.
Assuming that the insertion is being done through a console script, how could the previous existence of the instance be checked with graql during the insertion? And via the python client, are there any special recommendations or patterns to follow?
Your assertion is correct. At present Graql doesn't have a PUT behaviour built-in that would check for existence and insert only if not present. This is a feature that should be included in the future (I work at Grakn).
Instead, you have broadly two options:
You match for concepts by their keys. If there are no results then you insert them. Then you can match insert for the keyed concepts to add relations to them etc.
You first ensure that you've inserted all of the keyed concepts into the KB (may not be possible). You then make the match insert queries directly, matching for the keyed concepts, with no need for checking the keys exist

How to protect program with unique licence key on python?

I need to set key on my program, which would be an exe file. I want to see:
User clicks on exe file then program requers key, user paste the key and key never asks again. User can't send this acivated exe to other users also other users can't use this key again.
or suggest better idea.
p. c. exe file is console app
You can for instance use the platform module to (almost) uniquely identify a machine. They key can then be the sha256 hexdigest of this identifier viewed as a string, like this:
import hashlib
import platform
# Only an example, you can add whatever you want provided by the platform module to identify the machine
identifier = platform.platform()
key = hashlib.sha256(identifier.encode()).hexdigest()
Pros:
Can't be shared
Isn't reusable
Cons:
Doesn't respect Kerchkoff's principle
Hence, it means that your system is secure as long as the user does not know how to compute the identifier by themselves.
You can ellaborate on this model, using maybe a server of your own. For instance, you can compute a key on your server using the identifier you computed and a secret string.
Pros:
You don't have to store a random key for each user, you just need to have access to its identifier
Cons:
If your identifier isn't accurate enough, two users may have the same key
To solve this problem, you can define a random string for each user that you append to their identifier, but it means that you have to store this random string for each user.
Note also that the last two solutions make use of an external server. Hence, you assume that you will be able to do network requests.

Unique URL generator for Object Items or hiding ID from URL parameter

I am working on an application built using Python3 and Django that generates PDFs (via HTML) using filled fields from a data model.
I've created a URL function that takes a value of document ID and type, and then generates a PDF of that document.
What I want to do is to email clients a link that contains that URL function with a specific document ID, however, the problem that I'm facing is that the generated URL has the document ID in the URL parameter, and this is terrible for security purposes as all they can do is change ID number on URL and get access to a different document (that they are not supposed to see)
My questions are:
A- Is there a way to create a unique link for every generated PDF that I can send to clients?
B- Would it be better to create another field in the model of a randomly generated 15 character value, that I use instead of the ID in the parameter?
Ok so I have fixed it by doing the following:
1- UUID was definetly the way, thank you #Toan Quoc Ho for that suggestion. I have added a UUID field to each of the models,
2- Because I wanted to keep my PK as ID, I had the problem of generating unique UUID fields of existing documents. So I followed this solution, and it worked magically. Only thing to note is that there can be no traffic when applying these changes, otherwise the database will crash, be aware.
3- I, then, used the UUID together with ID to determine documents and passed them as URL parameters using regex as (\d+)/([\w-]+)
Voila, that did exactly what I wanted. No two documents share the same UUID, and vice-versa. I could generate a link unique to each document, and block any other access.
I would use the new secrets module available in Python 3.6+. Here is an example:
from secrets import token_urlsafe
random_string = token_urlsafe(16)
print(random_string)
The result would be something like this - nslhgo0dYowR6CvMDEwC_A.

django cache key naming

I want to store some items using Django cache API. Are there are best practices to follow while naming the key. I know some people just give user name as the key. But I am going to cache various items in different views and having the same key every where is not feasible. I was thinking on may be giving a key with username+ 'some view specific' so that the key can be unique.
Does any one have any other good suggestions for generating keys?
Generation of keys can depend on what you are tying to achieve.
Is what the user is trying to access for that user only?
Is what the user is trying to access generic for all the users?
e.g.
let's say you are trying to access a url:
http://yourserver/endpoint/?filter1=value1&filter2=value2
In the above case, you can use the query params filter1=value1&filter2=value2 to create a cached key (by generating the md5 hash).
Considering the two options earlier, if the view should return some data specific to the user then you can also append the user id to create a unique key for the user.
Another example could be a url like this, where one is trying to access all the articles from source 1:
http://yourserver/source/1/articles/?filter1=value1&filter2=value2
In this case it might also be useful to append the cache key with the source id (so this uses the context data for the views in generating the keys).

Categories

Resources