public async Task <string> GetStateAsync()
    {
        var group = await containerGroup
                    .ConfigureAwait(false);

        return(group.State);
    }
    public async Task <TAuthorizationToken> GetAsync <TAuthorizationToken>(DeploymentScope deploymentScope)
        where TAuthorizationToken : AuthorizationToken, new()
    {
        if (deploymentScope is null)
        {
            throw new ArgumentNullException(nameof(deploymentScope));
        }

        var client = await tableClient.ConfigureAwait(false);

        var rowKey       = AuthorizationEntity.GetEntityId(deploymentScope);
        var partitionKey = string.Join(",", typeof(TAuthorizationToken).AssemblyQualifiedName.Split(',').Take(2));

        try
        {
            var response = await client
                           .GetEntityAsync <TAuthorizationToken>(partitionKey, rowKey)
                           .ConfigureAwait(false);

            return(response.Value);
        }
        catch (RequestFailedException ex) when(ex.Status == 404)
        {
            // doesn't exist
            return(null);
        }
    }
示例#3
0
    public async Task <IEnumerable <string> > GetKeysAsync()
    {
        var storage = await storageInstance
                      .ConfigureAwait(false);

        var storageKeys = await storage
                          .GetKeysAsync()
                          .ConfigureAwait(false);

        return(storageKeys
               .Select(k => k.Value));
    }
示例#4
0
    public async Task <string> AcquireTokenAsync(User user, TimeSpan?ttl = null)
    {
        var client = await tableClient.ConfigureAwait(false);

        var entity = new OneTimeTokenServiceEntity(Guid.Parse(user.Organization), Guid.Parse(user.Id), ttl);

        _ = await client
            .UpsertEntityAsync(entity)
            .ConfigureAwait(false);

        return(entity.Token);
    }
        /// <inheritdoc />
        public async Task<Installation> GetInstallationAsync(long installationId)
        {
            var gitHubUserClient = await _lazyGitHubUserClient.ConfigureAwait(false);
            var gitHubAppsUserClient = gitHubUserClient.GitHubApps;
            var gitHubAppsInstallationsUserClient = gitHubAppsUserClient.Installations;

            var installation = await gitHubAppsUserClient.GetInstallation(installationId).ConfigureAwait(false);
            var repositoriesResponse = await gitHubAppsInstallationsUserClient
                .GetAllRepositoriesForUser(installation.Id).ConfigureAwait(false);

            var repositoriesResponseRepositories = repositoriesResponse.Repositories;

            var userInstallation = BuildInstallation(installation, repositoriesResponseRepositories);

            return userInstallation;
        }
示例#6
0
        public override async IAsyncEnumerable <IAzureIdentity> GetIdentitiesAsync()
        {
            _ = await identityInstance
                .ConfigureAwait(false);

            yield return(this);
        }
        /// <inheritdoc />
        public async Task <Repository> GetRepositoryAsync(long repositoryId)
        {
            var gitHubUserClient = await _lazyGitHubUserClient.ConfigureAwait(false);

            var repositoriesClient = gitHubUserClient.Repository;

            var repository = await repositoriesClient.Get(repositoryId).ConfigureAwait(false);

            return(BuildRepository(repository));
        }
示例#8
0
    public async Task SetAllSecretPermissionsAsync(Guid userObjectId)
    {
        try
        {
            var vault = await vaultInstance
                        .ConfigureAwait(false);

            await vault.Update()
            .DefineAccessPolicy()
            .ForObjectId(userObjectId.ToString())
            .AllowSecretAllPermissions()
            .Attach()
            .ApplyAsync()
            .ConfigureAwait(false);
        }
        finally
        {
            vaultInstance.Reset();
        }
    }
