public async Task <SetApiScopeResponse> SetApiScopeAsync(SetApiParam param, CancellationToken cancellationToken)
        {
            var retVal = new SetApiScopeResponse();

            var apiScope = await _repository.GetApiScopeAsync(new GatApiScopeParam
            {
                Authority = param.Authority,
                Name      = param.Name
            }, cancellationToken);

            if (apiScope == null)
            {
                apiScope = new ApiScope
                {
                    Name        = param.Name,
                    DisplayName = param.Name // ensure got display name if not set from param
                };

                retVal.Created = true;
            }

            if (!string.IsNullOrEmpty(param.DisplayName))
            {
                apiScope.DisplayName = param.DisplayName;
            }

            if (!param.DryRun)
            {
                await _repository.SetApiScopeAsync(apiScope, param, cancellationToken);
            }

            retVal.ApiScope = apiScope;
            retVal.DryRun   = param.DryRun;
            return(retVal);
        }
        public async Task SetApiScopeAsync(ApiScope apiScope, SetApiParam param, CancellationToken cancellationToken)
        {
            var config = await GetConfigDaoAsync(param.Authority, cancellationToken);

            var newApis = config.Apis == null ? new List <ApiScope>() : new List <ApiScope>(config.Apis);
            var oldApi  = newApis.Where(e => e.Name.Equals(apiScope.Name, StringComparison.Ordinal)).FirstOrDefault();

            if (oldApi != null)
            {
                newApis.Remove(oldApi);
            }
            newApis.Add(apiScope);
            config.Apis = newApis;
            await SetConfigDaoAsync(param.Authority, cancellationToken, config);
        }