on 12-02-2014 12:32 PM
Hi Expert,
we are working on afaria apis to automate the process of assigning CA server property for a tenant . where i am call server property api service.
but i don't know how to set property like server address, CA type etc. for a tenant.
any help will be apreciated.
BR,
Saurabh
What type of CA were you attempting to add? For a simple SCEP CA entry, see below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ServerProps_AddCA.AfariaServerProperties;
namespace ServerProps_AddCA
{
class Program
{
static void Main(string[] args)
{
string apiAddress = "10.10.10.10";
string apiUserDomain = "domain.com";
string apiUserName = "afaria";
string apiUserPass = "mysupersecretpassword";
string serverTransmitterID = "mytransmitterid";
string response = string.Empty;
Console.Write("Enter the API Server address or hit enter for default: ");
response = Console.ReadLine();
if (!string.IsNullOrWhiteSpace(response))
{
apiAddress = response;
Console.Write("Enter the API Service Account UserName or hit enter for default: ");
response = Console.ReadLine();
if (!string.IsNullOrWhiteSpace(response))
{
apiUserName = response;
Console.Write("Enter the API Service Account User Domain or hit enter for default: ");
response = Console.ReadLine();
if (!string.IsNullOrWhiteSpace(response))
{
apiUserDomain = response;
}
Console.Write("Enter the API Service Account User Password or hit enter for default: ");
response = Console.ReadLine();
if (!string.IsNullOrWhiteSpace(response))
{
apiUserPass = response;
}
}
}
using (ServerPropertiesServiceClient svcServerProperties = new ServerPropertiesServiceClient("NetTcpBinding_IServerPropertiesService"
, "net.tcp://" + apiAddress + ":7982/AfariaService/ServerProperties"))
{
svcServerProperties.ClientCredentials.Windows.ClientCredential.Domain = apiUserDomain;
svcServerProperties.ClientCredentials.Windows.ClientCredential.UserName = apiUserName;
svcServerProperties.ClientCredentials.Windows.ClientCredential.Password = apiUserPass;
svcServerProperties.InitContext(Guid.NewGuid().ToString());
Console.Write("Enter the Tenant ID # or hit enter for system tenant(0): ");
int tenantID = 0;
response = Console.ReadLine();
if (!string.IsNullOrWhiteSpace(response))
{
int.TryParse(response, out tenantID);
}
svcServerProperties.SetTenantIdContext(tenantID);
svcServerProperties.SetServerIdContext(serverTransmitterID);
string caName = "New CA-" + Guid.NewGuid().ToString("N");
string caDescription = "New CA Description";
string caAddress = "127.0.0.1";
CertificateAuthorityConfigurationScep caConfig = new CertificateAuthorityConfigurationScep();
caConfig.CertificateRequest = new CertificateRequestV002();
caConfig.ServerAccess = new ServerAccessSettings();
caConfig.ServerAccess.Address = caAddress;
caConfig.CertificateRenewalDays = 21;
try
{
//if (svcServerProperties.ValidateCertificateAuthoritySettingsV002(caConfig, null, 60))
//{
Console.WriteLine("Attempting to add CA entry...");
svcServerProperties.AddCertificateAuthorityDefinedSettingInfoV002(caName, caDescription, caConfig);
Console.WriteLine("Hooray! Success!");
//}
}
catch(Exception ex)
{
Console.WriteLine("Exception occurred: " + ex.Message + "\r\n" + ex.StackTrace);
if(ex.InnerException != null)
{
Console.WriteLine("\r\nInner exception: " + ex.InnerException.Message + "\r\n"+ ex.InnerException.StackTrace);
}
}
if (svcServerProperties.ChannelFactory.State != System.ServiceModel.CommunicationState.Faulted)
{
svcServerProperties.CloseContext();
}
}
Console.Write("\r\n\r\nPress a key to exit...");
Console.ReadKey();
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi John,
Thanks for your reply it worked very well . now i want to fetch no. of device registered for a tenant how to get that through api and also linking app policy or configuration policy to group through api. can you provide some sample code for SchemaQuery & StoredQueries
We are having issues in usage of the Schema Query for a defined Query ID.
Thanks,
Saurabh
User | Count |
---|---|
95 | |
11 | |
11 | |
10 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.