Exemplo n.º 1
0
        static void SetupSeq()
        {
            PrintTitle("Setting up Seq");
            var connection = new SeqConnection(SeqUrl);
            var entity     = new ApiKeyEntity
            {
                Title = AppName,
                AssignedPermissions = new HashSet <Permission> {
                    Permission.Ingest
                },
                InputSettings = new InputSettingsPart
                {
                    MinimumLevel      = LogEventLevel.Debug,
                    AppliedProperties = new List <InputAppliedPropertyPart>
                    {
                        new InputAppliedPropertyPart {
                            Name = "app", Value = AppName
                        }
                    }
                }
            };

            Task("Add API key", () =>
            {
                var result = connection.ApiKeys.AddAsync(entity).Result;
                GeneratedOutput.Add("SeqConfiguration::ApiKey", result.Token);
            });
        }
        public async Task <AddApiKeyResponse> Handle(AddApiKeyRequest request, CancellationToken cancellationToken)
        {
            var existing = await _storeDbContext
                           .ApiKeys
                           .Where(ak => ak.Name == request.Name)
                           .SingleOrDefaultAsync();

            if (existing == null)
            {
                var apiKey = new ApiKeyEntity(
                    request.Name,
                    ApiKeyGenerator.CreateApiKey(),
                    request.ValidTo ?? DateTime.UtcNow.AddYears(1));

                _storeDbContext.Add(apiKey);
                await _storeDbContext.SaveChangesAsync(cancellationToken);

                return(new AddApiKeyResponse()
                {
                    ApiKeyId = apiKey.Id,
                    ApiKey = apiKey.Key
                });
            }

            Log.ApiKeyAlreadyExist(_logger, request.Name);
            throw new InvalidOperationException($"A ApiKey with name {request.Name} already exist.");
        }
Exemplo n.º 3
0
 public static ApiKeyEntity Map(Character source, ApiKeyEntity target)
 {
     target.EntityId = (int)source.CharacterId;
     target.Name     = source.CharacterName;
     target.Type     = "Character";
     return(target);
 }
