I'm trying to create a new branch policy using Microsoft.TeamFoundation.Policy.WebApi Library.
my Code is:
variable info:
json - contains the setting in the policy configuration
connection - is the VSSConnection to our TFS server
TFSProject - is the project name in the TFS
the error i get the is not showing anything in my searches, i would appreciate some examples for how to create a new policy in TFS
code:
var json = "{\"statusName\": \"" + StatusNameForBlock + "\",\"statusGenre\": \"ci\",\"authorId\": null,\"invalidateOnSourceUpdate\": false,\"policyApplicability\": null,\"scope\": [{\"refName\": \"refs/heads/master\",\"matchKind\": \"Exact\"}]}";
JObject jToken = new JObject(JObject.Parse(json));
var newPolicy = new PolicyConfiguration();
var policyType = new PolicyTypeRef();
policyType.Id = Guid.NewGuid();
newPolicy.Type = policyType;
newPolicy.Settings = jToken;
var gitPolicyHttpClient = connection.GetClient<PolicyHttpClient>();
var policyCreated = gitPolicyHttpClient.CreatePolicyConfigurationAsync(newPolicy, TFSProject).Result;
exception: VssServiceException: Type with id '98813712-70a4-4937-b139-9a3654c9795f' does not exist
You could use Rest API to create a new branch policy.
POST https://{instance}/{collection}/{project}/_apis/policy/configurations/{configurationId}?api-version=5.0
Use these APIs to define policies for your projects. Configurations associate a type, such as "Required reviewers", with specific settings, such as "For pull requests with files named *.dll targeting the master branch in the xxx Git repository, add the Source-Controlled Binaries Team as a required reviewer".
Policy Examples for your reference.
For more details, you could also take a look at this blog-- Configuring standard policies for all repositories in Azure Repos
Related
I created an App Configuration using Pulumi:
_configurationStore = new ConfigurationStore(appConfigurationName, new ConfigurationStoreArgs
{
ResourceGroupName = _resourceGroup.Name,
Location = _resourceGroup.Location,
Sku = "standard"
});
Now I am stuck adding values to it. The docs don't mention any method to read or write settings into my ConfigurationStore (or I simply cannot find it).
How can I store simple key/value-Pairs?
How can I store "links" to values from an existing keyvault? Do I simply create the connectionstring manually?
Adding key-values was introduced by Azure Resource Manager (ARM) just recently in the 2020-07-01-preview version and there's no "stable" API version with them yet. So, you should use that version to define key-values
new Pulumi.AzureNextGen.AppConfiguration.V20200701Preview.KeyValue("kv",
new Pulumi.AzureNextGen.AppConfiguration.V20200701Preview.KeyValueArgs
{
ResourceGroupName = _resourceGroup.Name,
ConfigStoreName = _configurationStore.Name,
KeyValueName = "key1",
Value = "value1",
});
You can read more in the docs: https://www.pulumi.com/docs/reference/pkg/azure-nextgen/appconfiguration/keyvalue/
Also, discussed in this issue: https://github.com/pulumi/pulumi-azure-nextgen/issues/62
So far all the examples of using Google Cloud Firestore with .net show that you connect to your Firestore db by using this command:
FirestoreDb db = FirestoreDb.Create(projectId);
But is this skipping the step of authentication? I can't seem to find an example of wiring it up to use a Google service account. I'm guessing you need to connect using the service account's private_key/private_key_id/client_email?
You can also use the credentials stored in a json file:
GoogleCredential cred = GoogleCredential.FromFile("credentials.json");
Channel channel = new Channel(FirestoreClient.DefaultEndpoint.Host,
FirestoreClient.DefaultEndpoint.Port,
cred.ToChannelCredentials());
FirestoreClient client = FirestoreClient.Create(channel);
FirestoreDb db = FirestoreDb.Create("my-project", client);
I could not compile #Michael Bleterman's code, however the following worked for me:
using Google.Cloud.Firestore;
using Google.Cloud.Firestore.V1;
var jsonString = File.ReadAllText(_keyFilepath);
var builder = new FirestoreClientBuilder {JsonCredentials = jsonString};
FirestoreDb db = FirestoreDb.Create(_projectId, builder.Build());
Packages I use:
<PackageReference Include="Google.Cloud.Firestore" Version="2.0.0-beta02" />
<PackageReference Include="Google.Cloud.Storage.V1" Version="2.5.0" />
But is this skipping the step of authentication?
No. It will use the default application credentials. If you're running on Google Cloud Platform (AppEngine, GCE or GKE), they will just be the default service account credentials for the instance. Otherwise, you should set the GOOGLE_APPLICATION_CREDENTIALS environment variable to refer to a service account credential file.
From the home page of the user guide you referred to:
When running on Google Cloud Platform, no action needs to be taken to authenticate.
Otherwise, the simplest way of authenticating your API calls is to download a service account JSON file then set the GOOGLE_APPLICATION_CREDENTIALS environment variable to refer to it. The credentials will automatically be used to authenticate. See the Getting Started With Authentication guide for more details.
It's somewhat more awkward to use non-default credentials; this recent issue gives an example.
This worked for me.
https://pieterdlinde.medium.com/netcore-and-cloud-firestore-94628943eb3c
string filepath = "/Users/user/Downloads/user-a4166-firebase-adminsdk-ivk8q-d072fdf334.json";
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", filepath);
fireStoreDb = FirestoreDb.Create("user-a4166");
The simplest way:
Get service account json file and hardcode values into a class:
public class FirebaseSettings
{
[JsonPropertyName("project_id")]
public string ProjectId => "that-rug-really-tied-the-room-together-72daa";
[JsonPropertyName("private_key_id")]
public string PrivateKeyId => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
// ... and so on
}
Add it Startup.cs
var firebaseJson = JsonSerializer.Serialize(new FirebaseSettings());
services.AddSingleton(_ => new FirestoreProvider(
new FirestoreDbBuilder
{
ProjectId = firebaseSettings.ProjectId,
JsonCredentials = firebaseJson // <-- service account json file
}.Build()
));
Add wrapper FirebaseProvider
public class FirestoreProvider
{
private readonly FirestoreDb _fireStoreDb = null!;
public FirestoreProvider(FirestoreDb fireStoreDb)
{
_fireStoreDb = fireStoreDb;
}
// ... your methods here
}
Here is a full example of a generic provider.
https://dev.to/kedzior_io/simple-net-core-and-cloud-firestore-setup-1pf9
I am working on the CodedUI Test Automation project. i am developing a framework in which i am trying to access Test Cases in VSTS through RestAPI. I have worked on an MVC application previously in which i did the same thing to pull data from VSTS using RestAPI.
Now the problem is i am not able to access the VSTS. Everytime i am trying to access the VSTS, i got the exception TF400813: Resource not available for anonymous access. Client authentication required.
I am using the same PAT token. I have all the required access on my team project. I am able to access all work items in my project from browser. I have tried all the option mentioned in below thread but still its not working.
Client authentication error when starting Visual Studio 2015.3Any leads will be appreciated.Below is my code to get data from VSTS:
public static List<WorkItem> GetWorkItemsWithSpecificFields(IEnumerable<int> ids)
{
var collectionUri = "https://<name>.visualstudio.com";
var fields = new string[] {
"System.Id",
"System.Title",
"System.WorkItemType",
"Microsoft.VSTS.Scheduling.RemainingWork"
};
using (WorkItemTrackingHttpClient workItemTrackingHttpClient = new WorkItemTrackingHttpClient(new Uri(collectionUri), new VssBasicCredential("", System.Configuration.ConfigurationManager.AppSettings["PATToken"])))
{
// Exception is coming on below line
List<WorkItem> results = workItemTrackingHttpClient.GetWorkItemsAsync(ids, fields).Result;
return results;
}
}
It is necessary to define
<add key="AWSRegion" value="us-east-1"/>
application setting in App.config to specify region to use.
I need to change that programmatically
var creds = new BasicAWSCredentials(key, token);
using (var routes = AWSClientFactory.CreateAmazonRoute53Client(creds)){}
how to specify the region in code?
It is the best practice to use more configurable version (i.e. endpoint configured from web.config/app.config). For EC2 client, you can do it by the following way:
var region = RegionEndpoint.GetBySystemName("ap-northeast-1");
var awsEC2Client = new AmazonEC2Client(region);
For others reason, you can specify from here
Resource Link:
How to set the EndPoint / Region for the C# .NET SDK : EC2Client?
How to start an Amazon EC2 instance programmatically in .NET
I have created a plugin that invokes an AX custom web service.
The web service should return a price given a product and a customer.
I am able to invoke the web service without problems outside CRM, but after including it in the plugin it stopped working.
The error message I get is:
Could not find default endpoint element that references contract 'AxIntegrationServices.PriceDiscService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
Here is the code:
//retrieve the entity product as the input Entity
var entity = (Entity)context.InputParameters["Target"];
//Early bound entity
var oppProduct = new opportunityproduct(entity);
var quantity = (Decimal)oppProduct.quantity;
tracingService.Trace("Retrieving Opp with opp ID = {0}", oppProduct.opportunityid.Id.ToString());
//get the early bound opportunity containing the opportunity product
var opp = new opportunity(Helper.ActualEntity(oppProduct.opportunityid, service));
//get the early bound account entity that is the customer for the opportunity
tracingService.Trace("Retrieved, type = {0}", opp.name);
tracingService.Trace("Retrieving Account with accountID={0}", opp.customerid.Id.ToString());
Entity acc = Helper.ActualEntity(opp.customerid, service);
tracingService.Trace("Account retrieved");
var account = new account(acc);
//get the ax integration key for the account
tracingService.Trace("Retrieving Account AX key");
var accountAxKey = account.custom_axrecordid;
tracingService.Trace("Retrieving Product");
//get the early bound account entity that is the customer for the opportunity
var product = new product(Helper.ActualEntity(oppProduct.productid, service, new string[]{ "custom_axrecordid" }));
//get the integration key for the product
tracingService.Trace("Retrieving Product AX key");
var productAxKey = product.custom_axrecordid;
tracingService.Trace("Invoking web service");
PriceDiscServiceClient priceDiscServiceClient = new PriceDiscServiceClient();
CallContext callContext = new CallContext();
priceDiscServiceClient.ClientCredentials.Windows.ClientCredential.UserName = "xxx";
priceDiscServiceClient.ClientCredentials.Windows.ClientCredential.Password = "yyyy!";
priceDiscServiceClient.ClientCredentials.Windows.ClientCredential.Domain = "aaa";
PriceDiscServiceContract priceDiscServiceContract = priceDiscServiceClient.getPriceDiscSales(callContext, productAxKey, accountAxKey, quantity);
tracingService.Trace("Price :{0}",priceDiscServiceContract.Price);
tracingService.Trace("Markup :{0}", priceDiscServiceContract.Markup);
tracingService.Trace("PriceUnit :{0}", priceDiscServiceContract.PriceUnit);
tracingService.Trace("DiscAmount :{0}", priceDiscServiceContract.DiscAmount);
tracingService.Trace("DiscPct :{0}", priceDiscServiceContract.DiscPct);
oppProduct.priceperunit = priceDiscServiceContract.PriceUnit;
oppProduct.isproductoverridden = false;
oppProduct.ispriceoverridden = true;
The web service is located in the same network of the CRM environment and I am working through a VPN to connect to them.
Any ideas?
You should check your PriceDiscServiceClient constructor - it should accept a Binding and EndpointAddress so your code could look something like this:
//...
BasicHttpBinding binding = new BasicHttpBinding();
// configure Binding as needed (Timeout, etc.) ...
EndpointAddress endpoint = new EndpointAddress(endpointUri);
PriceDiscServiceClient client = new PriceDiscServiceClient(binding, endpoint);
//...
As James Wood already pointed out the next problem will be to populate endpointUri with a configurable value instead of hardcoding it into your Plugin.
I tend to prefer the plugin unsecure configration rather than roundtrip to a crm settings record for every time the plugin executes.
The link James Wood refers to is exactly the solution I'd choose to configure the endpoint address Uri.
If you code relies on configuration in the app.config as Filburt suggested then this approach is unlikely to work. When you add your plugin assembly to MSCRM the app.config is not included (its in a separate configuration file).
You wont be able to add any of the configuration in the app.config to the CRM app.config (because its not supported).
I would suggest whatever you are doing on the app.config moving into code within the plugin itself. Anything you are doing in the app.config you should be able to do in code as well.
If you need to retrieve settings values (e.g. connection strings) you might want to consider using a settings record in CRM and retrieving that information. Or alternatively using the plugins configuration section.