public void Init() { var stream = GetValidStream(); var options = new CredentialProfileOptions { AccessKey = System.Environment.GetEnvironmentVariable("AWSACCESSKEY"), SecretKey = System.Environment.GetEnvironmentVariable("AWSSECRET") }; var profile = new Amazon.Runtime.CredentialManagement.CredentialProfile("basic_profile", options); var netSDKFile = new NetSDKCredentialsFile(); var region = Amazon.RegionEndpoint.GetBySystemName(stream.AwsRegion); var creds = AWSCredentialsFactory.GetAWSCredentials(profile, netSDKFile); var connection = new AwsHttpConnection(creds, region); var pool = new SingleNodeConnectionPool(new Uri(stream.ElasticSearchDomainName)); var config = new Nest.ConnectionSettings(pool, connection); var client = new ElasticClient(config); if (client.Indices.Exists(stream.ElasticSearchIndexName).Exists) { var res = client.Indices.Delete(stream.ElasticSearchIndexName); Console.WriteLine(res.DebugInformation); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddControllersWithViews(); services.AddIdentity <ApplicationUser, IdentityRole>(options => { options.Password.RequireLowercase = false; options.Password.RequireUppercase = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequireDigit = false; }) .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); //Navigate users to login page if they are trying to access to authorized page while not logged in services.ConfigureApplicationCookie(options => options.LoginPath = "/Home/LogIn"); //method to register the profile. var options = new CredentialProfileOptions { AccessKey = Configuration.GetConnectionString("AWSAccessKey"), SecretKey = Configuration.GetConnectionString("AWSSecretKey"), }; var profile = new CredentialProfile("default", options); profile.Region = RegionEndpoint.USEast1; var netSDKFile = new NetSDKCredentialsFile(); netSDKFile.RegisterProfile(profile); }
private void btnCreateProfile_Click(object sender, EventArgs e) { String strProfileName = txtAWSProfileName.Text.Trim(); String strAccessKey = txtAWSAccessKey.Text.Trim(); String strSecretKey = txtAWSSecretKey.Text.Trim(); String strRegionServiceName = GetRegionEndpointServiceName(cboAWSRegions.Text.Trim()); var AmazonRegionEndpoint = RegionEndpoint.GetBySystemName(strRegionServiceName); var AWSProfileOptions = new CredentialProfileOptions { AccessKey = strAccessKey, SecretKey = strSecretKey }; var AWSProfile = new Amazon.Runtime.CredentialManagement.CredentialProfile(strProfileName, AWSProfileOptions); AWSProfile.Region = AmazonRegionEndpoint; //var AWSCredentialsFile = new Amazon.Runtime.CredentialManagement.SharedCredentialsFile(); var netSDKFile = new NetSDKCredentialsFile(); netSDKFile.RegisterProfile(AWSProfile); //refreshed the list of available profiles GetSavedProfiles(); GetProfilesToCleanUp(); //clear Create Profile Fields txtAWSProfileName.Text = ""; txtAWSAccessKey.Text = ""; txtAWSSecretKey.Text = ""; cboAWSRegions.Text = ""; cboAWSRegions.SelectedIndex = -1; btnCreateProfile.Enabled = false; }
public async Task <InvokeResult> InitAsync(DataStream stream) { _stream = stream; var options = new CredentialProfileOptions { AccessKey = stream.AwsAccessKey, SecretKey = stream.AwsSecretKey }; var profile = new Amazon.Runtime.CredentialManagement.CredentialProfile($"awsprofile_{stream.Id}", options); var netSDKFile = new NetSDKCredentialsFile(); netSDKFile.RegisterProfile(profile); var creds = AWSCredentialsFactory.GetAWSCredentials(profile, netSDKFile); try { _s3Client = new AmazonS3Client(creds, AWSRegionMappings.MapRegion(stream.AwsRegion)); await _s3Client.EnsureBucketExistsAsync(stream.S3BucketName); } catch (AmazonS3Exception amazonS3Exception) { _logger.AddException("AWSS3Connector_InitAsync", amazonS3Exception); return(InvokeResult.FromException("AWSS3Connector_InitAsync", amazonS3Exception)); } return(InvokeResult.Success); }
public DaemonService( ILogger <DaemonService> logger, Simulator simulator, Scheduler scheduler) { _logger = logger; if (!string.IsNullOrEmpty(Shared.Configuration["aws_access_key_id"]) && !string.IsNullOrEmpty(Shared.Configuration["aws_secret_access_key"])) { var credentialFile = new NetSDKCredentialsFile(); var option = new CredentialProfileOptions { AccessKey = Shared.Configuration["aws_access_key_id"], SecretKey = Shared.Configuration["aws_secret_access_key"] }; var profile = new CredentialProfile("default", option) { Region = Amazon.RegionEndpoint.EUWest1 }; credentialFile.RegisterProfile(profile); } var serviceName = Shared.Configuration["ServiceName"]; if ("simulator".Equals(serviceName, StringComparison.OrdinalIgnoreCase)) { _task = simulator; } else { _task = scheduler; } }
public async Task <IActionResult> ReplicationDetails(String tableName) { NetSDKCredentialsFile credentialsFile = new NetSDKCredentialsFile(); CredentialProfileOptions options = new CredentialProfileOptions(); options.AccessKey = HttpContext.Session.GetString("AccessKey"); options.SecretKey = HttpContext.Session.GetString("SecretKey"); credentialsFile.RegisterProfile(new CredentialProfile("default", options)); DescribeTableStatisticsRequest request = new DescribeTableStatisticsRequest(); request.ReplicationTaskArn = HttpContext.Session.GetString("ReplicationTaskArn"); request.Filters.Add(new Filter { Name = "table-name", Values = { tableName } }); var statistics = await DbMigrationService.DescribeTableStatisticsAsync(request); var item = statistics.TableStatistics.SingleOrDefault(t => t.TableName == tableName); if (item == null) { return(NotFound()); } return(View(new DisplayTableStatistics(item, displayIcon(item.TableName), statusColor(item)))); }
/// <summary> /// Creates a new profile in the AWS SDK Store for storing credentials in encrypted form. /// </summary> /// <remarks> /// The encrypted credentials in the SDK Store are located in the'%LOCALAPPDATA%\AWSToolkit' /// folder in the RegisteredAccounts.json file. /// </remarks> /// <param name="profileName">Profile name to associate with credentials.</param> /// <param name="accessKey">The access key to store with <paramref name="profileName"/>.</param> /// <param name="secretKey">The secret key to store with <paramref name="profileName"/>.</param> /// <param name="region">The AWS region to associate with <paramref name="profileName"/>.</param> /// <returns>Successful or not result.</returns> private static bool RegisterAccount(string profileName, string accessKey, string secretKey, string region) { var chain = new CredentialProfileStoreChain(); if (chain.ListProfiles().Any(p => p.Name.Equals(profileName, StringComparison.InvariantCultureIgnoreCase))) { MessageBox.Show("The profile name already exists in one or more locations.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } var options = new CredentialProfileOptions { AccessKey = accessKey, SecretKey = secretKey }; var profile = new CredentialProfile(profileName, options); var netSdkFile = new NetSDKCredentialsFile(); profile.Region = RegionEndpoint.GetBySystemName(region); netSdkFile.RegisterProfile(profile); MessageBox.Show("AWS account was stored successfully.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); }
private int GetProfileCount() { var netSDKFile = new NetSDKCredentialsFile(); var lstProfiles = netSDKFile.ListProfileNames(); int intProfileCount = lstProfiles.Count; return(intProfileCount); }
public async Task <IActionResult> Apply(LoginModel model) { DbContextService service = new DbContextService(_appSettings); try{ BaseContext context = service.CreateDbContext(model); var person = context.Person.Take(1).ToList(); ViewData["PrimaryConnectionMessage"] = "Primary Connection Test Successful"; ViewData["PrimaryConnectionError"] = false; } catch (Exception ex) { ViewData["PrimaryConnectionMessage"] = ex.Message; ViewData["PrimaryConnectionError"] = true; } if (!String.IsNullOrEmpty(model.ReplicaDatabaseName)) { try{ BaseContext context = service.CreateReplicaDbContext(model); var person = context.Person.Take(1).ToList(); ViewData["ReplicaConnectionMessage"] = "Secondary Connection Test Successful"; ViewData["ReplicaConnectionError"] = false; }catch (Exception ex) { ViewData["ReplicaConnectionMessage"] = ex.Message; ViewData["ReplicaConnectionError"] = true; } } if (!String.IsNullOrEmpty(model.ReplicationTaskArn) && !String.IsNullOrEmpty(model.AccessKey) && !String.IsNullOrEmpty(model.SecretKey) && !String.IsNullOrEmpty(model.EndPointArn)) { try{ NetSDKCredentialsFile credentialsFile = new NetSDKCredentialsFile(); CredentialProfileOptions options = new CredentialProfileOptions(); options.AccessKey = model.AccessKey; options.SecretKey = model.SecretKey; credentialsFile.RegisterProfile(new CredentialProfile("default", options)); TestConnectionRequest request = new TestConnectionRequest(); request.ReplicationInstanceArn = model.ReplicationTaskArn; request.EndpointArn = model.EndPointArn; var statistics = await _migrationService.TestConnectionAsync(request); ViewData["AWSConnectionMessage"] = "AWS API Connection Test Successful"; ViewData["AWSConnectionError"] = false; } catch (Exception ex) { ViewData["AWSConnectionMessage"] = ex.Message; ViewData["AWSConnectionError"] = true; } } return(Index(model)); }
private static AWSCredentials GetCredential(string profileName) { var netSDK = new NetSDKCredentialsFile(); if (netSDK.TryGetProfile(profileName, out CredentialProfile profile) && AWSCredentialsFactory.TryGetAWSCredentials(profile, netSDK, out AWSCredentials credentials)) { return(credentials); } throw new NullReferenceException($"{nameof(profileName)} not found from exsiting profile list. Make sure you have set Profile"); }
public CredentialProfile GetAwsProfile(string profileName) { var credentialFile = new NetSDKCredentialsFile(); CredentialProfile profile; if (!credentialFile.TryGetProfile(profileName, out profile)) { return(null); } return(profile); }
private static void EnsureAwsCredentials() { // http://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-config-creds.html var credentialsFile = new NetSDKCredentialsFile(); if (!credentialsFile.TryGetProfile(_defaultProfile, out var _)) { RegisterProfileFromUser(credentialsFile); } }
private void Authenticate() { CredentialProfileOptions options = new CredentialProfileOptions() { AccessKey = _accesKey, SecretKey = _secretKey }; CredentialProfile profile = new CredentialProfile("basic_profile", options); var netSDKFile = new NetSDKCredentialsFile(); netSDKFile.RegisterProfile(profile); }
private void btnRemoveProfile_Click(object sender, EventArgs e) { //Amazon.Util.ProfileManager.UnregisterProfile(cboAWSProfilesToCleanUp.Text); //var AWSProfile = new Amazon.Runtime.CredentialManagement.SharedCredentialsFile(); var netSDKFile = new NetSDKCredentialsFile(); netSDKFile.UnregisterProfile(cboAWSProfilesToCleanUp.Text); GetProfilesToCleanUp(); GetSavedProfiles(); cboAWSProfilesToCleanUp.Text = ""; btnRemoveProfile.Enabled = false; }
public AWSHelper() { var options = new CredentialProfileOptions { AccessKey = "", SecretKey = "" }; var profile = new Amazon.Runtime.CredentialManagement.CredentialProfile("basic_profile", options); profile.Region = RegionEndpoint.USWest1; var netSDKFile = new NetSDKCredentialsFile(); netSDKFile.RegisterProfile(profile); }
// dotnet test --filter "FullyQualifiedName=damper_dan_client.tests.AWSTests.UploadToS3Bucket" public void UploadToS3Bucket() { Console.WriteLine("UploadToS3Bucket"); var options = new CredentialProfileOptions { AccessKey = "AKIAJETN6IOF34SLVHTQ", SecretKey = "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" }; var profile = new Amazon.Runtime.CredentialManagement.CredentialProfile("basic_profile", options); profile.Region = RegionEndpoint.USEast1; var netSDKFile = new NetSDKCredentialsFile(); netSDKFile.RegisterProfile(profile); }
/// <summary> /// IMPORTANT: /// This creates an AWS user profile entry in the file located in this /// folder: C:\Users\<username>\AppData\Local\AWSToolkit\RegisteredAccounts.json /// /// See reference at https://docs.aws.amazon.com/sdk-for-net/v3/developer-guide/net-dg-config-creds.html /// /// This is done for expediency, experiment and example purposes. For real production functionality you do /// not want to expose your credentials in this manner. For security and credential file concerns /// see this reference: https://docs.aws.amazon.com/sdk-for-net/v2/developer-guide/net-dg-config-creds.html#creds-assign /// /// </summary> private static void CreateProfile() { var options = new CredentialProfileOptions { AccessKey = "add-user-key-here", SecretKey = "add-user-secret-here" }; var profile = new Amazon.Runtime.CredentialManagement.CredentialProfile("basic_profile", options); profile.Region = awsRegion; var netSDKFile = new NetSDKCredentialsFile(); netSDKFile.RegisterProfile(profile); }
/// <summary> /// Sets credentials for AmazonCloudWatchLogsClient /// </summary> private void ConfigureCredentials() { var options = new CredentialProfileOptions { AccessKey = "access_key", SecretKey = "secret_key" }; // TODO: These would go into appsettings.json var profile = new Amazon.Runtime.CredentialManagement.CredentialProfile("basic_profile", options); profile.Region = RegionEndpoint.USEast2; var netSdkFile = new NetSDKCredentialsFile(); netSdkFile.RegisterProfile(profile); }
private static void RegisterProfileFromUser(NetSDKCredentialsFile credentialsFile = null) { credentialsFile ??= new NetSDKCredentialsFile(); Console.Write("Access Key>"); var accessKey = Console.ReadLine(); Console.Write("Secret Key>"); var secretKey = Console.ReadLine(); RegionEndpoint region; var regions = RegionEndpoint.EnumerableAllRegions.OrderBy(r => r.SystemName).ToList(); for (int i = 0; i < regions.Count; i++) { Console.WriteLine($"{i}) {regions[i]}"); } Console.Write("Region>"); while (true) { var line = Console.ReadLine(); if (int.TryParse(line, out var index) && index >= 0 && index < regions.Count) { region = regions[index]; break; } var blank = new string(' ', line.Length); Console.SetCursorPosition("Region>".Length, Console.CursorTop - 1); Console.Write(blank); Console.SetCursorPosition("Region>".Length, Console.CursorTop); } var options = new CredentialProfileOptions { AccessKey = accessKey, SecretKey = secretKey }; var profile = new CredentialProfile(_defaultProfile, options) { Region = region }; credentialsFile.RegisterProfile(profile); }
public CredentialProfile RegisterAwsProfile(string profileName, string accessKey, string secretKey, RegionEndpoint region) { var profile = new CredentialProfile(profileName, new CredentialProfileOptions { AccessKey = accessKey, SecretKey = secretKey, }); profile.Region = region; var credentialFile = new NetSDKCredentialsFile(); credentialFile.RegisterProfile(profile); return(profile); }
static void InitializeProfile() { var options = new CredentialProfileOptions { AccessKey = "33", SecretKey = "444+Puwxq+" }; var profile = new CredentialProfile("basic_profile", options) { Region = RegionEndpoint.APSoutheast2 }; var netSDKFile = new NetSDKCredentialsFile(); netSDKFile.RegisterProfile(profile); }
public AwsEc2(ShadowsocksController controller, string accessKey, string secretKey) { // aws 配置用户名和密码 AddOrUpdateAppSettings("AWSProfileName", "aws_profile"); var options = new CredentialProfileOptions { AccessKey = accessKey, SecretKey = secretKey }; var profile = new Amazon.Runtime.CredentialManagement.CredentialProfile("aws_profile", options); var netSDKFile = new NetSDKCredentialsFile(); netSDKFile.RegisterProfile(profile); // 初始化客户端 ec2Client = new AmazonEC2Client(RegionEndpoint.USWest2); this.controller = controller; }
public static void MigrateProfile() { // Credential profile used to be stored in .net sdk credentials store. // Shared credentials file is more modern. Migrate old profile if needed. // Shows good form for profile management CredentialProfile profile; var scf = new SharedCredentialsFile(); if (!scf.TryGetProfile(profileName, out _)) { var nscf = new NetSDKCredentialsFile(); if (nscf.TryGetProfile(profileName, out profile)) { scf.RegisterProfile(profile); nscf.UnregisterProfile(profileName); } } }
private AmazonS3Client GetS3Client() { var options = new CredentialProfileOptions { AccessKey = System.Environment.GetEnvironmentVariable("AWSACCESSKEY"), SecretKey = System.Environment.GetEnvironmentVariable("AWSSECRET") }; var profile = new Amazon.Runtime.CredentialManagement.CredentialProfile("basic_profile", options); var netSDKFile = new NetSDKCredentialsFile(); netSDKFile.RegisterProfile(profile); var creds = AWSCredentialsFactory.GetAWSCredentials(profile, netSDKFile); return(new AmazonS3Client(creds, RegionEndpoint.USEast1)); }
private void GetProfilesToCleanUp() { cboAWSProfilesToCleanUp.Items.Clear(); var netSDKFile = new NetSDKCredentialsFile(); var lstProfiles = netSDKFile.ListProfileNames(); foreach (var Profile in lstProfiles) { cboAWSProfilesToCleanUp.Items.Add(Profile); } if (cboAWSProfilesToCleanUp.Items.Count == 0) { cboAWSProfilesToCleanUp.Enabled = false; } else { cboAWSProfilesToCleanUp.Enabled = true; } }
public override void Execute() { var options = new CredentialProfileOptions { AccessKey = AccessKey, SecretKey = SecretKey }; var profile = new CredentialProfile(ProfileName, options) { Region = RegionEndpoint.GetBySystemName(Region) }; var netSDKFile = new NetSDKCredentialsFile(); netSDKFile.RegisterProfile(profile); Console.WriteLine($"*** Completed registration for AWS credential profile as named '{ProfileName}' on SDK Store."); }
private AWSCredentials GetCredentials() { const string profileName = "example_profile"; const string endpointName = profileName + "_endpoint"; const string samlEndpointUrl = "https://<adfs host>/adfs/ls/IdpInitiatedSignOn.aspx?loginToRp=urn:amazon:webservices"; //Create and register our saml endpoint that will be used by our profile var endpoint = new SAMLEndpoint( endpointName, new Uri(samlEndpointUrl), SAMLAuthenticationType.Negotiate); var endpointManager = new SAMLEndpointManager(); endpointManager.RegisterEndpoint(endpoint); //Use the default credential file. This could be substituted for a targeted file. var netSdkFile = new NetSDKCredentialsFile(); CredentialProfile profile; //See if we already have the profile and create it if not if (netSdkFile.TryGetProfile(profileName, out profile).Equals(false)) { var profileOptions = new CredentialProfileOptions { EndpointName = endpointName, //This was kind of confusing as the AWS documentation did not say that this was //a comma separated string combining the principle ARN (the ARN of the identity provider) //and the ARN of the role. The documentation only shows that it's the ARN of the role. RoleArn = principleArn + "," + roleArn }; profile = new CredentialProfile(profileName, profileOptions); profile.Region = RegionEndpoint.USEast1; //Store the profile netSdkFile.RegisterProfile(profile); } return(AWSCredentialsFactory.GetAWSCredentials(profile, netSdkFile)); }
public string RegistrarCredenciais() { //Apenas para desenvolver try { var options = new CredentialProfileOptions { AccessKey = "", SecretKey = "" }; var profile = new Amazon.Runtime.CredentialManagement.CredentialProfile("root_profile", options); profile.Region = RegionEndpoint.SAEast1; var netSDKFile = new NetSDKCredentialsFile(); netSDKFile.RegisterProfile(profile); return("Registrado"); } catch (Exception e) { return("Erro" + e.Message); } }
public void subeFile() { //_environment = environment; AmazonS3Config cfg = new AmazonS3Config(); cfg.RegionEndpoint = bucketRegion; var options = new CredentialProfileOptions { AccessKey = "", SecretKey = "" }; var profile = new CredentialProfile("basic_profile", options); profile.Region = RegionEndpoint.USEast1; var netSDKFile = new NetSDKCredentialsFile(); netSDKFile.RegisterProfile(profile); s3Client = new AmazonS3Client("", "", RegionEndpoint.EUWest2); UploadFileAsync().Wait(); }
private static AmazonDynamoDBClient GetAwsClient() { CredentialProfile profile; AWSCredentials awsCredentials; var file = new NetSDKCredentialsFile(); if (!file.TryGetProfile(Application.AwsProfile, out profile)) { return(null); } if (!AWSCredentialsFactory.TryGetAWSCredentials(profile, file, out awsCredentials)) { return(null); } AmazonDynamoDBConfig config = new AmazonDynamoDBConfig(); config.RegionEndpoint = Application.AwsRegion; return(new AmazonDynamoDBClient(awsCredentials, config)); }