I am able to create a CNAME record through the AWS console no problem see picture above. But when I try to do the same thing programmatically with the AWS Route53 SDK I keep getting an
com.amazonaws.services.route53.model.InvalidInputException: Invalid
request (Service: AmazonRoute53; Status Code: 400; Error Code:
InvalidInput; Request ID: 7fd7b5d1-5ea8-11e8-a252-7f474094c446)
Here's my attempted code
private static final String QA_HOSTED_ZONE_ID = "UUIDFromConsole";
GetHostedZoneRequest getHostedZoneRequest = new GetHostedZoneRequest(HOSTED_ZONE_ID);
GetHostedZoneResult result = route53Client.getHostedZone(getHostedZoneRequest);
ResourceRecordSet resourceRecordSet = new
ResourceRecordSet("DN4TheRecordSet", RRType.CNAME);
GeoLocation geoLocation = new GeoLocation();
geoLocation.setContinentCode("NA");
geoLocation.setSubdivisionCode("NY");
resourceRecordSet.setGeoLocation(geoLocation);
resourceRecordSet.setTTL(50L);
resourceRecordSet.setGeoLocation(geoLocation);
resourceRecordSet.setSetIdentifier("uniqueid-statecode");Change addStateChange = new Change(ChangeAction.CREATE, resourceRecordSet);
ChangeBatch changeBatch = new ChangeBatch(Arrays.asList(addStateChange));
ChangeResourceRecordSetsRequest changeResourceRecordSetsRequest = new ChangeResourceRecordSetsRequest().withHostedZoneId(HOSTED_ZONE_ID).withChangeBatch(changeBatch);
route53Client.changeResourceRecordSets(changeResourceRecordSetsRequest);
I am also not able to configure the value for the CNAME, meaning where I want to redirect my traffic after it hits the DN4TheRecordSet.This is probably the cause of the invalid error I am receiving in the response.
Please help 🤕
Found the issue.
The InvalidInputException was eluding to the fact of a missing ResourceRecord which corresponds to the value field in the picture above.
Here's the solution above with the addition of a ResourceRecord to the ResourceRecordSet
private static final String QA_HOSTED_ZONE_ID = "UUIDFromConsole";
private static final String REDIRECT_DNS = "DNS to want the cname to route to";
GetHostedZoneRequest getHostedZoneRequest = new GetHostedZoneRequest(HOSTED_ZONE_ID);
GetHostedZoneResult result = route53Client.getHostedZone(getHostedZoneRequest); ResourceRecordSet resourceRecordSet = new ResourceRecordSet("DN4TheRecordSet", RRType.CNAME);
GeoLocation geoLocation = new GeoLocation();
geoLocation.setContinentCode("NA");
geoLocation.setSubdivisionCode("NY");
resourceRecordSet.setGeoLocation(geoLocation);
resourceRecordSet.setTTL(50L);
resourceRecordSet.setGeoLocation(geoLocation);
resourceRecordSet.setSetIdentifier("uniqueid-statecode");
resourceRecordSet.setResourceRecords(Arrays.asList(new ResourceRecord(REDIRECT_DNS))); // This line being missing cause the exception
Change addStateChange = new Change(ChangeAction.CREATE, resourceRecordSet);
ChangeBatch changeBatch = new ChangeBatch(Arrays.asList(addStateChange));
ChangeResourceRecordSetsRequest changeResourceRecordSetsRequest = new ChangeResourceRecordSetsRequest().withHostedZoneId(HOSTED_ZONE_ID).withChangeBatch(changeBatch);
route53Client.changeResourceRecordSets(changeResourceRecordSetsRequest);
See Geolocation Syntax section in this page for example of the payload the sdk creates and sends for your request.
Related
I have a Java application that integrates with One Drive through Microsoft Graph. I followed the documentation and I am able to pass the authorisation step but when interrogating the API I get this error:
"AADSTS70000121: The passed grant is from a personal Microsoft account and is required to be sent to the /consumers or /common endpoint."
What am I missing?
This is the code I am using:
Get an authorisation token using the URL bellow
private static final String RESPONSE_TYPE = "code";
private static final String SCOPE = "openid%20Files.Read%20Files.ReadWrite%20Contacts.Read%20offline_access";
String authorizeUrl = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=" + CLIENT_ID
+ "&scope=" + SCOPE + "&response_type=" + RESPONSE_TYPE + "&redirect_uri=" + REDIRECT_URL;
Exchange the received authorization token
List<String> scopes = new LinkedList<String>();
scopes.add("https://graph.microsoft.com/.default");
AuthorizationCodeCredential authCodeCredential = new AuthorizationCodeCredentialBuilder()
.clientId(CLIENT_ID)
.clientSecret(CLIENT_SECRET)
.authorizationCode(authorizationCode)
.redirectUrl(REDIRECT_URL)
.build();
TokenCredentialAuthProvider tokenCredAuthProvider = new TokenCredentialAuthProvider(scopes, authCodeCredential);
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider(tokenCredAuthProvider).buildClient();
User me = graphClient.me()
.buildRequest()
.get();
As you are using the personal account then please change the endpoint to consumers instead of common,
https://login.microsoftonline.com/consumers/oauth2/v2.0/authorize?
ref doc - https://learn.microsoft.com/en-au/azure/active-directory/develop/v2-oauth2-auth-code-flow
Hope this helps
Thanks
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());
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!
I want to make a send payment from my wallet.
public static Transaction send(Wallet wallet,String destinationAddress,long satoshis, NetworkParameters parameters)
throws Exception {
Address dest = Address.fromBase58(parameters, destinationAddress);
SendRequest request = SendRequest.to(dest, Coin.valueOf(satoshis));
Wallet.SendResult result = wallet.sendCoins(request);
Transaction endTransaction = result.broadcastComplete.get();
return endTransaction;
}
or tried to make
SendRequest req;
Transaction transaction = new Transaction(parameters);
Coin coinToSpend = Coin.valueOf(600);
//Address addressoSpend = new Address(parameters,"1PSq12YPRBCGwmb2cqqXaGpRrLfotsthPv");
transaction.addOutput(coinToSpend,Address.fromBase58(parameters,"18MQPpjbB5UUwZBT7DALE6Q55pKCtfPCK3"));
req = SendRequest.forTx(transaction);
Wallet.SendResult sendResult = restoredWallet.sendCoins(req);
both of them return
Exception in thread "main" org.bitcoinj.core.InsufficientMoneyException: Insufficient money, missing 0.0004729 BTC
How to make a proper send payment to another BTC address?
The problem actually was with the input and output. In new versions of bitcoinj you should set unput and output ot make transaction. Unfortuanetly, it was not updated on officail page. Here below is the answer for my question:
Coin value = Coin.valueOf(680l);
Address to = Address.fromBase58(parameters, addressTo);
Transaction transaction = new Transaction(parameters);
transaction.addInput(wallet.getUnspents().get(0));// important to add proper input
transaction.addOutput(value, to);
SendRequest request = SendRequest.forTx(transaction);
request.feePerKb = Coin.valueOf(1000);
Wallet.SendResult sendResult = wallet.sendCoins(peerGroup, request);
Can any one help me on how to create shared link in BOX using java SDK. I am using below code:-
BoxFile file = new BoxFile(api, ID);
BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions();
permissions.setCanDownload(true);
permissions.setCanPreview(true);
Date unshareDate = new Date();
BoxSharedLink sharedLink = file.createSharedLink(
BoxSharedLink.Access.OPEN, unshareDate, permissions);
Getting error :-
The API returned the error code: 400
{"type":"error","status":400,"code":"bad_request","context_info":{"errors":[{"reason":"invalid_parameter","name":"unshared_at","message":"Invalid value '1471842735'."}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Bad Request","request_id":"208420399157ba89af5e170"}
private static BoxSharedLink createSharedLink(BoxAPIConnection api, String fileId) {
BoxFile file = new BoxFile(api, fileId);
BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions();
permissions.setCanDownload(true);
permissions.setCanPreview(true);
Date date = new Date();
Calendar unshareAt = Calendar.getInstance();
unshareAt.setTime(date);
unshareAt.add(Calendar.DATE, 14);
BoxSharedLink sharedLink = file.createSharedLink(BoxSharedLink.Access.COMPANY, unshareAt.getTime(), permissions);
logger.info("shared link: " + sharedLink.getURL());
return sharedLink;
}
I just passed "null" in place of unsharedDate..I am able to get a shared link.
BoxSharedLink sharedLink = file.createSharedLink(
BoxSharedLink.Access.OPEN, null, permissions);
I am not sure what null value means. I am guessing there is no unsharedDate set if you pass null. couldn't find any api documentation for this.