Exemplo n.º 4
0
        public async Task <IndustryJobs> GetIndustryJobs(ApiKey key, ApiKeyEntity entity)
        {
            var character = new Character(key.ApiKeyId, key.VCode, entity.EntityId);
            var result    = (await character.GetIndustryJobsAsync().ConfigureAwait(false)).Result;

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Retrieve a detailed metric for the API key.
        /// </summary>
        /// <param name="entity">The API key to retrieve metrics for.</param>
        /// <param name="cancellationToken">A <see cref="CancellationToken"/> allowing the operation to be canceled.</param>
        /// <param name="measurement">The measurement to get.</param>
        /// <returns></returns>
        public async Task <MeasurementTimeseriesPart> GetMeasurementTimeseriesAsync(ApiKeyEntity entity, string measurement, CancellationToken cancellationToken = default)
        {
            var parameters = new Dictionary <string, object> {
                ["id"] = entity.Id, ["measurement"] = measurement
            };

            return(await GroupGetAsync <MeasurementTimeseriesPart>("Metric", parameters, cancellationToken));
        }
Exemplo n.º 6
0
        static ApplicationHelper() {
            Instance = new ApplicationHelper();
            TaxRate = 0.75;
            BrokerFeeRate = 0.73;
            ActiveEntity = new ApiKeyEntity();
            ActiveEntity.Name = "No Active Entity";
            StationId = 60003760;

        }
Exemplo n.º 7
0
        public CharacterData GetCharacterData(ApiKey key, ApiKeyEntity entity)
        {
            var       data      = new CharacterData();
            var       ckey      = new CharacterKey(key.ApiKeyId, key.VCode);
            Character character = ckey.Characters.Single(c => c.CharacterId == entity.EntityId);
            EveApiResponse <CharacterInfo> info = character.GetCharacterInfo();

            return(data);
        }
Exemplo n.º 8
0
        public async Task <AssetList> GetAssetsAsync(ApiKey key, ApiKeyEntity entity)
        {
            var       data      = new CharacterData();
            var       ckey      = await new CharacterKey(key.ApiKeyId, key.VCode).InitAsync().ConfigureAwait(false);
            Character character = ckey.Characters.Single(c => c.CharacterId == entity.EntityId);
            var       assets    = await character.GetAssetListAsync().ConfigureAwait(false);

            return(assets.Result);
        }
Exemplo n.º 9
0
        public async Task <string> Get()
        {
            TableOperation retrieveOperation = TableOperation.Retrieve <ApiKeyEntity>("apikey", "apikey");
            TableResult    result            = await _table.ExecuteAsync(retrieveOperation);

            ApiKeyEntity apiKeyEntity = (ApiKeyEntity)result.Result;

            return(apiKeyEntity.ApiKey);
        }
        public async Task CreateAsync(CreateApiKeyRequest request)
        {
            var entity = new ApiKeyEntity
            {
                Owner       = request.Owner,
                Permissions = request.Permissions
            };

            await(await _container).CreateItemAsync(await _entityMutator.CreateMetadataAsync(entity, request.SharedWith));
        }
        public async Task UpdateAsync(string key, UpdateApiKeyRequest request)
        {
            var entity = await _readRepository.GetByKeyAsync(key);

            var updatedEntity = new ApiKeyEntity
            {
                Owner       = request.Owner ?? entity.Owner,
                Permissions = request.Permissions ?? entity.Permissions
            };

            await(await _container).ReplaceItemAsync(
                await _entityMutator.UpdateMetadataAsync(updatedEntity, entity, request.SharedWith),
                key
                );
        }
Exemplo n.º 12
0
        public static async Task CreateApiKey(string keyName, string env)
        {
            ApiKeyEntity templateKey = await _seqConnection.ApiKeys.TemplateAsync();

            templateKey.Title = keyName;

            InputAppliedPropertyPart _property = new InputAppliedPropertyPart();

            _property.Name  = "Environment";
            _property.Value = _envKV.GetValueOrDefault(env);
            templateKey.AppliedProperties.Add(_property);

            if (applyChanges)
            {
                await _seqConnection.ApiKeys.AddAsync(templateKey);
            }
        }
Exemplo n.º 13
0
        public async Task <AddApiKeyResponse> Handle(AddApiKeyRequest request, CancellationToken cancellationToken)
        {
            var existing = await _storeDbContext
                           .ApiKeys
                           .Where(ak => ak.Name == request.Name)
                           .SingleOrDefaultAsync();

            if (existing == null)
            {
                var key = ApiKeyGenerator.CreateApiKey();

                var apiKey = new ApiKeyEntity(
                    name: request.Name,
                    key: key,
                    validTo: request.ValidTo ?? DateTime.UtcNow.AddYears(1));

                var apiKeyPermissions = new PermissionEntity()
                {
                    SubjectId       = key,
                    Kind            = SubjectType.Application,
                    ApplicationRole = Enum.Parse <ApplicationRole>(request.ActAs, ignoreCase: true)
                };

                _storeDbContext
                .Add(apiKeyPermissions);

                _storeDbContext
                .Add(apiKey);

                await _storeDbContext.SaveChangesAsync(cancellationToken);

                return(new AddApiKeyResponse()
                {
                    Name = apiKey.Name,
                    Key = key
                });
            }

            Log.ApiKeyAlreadyExist(_logger, request.Name);
            throw new InvalidOperationException($"A ApiKey with name {request.Name} already exist.");
        }
Exemplo n.º 14
0
        public void FirstRun(ApiKeyEntity apiKeyEntity)
        {
            // Create the table client
            CloudTableClient tableClient = _storageAccount.CreateCloudTableClient();

            // Create the table if it doesn't exist
            const string tableName = "keys";

            tableClient.CreateTableIfNotExist(tableName);

            // Get the data service context
            TableServiceContext serviceContext = tableClient.GetDataServiceContext();

            // Add the new customer to the people table
            serviceContext.AddObject("keys", apiKeyEntity);

            // Submit the operation to the table service
            serviceContext.SaveChangesWithRetries();

            ApiKeyEntity retrieveApiKey = RetrieveApiKey(apiKeyEntity.ApiKey);
        }
Exemplo n.º 15
0
        private async Task InitializeAsync()
        {
            IEnumerable <ApiKeyEntity> entities = await _shellService.GetAllActiveEntities();

            Entities = new BindableCollection <ApiKeyEntity>(entities);
            int activeEntityId = Settings.Default.ActiveEntity;

            if (activeEntityId != 0)
            {
                ApiKeyEntity entity = Entities.Single(e => e.Id == activeEntityId);
                if (entity != null)
                {
                    ApplicationHelper.ActiveEntity = entity;
                }
            }
            StatusMessage = "Initializing data...";
            await IoC.Get <EveStaticDataRepository>().Initialize;

            StatusMessage = "Initializing modules...";
            await _moduleService.InitialiseAsync();

            StatusMessage = "Ready";
        }
Exemplo n.º 16
0
        public async Task <int> Handle(AddApiKeyRequest request, CancellationToken cancellationToken)
        {
            var existing = await _storeDbContext
                           .ApiKeys
                           .Where(ak => ak.Name == request.Name)
                           .SingleOrDefaultAsync();

            if (existing == null)
            {
                var apiKey = new ApiKeyEntity(
                    request.Name,
                    request.Description,
                    ApiKeyGenerator.CreateApiKey());

                _storeDbContext.Add(apiKey);
                await _storeDbContext.SaveChangesAsync(cancellationToken);

                return(apiKey.Id);
            }

            Log.ApiKeyAlreadyExist(_logger, request.Name);
            throw new InvalidOperationException($"A ApiKey with name {request.Name} already exist.");
        }
Exemplo n.º 17
0
 /// <summary>
 /// Update an existing API key.
 /// </summary>
 /// <param name="entity">The API key to update.</param>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/> allowing the operation to be canceled.</param>
 /// <returns>A task indicating completion.</returns>
 /// <remarks>The API key token itself cannot be updated using this method.</remarks>
 public async Task UpdateAsync(ApiKeyEntity entity, CancellationToken cancellationToken = default)
 {
     await Client.PutAsync(entity, "Self", entity, cancellationToken : cancellationToken).ConfigureAwait(false);
 }
Exemplo n.º 18
0
 /// <summary>
 /// Add a new API key.
 /// </summary>
 /// <param name="entity">The API key to add.</param>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/> allowing the operation to be canceled.</param>
 /// <returns>The API key, with server-allocated properties, such as <see cref="ApiKeyEntity.Token"/> (if server-allocated),
 /// and <see cref="Entity.Id"/>, initialized.</returns>
 /// <remarks>Leaving the token blank will cause the server to generate a cryptographically random API key token. After creation, the first
 /// few characters of the token will be readable from <see cref="ApiKeyEntity.TokenPrefix"/>, but because only a cryptographically-secure
 /// hash of the token is stored internally, the token itself cannot be retrieved.</remarks>
 public async Task <ApiKeyEntity> AddAsync(ApiKeyEntity entity, CancellationToken cancellationToken = default)
 {
     return(await GroupCreateAsync <ApiKeyEntity, ApiKeyEntity>(entity, cancellationToken : cancellationToken).ConfigureAwait(false));
 }
Exemplo n.º 19
0
 public ActiveEntityChangedEvent(ApiKeyEntity newEntity)
 {
     NewEntity = newEntity;
 }
Exemplo n.º 20
0
        private static async Task <IList <JournalEntry> > getJournalEntriesAsync(ApiKey key, ApiKeyEntity apiKeyEntity,
                                                                                 int rowLimit,
                                                                                 long limitId = 0)
        {
            var       list   = new List <JournalEntry>();
            var       ckey   = await new CharacterKey(key.ApiKeyId, key.VCode).InitAsync().ConfigureAwait(false);
            Character entity = ckey.Characters.Single(c => c.CharacterId == apiKeyEntity.EntityId);
            var       res    = await entity.GetWalletJournalAsync(rowLimit).ConfigureAwait(false);

            while (res.Result.Journal.Count > 0)
            {
                var sortedList = res.Result.Journal.OrderByDescending(f => f.RefId);
                foreach (var entry in sortedList)
                {
                    if (entry.RefId == limitId)
                    {
                        return(list);
                    }
                    var newEntry = new JournalEntry();
                    newEntry.ApiKeyEntity_Id = apiKeyEntity.Id;
                    list.Add(ApiEntityMapper.Map(entry, newEntry));
                }
                try {
                    res =
                        await entity.GetWalletJournalAsync(rowLimit, sortedList.Last().RefId).ConfigureAwait(false);
                } catch (Exception) {
                    return(list);
                }
            }
            return(list);
        }
Exemplo n.º 21
0
 public async Task <ApiKeyEntity> AddAsync(ApiKeyEntity entity)
 {
     return(await Client.PostAsync <ApiKeyEntity, ApiKeyEntity>(entity, "Create", entity).ConfigureAwait(false));
 }
Exemplo n.º 22
0
 public Task <IList <JournalEntry> > GetAllJournalEntriesAsync(ApiKey key, ApiKeyEntity entity,
                                                               Func <JournalEntry> transactionFactory)
 {
     return(getJournalEntriesAsync(key, entity, 2560));
 }
Exemplo n.º 23
0
 public async Task RemoveAsync(ApiKeyEntity entity)
 {
     await Client.DeleteAsync(entity, "Self", entity).ConfigureAwait(false);
 }
Exemplo n.º 24
0
 public Task <IList <Transaction> > GetAllTransactionsAsync(ApiKey key, ApiKeyEntity entity,
                                                            Func <Transaction> transactionFactory)
 {
     return(getTransactionsAsync(key, entity, 2560));
 }
Exemplo n.º 25
0
 public Task <IList <JournalEntry> > GetNewJournalEntriesAsync(ApiKey key, ApiKeyEntity entity, long latestId)
 {
     return(getJournalEntriesAsync(key, entity, 2560, latestId));
 }
Exemplo n.º 26
0
 public Task <IList <Transaction> > GetNewTransactionsAsync(ApiKey key, ApiKeyEntity entity, long latestId)
 {
     return(getTransactionsAsync(key, entity, 2560, latestId));
 }
Exemplo n.º 27
0
 public string GetPortraint(ApiKeyEntity entity)
 {
     return(new Image().GetCharacterPortrait(entity.EntityId, Image.CharacterPortraitSize.X256, @"c:\Temp"));
 }
Exemplo n.º 28
0
        public async Task <MarketOrders> GetMarketOrdersAsync(ApiKey activeKey, ApiKeyEntity apiKeyEntity)
        {
            var entity = new Character(activeKey.ApiKeyId, activeKey.VCode, apiKeyEntity.EntityId);

            return((await entity.GetMarketOrdersAsync()).Result);
        }
Exemplo n.º 29
0
 public async Task UpdateAsync(ApiKeyEntity entity)
 {
     await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false);
 }
