Beispiel #1
0
 public DigitalDealersClient(string token, params DelegatingHandler[] handlers) : this(handlers)
 {
     Credentials = new TokenCredentials(token, "Bearer");
     if (Credentials != null)
     {
         Credentials.InitializeServiceClient(this);
     }
 }
        protected MonitorManagementClient GetMonitorManagementClient(RecordedDelegatingHandler handler)
        {
            handler.IsPassThrough = false;
            var tokenProvider = new StringTokenProvider("granted", "SimpleString");
            var id            = Guid.NewGuid().ToString();
            var token         = new TokenCredentials(tokenProvider: tokenProvider, tenantId: id, callerId: id);
            var client        = new MonitorManagementClient(token, handler);

            token.InitializeServiceClient(client);
            client.SubscriptionId = id;

            return(client);
        }
Beispiel #3
0
        /// <summary>
        /// Will create a system topic on a storage account where Azure will publish events for containers in the storage account.
        /// Only one system topic can be created per storage account.
        /// </summary>
        private bool CreateStorageSystemTopic(string _TopicName, Action <string> _ErrorMessageAction = null)
        {
            try
            {
                SystemTopic TopicInfo = new SystemTopic(ResourceGroupLocation,
                                                        $"/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/Microsoft.EventGrid/systemTopics/{_TopicName}",
                                                        _TopicName,
                                                        "Microsoft.EventGrid/systemTopics",
                                                        null,
                                                        null,
                                                        $"/subscriptions/{SubscriptionId}/resourceGroups/{ResourceGroupName}/providers/microsoft.storage/storageaccounts/{StorageAccountName}",
                                                        null,
                                                        "microsoft.storage.storageaccounts");

                if (LastGeneratedToken.ExpiresOn.UtcDateTime <= DateTime.UtcNow)
                {
                    ClientSecretCredential ClientCred     = new ClientSecretCredential(TenantId, ClientId, ClientSecret);
                    TokenRequestContext    RequestContext = new TokenRequestContext(new string[] { $"https://management.azure.com/.default" });
                    LastGeneratedToken = ClientCred.GetToken(RequestContext);
                }

                TokenCredentials TokenCredential = new TokenCredentials(new StringTokenProvider(LastGeneratedToken.Token, "Bearer"));

                EventGridManagementClient ManagmentClient = new EventGridManagementClient(TokenCredential);
                TokenCredential.InitializeServiceClient(ManagmentClient);
                ManagmentClient.SubscriptionId = SubscriptionId;

                AZSystemTopicOperations SystemTopicOperations = new AZSystemTopicOperations(ManagmentClient);

                bool Success = SystemTopicOperations.CreateOrUpdate(ResourceGroupName, _TopicName, TopicInfo, out SystemTopic _, _ErrorMessageAction);

                return(Success);
            }
            catch (Exception ex)
            {
                _ErrorMessageAction?.Invoke($"{ex.Message} :\n {ex.StackTrace}");
                return(false);
            }
        }