I am currently trying to write a revocation registry definition (revRegDef) to a Hyperledger Indy pool as shown in the Indy Getting Started.
The workflow is like this:
create a schema
using the schemaId, create a credential definition (credDef)
using the credDefId, create a revRegDef
Since I need to use Java, i added the appropriate requests to the ledger to the Java Sample, i uploaded my modified version here.
Creating the schema and credDef works fine, but when I send the last request, i get the following error message:
reason -> client request invalid: InvalidClientRequest("Format of credDefId field is not acceptable.
Expected: 'did:marker:signature_type:schema_ref' or 'did:marker:signature_type:schema_ref:tag'",)
At this point, the mentioned credDefId looks like this: Th7MpTaRZVRYnPiabds81Y:3:CL:Th7MpTaRZVRYnPiabds81Y:2:gvt:1.0:Tag1
while the schemaId is Th7MpTaRZVRYnPiabds81Y:2:gvt:1.0
Obviously the mentioned pattern is not met, but the Ledger.buildCredDefReq() function returns the credDefId like this, so i would expect it to be correct.
Edit: while my old answer worked, it only was a workaround and complete bs.. the following should be the correct way of creating credential schema, credential definition and revocation registry definition.
// Create Credential Schema
String name = "schema_name";
String schemaAttrs = new JSONArray().put("name").put("age").toString();
AnoncredsResults.IssuerCreateSchemaResult schema =
Anoncreds.issuerCreateSchema(verinym, name, "1.0", schemaAttrs).get();
String schemaId = schema.getSchemaId();
String schemaJson = schema.getSchemaJson();
JSONObject schemaRes = new JSONObject(Ledger.signAndSubmitRequest(PoolUtils.getInstance(), wallet, verinym,
Ledger.buildSchemaRequest(verinym, schemaJson).get()
).get());
int schemaSeqNo = schemaRes.getJSONObject("result").getJSONObject("txnMetadata").getInt("seqNo");
schemaJson = new JSONObject(schemaJson).put("seqNo", schemaSeqNo).toString();
// Create Credential Definition
AnoncredsResults.IssuerCreateAndStoreCredentialDefResult credDef =
Anoncreds.issuerCreateAndStoreCredentialDef(
wallet, verinym, schemaJson, "tag", null,
new JSONObject().put("support_revocation", true).toString()
).get();
// creating credDef req and sending it to the ledger
JSONObject credDefRes = new JSONObject(
Ledger.signAndSubmitRequest(
PoolUtils.getInstance(), wallet, verinym,
Ledger.buildCredDefRequest(verinym, credDef.getCredDefJson()).get()
).get()
);
int credSeqNo = credDefRes.getJSONObject("result").getJSONObject("txnMetadata").getInt("seqNo");
// Create Revocation Registry Definition
String tailsWriterConfig = new JSONObject().put("base_dir", "/tmp/indy_tails").put("uri_pattern", "").toString();
BlobStorageWriter tails = BlobStorageWriter.openWriter("default", tailsWriterConfig).get();
AnoncredsResults.IssuerCreateAndStoreRevocRegResult revocRegDef = Anoncreds.issuerCreateAndStoreRevocReg(
wallet, verinym, null, "contractDef", credDefId,
"{}", tails
).get();
JSONObject revocRegDefRes = new JSONObject(
Ledger.signAndSubmitRequest(PoolUtils.getInstance(), wallet, verinym,
Ledger.buildRevocRegDefRequest(verinym, revocRegDef.getRevRegDefJson()).get()
).get());
revocRegDefSeqNo = revocRegDefRes.getJSONObject("result").getJSONObject("txnMetadata").getInt("seqNo");
The learning is that the ledger returns important values for the creation of definition
Furthermore, nowhere was mentioned that you need to create an initial revocation registry entry:
// Create initial revocation entry
JSONObject revocRegEntryRes = new JSONObject(Ledger.signAndSubmitRequest(PoolUtils.getInstance(), wallet, verinym,
Ledger.buildRevocRegEntryRequest(verinym, revocRegDef.getRevRegId(),
"CL_ACCUM", revocRegDef.getRevRegEntryJson()).get()).get());
Related
I'm new to DynamoDB and was following tutorial to implement basic CRUD operations.
I have the below code
public static void main(String ... args) throws Exception {
//1. create client
client = AmazonDynamoDBClientBuilder.standard()
.withRegion(Regions.US_EAST_1)
.build();
//2. Create table
String jobID="8aee43e5c44212040529fe11000117cdd0cb77eb";
PutItemSpec putItemSpec = new PutItemSpec();
putItemSpec.withItem(new Item().withPrimaryKey("jobid", jobID ).
withString("type", "first").withBoolean("cancel", false));
PutItemOutcome putItemOutcome = table.putItem(putItemSpec);
System.out.println(putItemOutcome);
//3. Read
GetItemSpec spec = new GetItemSpec().withPrimaryKey("jobid", jobID);
Item item = table.getItem(spec);
System.out.println(item);
//4.Update boolean
UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey("jobid", jobID)
.withUpdateExpression("set cancel=:s")
.withValueMap(new ValueMap().withBoolean(":s",true));
UpdateItemOutcome updateItemOutcome = table.updateItem(updateItemSpec);
//4. read updated bool
item = table.getItem(spec);
System.out.println(item);
//5. update String breaks
UpdateItemSpec updateItemSpec2 = new UpdateItemSpec().withPrimaryKey("jobid", jobID)
.withUpdateExpression("set type=:s")
.withValueMap(new ValueMap().withString(":s","updated"));
UpdateItemOutcome updateItemOutcome2 = table.updateItem(updateItemSpec2);
//4. read updated bool
item = table.getItem(spec);
System.out.println(item);
}}
In this code, Create works fine and getItem fetches the data. When I updated the cancel boolean column it works fine and returns the updated Item. However, when I try to update the String column type to different value it throws the following exception.
Exception in thread "main" com.amazonaws.AmazonServiceException: Unable to unmarshall exception response with the unmarshallers provided (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: 4RHDOGACM1MOADU4N8RUPFMUJBVV4KQNSO5AEMVJF66Q9ASUAAJG; Proxy: null)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1862)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleServiceErrorResponse(AmazonHttpClient.java:1415)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1384)
The AWS-SDK-Version is 1.12.153 and JDK Version is 17.0.1. Also, when I add new string column type2 as part of the update and update it with another call it works. But, String column added as part of create is not getting updated.
Please let me know what I'm missing?
Thanks!
The word type is one of many DynamoDB reserved words.
You cannot use a reserved word in an expression. Instead you need to use an alias and then provide DynamoDB with a map from the alias to the real name. For example you might indicate an alias by set #t=:s and then provide a map from #t to type.
Your code will look something like this:
UpdateItemSpec updateItemSpec2 =
new UpdateItemSpec()
.withPrimaryKey("jobid", jobID)
.withUpdateExpression("set #t=:s")
.withValueMap(new ValueMap().withString(":s","updated"))
.withNameMap(new NameMap().with("#t","type"));
I am trying to use https://github.com/eclipse/egit-github/tree/master/org.eclipse.egit.github.core to create a pull request, but I can't find a way to add reviews to the pull request. The V3 Github API supports adding reviewers as mentioned here, https://developer.github.com/v3/pulls/review_requests/#create-a-review-request. I am trying to create the pull request as follows.
private void createPullRequest(
String repositoryName,
String repositoryOwner,
String pullRequestTitle,
String pullRequestBody,
String branchSource,
String branchDestination
) throws IOException {
logger.info("starting to create pull request");
var gitHubClient = new GitHubClient();
gitHubClient.setCredentials("x", "y");
var repositoryService = new RepositoryService(gitHubClient);
var repository = repositoryService.getRepository(repositoryOwner, repositoryName);
var pullRequestService = new PullRequestService(gitHubClient);
var pullRequest = new PullRequest();
pullRequest.setTitle(pullRequestTitle);
pullRequest.setBody(pullRequestBody);
pullRequest.setHead(
new PullRequestMarker().setRef(branchSource).setLabel(branchSource)
);
pullRequest.setBase(
new PullRequestMarker().setRef(branchDestination).setLabel(branchDestination)
);
logger.info("Finally starting to push PR");
pullRequestService.createPullRequest(repository, pullRequest);
logger.info("PR should be created now");
}
From the documentation it says, it supports 100% of Github V3 API. But I am unable to find any reference in code & online for adding reviewers.
Thanks!
We are trying to automate the project migration from one Rally workspace to other. Everything seems to work fine like we are able to migrate project and related releases/iterations/userstories/tasks from one workspace to another workspace.
But while trying to migrate BE Initiative/BE Feature/CPM Feature we are getting some exception related to Null Pointer exception but the error we are getting in Response doesn't seem to give much info.
A sample of code is -
String oldProjectObjectId = "12345";
String newProjectObjectId = "67890";
String oldRallyWorkspaceObjectId = "32145";
String newRallyWorkspaceObjectId = "67894";
QueryResponse beInitiativeResponse = queryRally("portfolioitem/beinitiative", "/project/"+this.oldProjectObjectId, "/workspace/"+this.oldRallyWorkspaceObjectId);
int beInitiativeCount = beInitiativeResponse.getTotalResultCount();
if(beInitiativeCount >0){
JsonArray initiativeArray = beInitiativeResponse.getResults();
for(int i=0; i< initiativeArray.size();i++){
JsonObject beInitiativeObject = initiativeArray.get(i).getAsJsonObject();
String oldBeInitiativeObjectId = beInitiativeObject.get("ObjectID").getAsString();
String oldBeInitiativeName = beInitiativeObject.get("_refObjectName").getAsString();
String owner = getObjectId(beInitiativeObject, "Owner");
JsonObject BeInitiativeCreateObject = getJsonObject(oldBeInitiativeName, "/project/"+this.newProjectObjectId, "/workspace/"+this.newRallyWorkspaceObjectId, owner);
CreateResponse beInitiativeCreateResponse = createInRally("portfolioitem/beinitiative", BeInitiativeCreateObject);
if(beInitiativeCreateResponse.wasSuccessful()){
String newBeInitiativeObjectId = beInitiativeCreateResponse.getObject().get("ObjectID").getAsString();
String mapKey = oldBeInitiativeObjectId;
String mapValue= newBeInitiativeObjectId;
this.beInitiativesHashMap.put(mapKey, mapValue);
}
else{
String[] errorList;
errorList = beInitiativeCreateResponse.getErrors();
for (int j = 0; j < errorList.length; j++) {
System.out.println(errorList[j]);
}
}
}
}
queryRally and createInRally functions use Rally rest client to fetch and create the required projects and associated attributes like releases, iterations etc.
After executing CreateResponse beInitiativeCreateResponse = createInRally("portfolioitem/beinitiative", BeInitiativeCreateObject); when it's trying to execute if(beInitiativeCreateResponse.wasSuccessful()) it is instead going to else block and thus printing the below mentioned error.
An unexpected error has occurred.We have recorded this error and will begin to investigate it. In the meantime, if you would like to speak with our Support Team, please reference the information below:java.lang.NullPointerException2017-12-05 11:01 AM PST America/Los_Angeles
But the important point that is when trying to migrate projects and it's related attributes like release/iterations etc. withing same Rally workspace the above piece of code works just fine.
Update1:
While analysing the issue I made the following observations -
The workspace in which I am trying to create the BeInitiative doesn't have BEinitiative, Be Feature, CPM Feature options in Portfolio items dropdown. Rather it has Theme, Initiative and Feature options in it.
Therefore, I think I was getting the previouly mentioned error. Now I made the following changes to the code.
CreateResponse beInitiativeCreateResponse = createInRally("portfolioitem/theme", themeCreateObject);
So now instead of creating the BEInitiative I am trying to create the theme only in new workspace but getting the following error -
Requested type name \"/portfolioitem/theme\" is unknown.
The object that i am passing to CreateResponse function is -
{"Name":"xyz","Project":"/project/1804","Workspace":"/workspace/139"}
Also code for createInRally function is as mentioned below -
public CreateResponse createInRally( String query, JsonObject object) throws IOException{
CreateRequest createRequest = new CreateRequest(query, object);
CreateResponse createResponse = restApi.create(createRequest);
return createResponse;
}
The Unknown Type error was occurring as a result of not passing the workspace's object id in which we were trying to create the portfolio item.
So after modifying the createInRally function to include the workspace object id we were able to create the initiative portfolio item.
The modified createInRally function is as shown below-
CreateRequest createRequest = new CreateRequest(query, object);
createRequest.addParam("workspace", "/workspace/1333333333");
CreateResponse createResponse = restApi.create(createRequest);
return createResponse;
So this is definitely an error in the web services api. You should never get 500 responses with an unhandled nullpointer. My initial guess is that when you're creating your new object some field on it is still referencing an object in the old workspace, and when we try to correctly hook up all the associations it fails to read one of those objects in the new workspace. Can you provide some more information about what your actual object you're sending to create looks like? Specifically what object relationships are you including (that may not be valid in the new workspace)?
The docs for cognito user pools can be found here:
http://docs.aws.amazon.com/cognito/latest/developerguide/how-to-manage-user-accounts.html
In this they do not say whether you can query users by the automatically generated sub attribute, which is a uuid. It explicitly says you can't search for users by custom attributes, but sub/uuid is not a custom attribute. Weirdly though, in the list of searchable attributes sub/uuid is not one of them. Surely though you can look up users by their UUID, how would this be done though??
You know, I have used COgnito but never needed to look up via sub (or other params other than the username). I looked into it because surely you can, but it is not very clear (like a lot of their documentation). Here is what I saw that you could try... hope it helps man.
// the imported ListUsersResult is...
import com.amazonaws.services.cognitoidp.model.ListUsersRequest;
import com.amazonaws.services.cognitoidp.model.ListUsersResult;
// class var
protected final AWSCognitoIdentityProviderClient identityUserPoolProviderClient;
// omitted stuff...
// initialize the Cognito Provider client. This is used to talk to the user pool
identityUserPoolProviderClient = new AWSCognitoIdentityProviderClient(new BasicAWSCredentials(AWS_ACCESS_KEY, AWS_SECRET_KEY)); // creds are loaded via variables that are supplied to my program dynamically
identityUserPoolProviderClient.setRegion(RegionUtils.getRegion(USER_POOL_REGION)); // var loaded
// ...some code omitted
ListUsersRequest listUsersRequest = new ListUsersRequest();
listUsersRequest.withUserPoolId(USER_POOL_ID); // id of the userpool, look this up in Cognito console
listUsersRequest.withFilter("sub=xyz"); // i THINK this is how the Filter works... the documentation is terribad
// get the results
ListUsersResult result = identityUserPoolProviderClient.listUsers(listUsersRequest);
List<UserType> userTypeList = result.getUsers();
// loop through them
for (UserType userType : userTypeList) {
List<AttributeType> attributeList = userType.getAttributes();
for (AttributeType attribute : attributeList) {
String attName = attribute.getName();
String attValue = attribute.getValue();
System.out.println(attName + ": " + attValue);
}
}
If you have the username you could get the user like this
// build the request
AdminGetUserRequest idRequest = new AdminGetUserRequest();
idRequest.withUserPoolId(USER_POOL_ID);
idRequest.withUsername(username);
// call cognito for the result
AdminGetUserResult result = identityUserPoolProviderClient.adminGetUser(idRequest);
// loop through results
i need to connect to a rest service to get the user id by using a token.
List<Object> providers = new ArrayList<>();
providers.add(new JacksonJaxbJsonProvider());
client = WebClient.create(properties.getProperty(URL), providers);
client = client.accept(MediaType.APPLICATION_JSON_TYPE).type(MediaType.APPLICATION_JSON_TYPE);
client.path(PATH + token);
Response response = client.get();
The entity of response have this format:
{"message":"Token is valid","userId":1}
To get the userId, i have:
response.readEntity(AuthResponse.class).userId;
It is possible to take only the userId without creating an class with that format ? (without AuthResponse.class)
You can try to read your JSON as Map, for example: response.readEntity(Map.class).get("userId")
Please refer to this page for more information.