Exemplo n.º 30
0
        private static async Task <IList <Transaction> > getTransactionsAsync(ApiKey key, ApiKeyEntity apiKeyEntity, int rowLimit,
                                                                              long limitId = 0)
        {
            var       transactions = new List <Transaction>();
            var       ckey         = await new CharacterKey(key.ApiKeyId, key.VCode).InitAsync().ConfigureAwait(false);
            Character entity       = ckey.Characters.Single(c => c.CharacterId == apiKeyEntity.EntityId);
            EveApiResponse <WalletTransactions> res = await entity.GetWalletTransactionsAsync(rowLimit).ConfigureAwait(false);

            while (res.Result.Transactions.Count > 0)
            {
                IOrderedEnumerable <WalletTransactions.Transaction> sortedList =
                    res.Result.Transactions.OrderByDescending(f => f.TransactionId);
                foreach (WalletTransactions.Transaction transaction in sortedList)
                {
                    if (transaction.TransactionId == limitId)
                    {
                        return(transactions);
                    }
                    var newTransaction = new Transaction();
                    newTransaction.ApiKeyEntity_Id = apiKeyEntity.Id;
                    transactions.Add(ApiEntityMapper.Map(transaction, newTransaction));
                }

                res = entity.GetWalletTransactions(rowLimit, sortedList.Last().TransactionId);
            }
            return(transactions);
        }