示例#9
0
        /// <summary>
        ///   Starts the network services.
        /// </summary>
        /// <returns>
        ///   A task that represents the asynchronous operation.
        /// </returns>
        /// <remarks>
        ///   Starts the various IPFS and PeerTalk network services.  This should
        ///   be called after any configuration changes.
        /// </remarks>
        /// <exception cref="Exception">
        ///   When the engine is already started.
        /// </exception>
        public async Task StartAsync()
        {
            if (stopTasks.Count > 0)
            {
                throw new Exception("IPFS engine is already started.");
            }

            var localPeer = await LocalPeer.ConfigureAwait(false);

            log.Debug("starting " + localPeer.Id);

            // Everybody needs the swarm.
            var swarm = await SwarmService.ConfigureAwait(false);

            stopTasks.Add(async() =>
            {
                await swarm.StopAsync().ConfigureAwait(false);
            });
            await swarm.StartAsync().ConfigureAwait(false);

            // Start the primary services.
            var tasks = new List <Func <Task> >
            {
                async() =>
                {
                    var bitswap = await BitswapService.ConfigureAwait(false);

                    stopTasks.Add(async() => await bitswap.StopAsync().ConfigureAwait(false));
                    await bitswap.StartAsync().ConfigureAwait(false);
                },
                async() =>
                {
                    var dht = await DhtService.ConfigureAwait(false);

                    stopTasks.Add(async() => await dht.StopAsync().ConfigureAwait(false));
                    await dht.StartAsync().ConfigureAwait(false);
                },
                async() =>
                {
                    var pubsub = await PubSubService.ConfigureAwait(false);

                    stopTasks.Add(async() => await pubsub.StopAsync().ConfigureAwait(false));
                    await pubsub.StartAsync().ConfigureAwait(false);
                },
            };

            log.Debug("waiting for services to start");
            await Task.WhenAll(tasks.Select(t => t())).ConfigureAwait(false);

            // Starting listening to the swarm.
            var json = await Config.GetAsync("Addresses.Swarm").ConfigureAwait(false);

            var numberListeners = 0;

            foreach (string a in json)
            {
                try
                {
                    await swarm.StartListeningAsync(a).ConfigureAwait(false);

                    ++numberListeners;
                }
                catch (Exception e)
                {
                    log.Warn($"Listener failure for '{a}'", e);
                    // eat the exception
                }
            }
            if (numberListeners == 0)
            {
                log.Error("No listeners were created.");
            }

            // Now that the listener addresses are established, the discovery
            // services can begin.
            MulticastService multicast = null;

            if (!Options.Discovery.DisableMdns)
            {
                multicast = new MulticastService();
#pragma warning disable CS1998
                stopTasks.Add(async() => multicast.Dispose());
#pragma warning restore CS1998
            }

            var autodialer = new AutoDialer(swarm)
            {
                MinConnections = Options.Swarm.MinConnections
            };
#pragma warning disable CS1998
            stopTasks.Add(async() => autodialer.Dispose());
#pragma warning restore CS1998

            tasks = new List <Func <Task> >
            {
                // Bootstrap discovery
                async() =>
                {
                    var bootstrap = new PeerTalk.Discovery.Bootstrap
                    {
                        Addresses = await this.Bootstrap.ListAsync()
                    };
                    bootstrap.PeerDiscovered += OnPeerDiscovered;
                    stopTasks.Add(async() => await bootstrap.StopAsync().ConfigureAwait(false));
                    await bootstrap.StartAsync().ConfigureAwait(false);
                },
                // New multicast DNS discovery
                async() =>
                {
                    if (Options.Discovery.DisableMdns)
                    {
                        return;
                    }
                    var mdns = new PeerTalk.Discovery.MdnsNext
                    {
                        LocalPeer        = localPeer,
                        MulticastService = multicast
                    };
                    if (Options.Swarm.PrivateNetworkKey != null)
                    {
                        mdns.ServiceName = $"_p2p-{Options.Swarm.PrivateNetworkKey.Fingerprint().ToHexString()}._udp";
                    }
                    mdns.PeerDiscovered += OnPeerDiscovered;
                    stopTasks.Add(async() => await mdns.StopAsync().ConfigureAwait(false));
                    await mdns.StartAsync().ConfigureAwait(false);
                },
                // Old style JS multicast DNS discovery
                async() =>
                {
                    if (Options.Discovery.DisableMdns || Options.Swarm.PrivateNetworkKey != null)
                    {
                        return;
                    }
                    var mdns = new PeerTalk.Discovery.MdnsJs
                    {
                        LocalPeer        = localPeer,
                        MulticastService = multicast
                    };
                    mdns.PeerDiscovered += OnPeerDiscovered;
                    stopTasks.Add(async() => await mdns.StopAsync().ConfigureAwait(false));
                    await mdns.StartAsync().ConfigureAwait(false);
                },
                // Old style GO multicast DNS discovery
                async() =>
                {
                    if (Options.Discovery.DisableMdns || Options.Swarm.PrivateNetworkKey != null)
                    {
                        return;
                    }
                    var mdns = new PeerTalk.Discovery.MdnsGo
                    {
                        LocalPeer        = localPeer,
                        MulticastService = multicast
                    };
                    mdns.PeerDiscovered += OnPeerDiscovered;
                    stopTasks.Add(async() => await mdns.StopAsync().ConfigureAwait(false));
                    await mdns.StartAsync().ConfigureAwait(false);
                },
                async() =>
                {
                    if (Options.Discovery.DisableRandomWalk)
                    {
                        return;
                    }
                    var randomWalk = new RandomWalk {
                        Dht = Dht
                    };
                    stopTasks.Add(async() => await randomWalk.StopAsync().ConfigureAwait(false));
                    await randomWalk.StartAsync().ConfigureAwait(false);
                }
            };
            log.Debug("waiting for discovery services to start");
            await Task.WhenAll(tasks.Select(t => t())).ConfigureAwait(false);

            multicast?.Start();

            log.Debug("started");
        }
