예제 #1
0
        public ConfigTest()
        {
            var dotenvPath = GetEnvFilePath();

            DotEnv.Load(options: new DotEnvOptions(
                            envFilePaths: new[] { dotenvPath }
                            ));
            var dotenv = DotEnv.Read(options: new DotEnvOptions(
                                         envFilePaths: new[] { dotenvPath }
                                         ));

            WORKFLOW_ID     = dotenv["WORKFLOW_ID"];
            TRACE_ID        = dotenv["TRACE_ID"];
            MY_GROUP        = dotenv["MY_GROUP"];
            OTHER_GROUP     = dotenv["OTHER_GROUP"];
            ACCOUNT_API_URL = dotenv["ACCOUNT_API_URL"];
            TRACE_API_URL   = dotenv["TRACE_API_URL"];
            MEDIA_API_URL   = dotenv["MEDIA_API_URL"];

            // Bot 1
            PEM_PRIVATEKEY = dotenv["PEM_PRIVATEKEY"].Replace("\\n", "\n");

            // // Bot 2
            PEM_PRIVATEKEY_2 = dotenv["PEM_PRIVATEKEY_2"].Replace("\\n", "\n");
        }
예제 #2
0
        public BaseRepository(IMongoDbSettings settings, string collection)
        {
            var client   = new MongoClient(DotEnv.Read()[Text.MongoDbUri]);
            var database = client.GetDatabase(DotEnv.Read()[Text.MongoDbDb]);

            _documents = database.GetCollection <T>(collection);
        }
예제 #3
0
        public UserService(IMongoDbSettings settings)
        {
            var client   = new MongoClient(DotEnv.Read()["MONGODB_URI"]);
            var database = client.GetDatabase(DotEnv.Read()["MONGODB_DB"]);

            _users = database.GetCollection <User>("users"); //settings.CollectionName is not users
        }
예제 #4
0
 public MailService(IOptions <MailSettings> mailSettings)
 {
     _mailSettings          = mailSettings.Value;
     _mailSettings.Mail     = DotEnv.Read()["MAIL"];
     _mailSettings.Password = DotEnv.Read()["MAIL_PASSWORD"];
     //TODO: check if we could load .env and not use Read anymore
 }
예제 #5
0
        public BaseRepository(IMongoDbSettings settings, string collection)
        {
            var client   = new MongoClient(DotEnv.Read()["MONGODB_URI"]);
            var database = client.GetDatabase(DotEnv.Read()["MONGODB_DB"]);

            _documents = database.GetCollection <T>(collection);
        }
예제 #6
0
        private async Task RunBotAsync()
        {
            //Load our DotEnv file and make var
            DotEnv.Load();
            var envFile = DotEnv.Read();

            // Creates the Client, Command Service and Discord Service.
            Config = new DiscordSocketConfig
            {
                AlwaysDownloadUsers = true,
                MessageCacheSize    = 100
            };
            Client   = new DiscordSocketClient(Config);
            Commands = new CommandService();
            Services = new ServiceCollection().AddSingleton(Client).AddSingleton(Commands).BuildServiceProvider();

            // This is your bot token. You get this from http://www.discordapp.com/developers/, if you need help, read the README in the repository.
            string botToken = envFile["BOT_TOKEN"];

            // Injects the commands into the bot as something to monitor.
            await RegisterCommandsAsync();

            // Log the Bot in, as a Bot, using the token retrieved earlier, then start the bot.
            await Client.LoginAsync(Discord.TokenType.Bot, botToken);

            await Client.StartAsync();

            System.Console.WriteLine("Bot is connected!");

            // This is so the bot never closes unless there is a bug or error.
            await Task.Delay(-1);
        }
예제 #7
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            IDictionary <string, string> env = DotEnv.Read();

            webBuilder
            .UseSentry(options =>
            {
                options.Dsn        = env["SENTRY_DSN"];
                options.BeforeSend = @event =>
                {
                    if (
                        @event.Exception is DataNotFoundException ||
                        @event.Exception is DataException ||
                        @event.Exception is UnauthorizedException ||
                        @event.Exception is TokenNotValidException
                        )
                    {
                        return(null);
                    }

                    @event.ServerName = null;
                    return(@event);
                };
            })
            .UseStartup <Startup>();
        });
예제 #8
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     if (!optionsBuilder.IsConfigured)
     {
         IDictionary <string, string> env = DotEnv.Read();
         optionsBuilder.UseMySQL(env["CONNECTION_STRING"]);
     }
 }
예제 #9
0
        public DbHelper()
        {
            var envValues = DotEnv.Read();

            this.DBHost           = envValues[Constants.DB_Host_Key];
            this.DBUserName       = envValues[Constants.DB_User_name_Key];
            this.DBPassword       = envValues[Constants.DB_Password_Key];
            this.DBDatabaseName   = envValues[Constants.DB_Database_Name_Key];
            this.ConnectionString = string.Format("Server={0}; database={1}; UID={2}; password={3}", this.DBHost, this.DBDatabaseName,
                                                  this.DBUserName, this.DBPassword);
        }
예제 #10
0
        private string generateJwtToken(User user)
        {
            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = Encoding.ASCII.GetBytes(DotEnv.Read()["SECRET"].PadLeft(32));
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject            = new ClaimsIdentity(new[] { new Claim("id", user.Id) }),
                Expires            = DateTime.UtcNow.AddDays(7),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };
            var token = tokenHandler.CreateToken(tokenDescriptor);

            return(tokenHandler.WriteToken(token));
        }
예제 #11
0
        private static void attachUserToContext(HttpContext context, string token)
        {
            var tokenHandler = new JwtSecurityTokenHandler();
            var key          = Encoding.ASCII.GetBytes(DotEnv.Read()[Text.Secret].PadLeft(32));

            tokenHandler.ValidateToken(token, new TokenValidationParameters
            {
                ValidateIssuerSigningKey = true,
                IssuerSigningKey         = new SymmetricSecurityKey(key),
                ValidateIssuer           = false,
                ValidateAudience         = false,
                ClockSkew = TimeSpan.Zero
            }, out var validatedToken);

            var jwtToken = (JwtSecurityToken)validatedToken;
            var userId   = jwtToken.Claims.First(x => x.Type == Text.Id).Value;

            context.Items[Text.UserId] = userId;
        }
예제 #12
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "simple_movie_api_dotnet", Version = "v1"
                });
            });

            // modif serialize json response dan param^M
            services.AddMvc().AddJsonOptions(options =>
            {
                // custom policy
                options.JsonSerializerOptions.PropertyNamingPolicy = SnakeCaseNamingPolicy.Instance;
                // camel case
                // options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
            });

            IDictionary <string, string> env = DotEnv.Read();

            services.AddDbContext <ModelContext>(options => options.UseMySQL(env["CONNECTION_STRING"]));
            services.AddScoped <MovieGenreRepository>();
        }
예제 #13
0
        public async Task <IDictionary <string, string> > DenyAccess()
        {
            var x = DotEnv.Read();

            return(x);
        }