示例#10
0
        void Init()
        {
            // Init the core api inteface.
            Bitswap         = new BitswapApi(this);
            Block           = new BlockApi(this);
            BlockRepository = new BlockRepositoryApi(this);
            Bootstrap       = new BootstrapApi(this);
            Config          = new ConfigApi(this);
            Dag             = new DagApi(this);
            Dht             = new DhtApi(this);
            Dns             = new DnsApi(this);
            FileSystem      = new FileSystemApi(this);
            Generic         = new GenericApi(this);
            Key             = new KeyApi(this);
            Name            = new NameApi(this);
            Object          = new ObjectApi(this);
            Pin             = new PinApi(this);
            PubSub          = new PubSubApi(this);
            Stats           = new StatsApi(this);
            Swarm           = new SwarmApi(this);

            // Async properties
            LocalPeer = new AsyncLazy <Peer>(async() =>
            {
                log.Debug("Building local peer");
                var keyChain = await KeyChain().ConfigureAwait(false);
                log.Debug("Getting key info about self");
                var self      = await keyChain.FindKeyByNameAsync("self").ConfigureAwait(false);
                var localPeer = new Peer
                {
                    Id              = self.Id,
                    PublicKey       = await keyChain.GetPublicKeyAsync("self").ConfigureAwait(false),
                    ProtocolVersion = "ipfs/0.1.0"
                };
                var version            = typeof(IpfsEngine).GetTypeInfo().Assembly.GetName().Version;
                localPeer.AgentVersion = $"net-ipfs/{version.Major}.{version.Minor}.{version.Revision}";
                log.Debug("Built local peer");
                return(localPeer);
            });
            SwarmService = new AsyncLazy <Swarm>(async() =>
            {
                log.Debug("Building swarm service");
                if (Options.Swarm.PrivateNetworkKey == null)
                {
                    var path = Path.Combine(Options.Repository.Folder, "swarm.key");
                    if (File.Exists(path))
                    {
                        using (var x = File.OpenText(path))
                        {
                            Options.Swarm.PrivateNetworkKey = new PreSharedKey();
                            Options.Swarm.PrivateNetworkKey.Import(x);
                        }
                    }
                }
                var peer     = await LocalPeer.ConfigureAwait(false);
                var keyChain = await KeyChain().ConfigureAwait(false);
                var self     = await keyChain.GetPrivateKeyAsync("self").ConfigureAwait(false);
                var swarm    = new Swarm
                {
                    LocalPeer        = peer,
                    LocalPeerKey     = PeerTalk.Cryptography.Key.CreatePrivateKey(self),
                    NetworkProtector = Options.Swarm.PrivateNetworkKey == null
                        ? null
                        : new Psk1Protector {
                        Key = Options.Swarm.PrivateNetworkKey
                    }
                };
                if (Options.Swarm.PrivateNetworkKey != null)
                {
                    log.Debug($"Private network {Options.Swarm.PrivateNetworkKey.Fingerprint().ToHexString()}");
                }

                log.Debug("Built swarm service");
                return(swarm);
            });
            BitswapService = new AsyncLazy <BlockExchange.Bitswap>(async() =>
            {
                log.Debug("Building bitswap service");
                var bitswap = new BlockExchange.Bitswap
                {
                    Swarm        = await SwarmService.ConfigureAwait(false),
                    BlockService = Block
                };
                log.Debug("Built bitswap service");
                return(bitswap);
            });
            DhtService = new AsyncLazy <PeerTalk.Routing.Dht1>(async() =>
            {
                log.Debug("Building DHT service");
                var dht = new PeerTalk.Routing.Dht1
                {
                    Swarm = await SwarmService.ConfigureAwait(false)
                };
                dht.Swarm.Router = dht;
                log.Debug("Built DHT service");
                return(dht);
            });
            PubSubService = new AsyncLazy <PeerTalk.PubSub.NotificationService>(async() =>
            {
                log.Debug("Building PubSub service");
                var pubsub = new PeerTalk.PubSub.NotificationService
                {
                    LocalPeer = await LocalPeer.ConfigureAwait(false)
                };
                pubsub.Routers.Add(new PeerTalk.PubSub.FloodRouter
                {
                    Swarm = await SwarmService.ConfigureAwait(false)
                });
                log.Debug("Built PubSub service");
                return(pubsub);
            });
        }