Ejemplo n.º 1
0
        public async Task <IActionResult> CreateAmazonAccount(int id)
        {
            var username     = ApplicationUtility.GetTokenAttribute(Request.Headers["Authorization"], "sub");
            var service      = new InstituteRepositoryService(connString);
            var institute    = (await service.GetInstituteById(id)).Name;
            var bucketSevice = new AmazonS3Service();
            var bucketName   = GetName(institute);
            await bucketSevice.CreateBucketToS3(bucketName);

            var iamService   = new AmazonIAMService();
            var iamUserName  = GetName(institute);
            var accesKeyInfo = await iamService.CreateIAMUser("/", iamUserName);

            var amazonAccountModel = new InstituteAmazonAccount()
            {
                AccessKey   = accesKeyInfo.AccessKey,
                Actor       = username,
                BucketName  = bucketName,
                IamUsername = iamUserName,
                InstituteId = id,
                SecretKey   = accesKeyInfo.SecurityKey
            };
            await service.CreateInstituteAmazonAccount(amazonAccountModel);

            var response = new GenericResponse <string>()
            {
                IsSuccess    = true,
                Message      = "Cloud account created successfully.",
                ResponseCode = 200,
                Result       = "Success"
            };

            return(Ok(response));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CreateBucket(BucketModel model)
        {
            var service = new AmazonS3Service();
            await service.CreateBucketToS3(model.Name);

            var response = new GenericResponse <string>()
            {
                IsSuccess    = true,
                Message      = "Bucket created successfully.",
                ResponseCode = 200,
                Result       = "Success"
            };

            return(Ok(response));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreateIAM(IAMModel model)
        {
            var s3service = new AmazonS3Service();
            await s3service.CreateBucketToS3(model.BucketName);

            var iamservice = new AmazonIAMService();
            await iamservice.CreateIAMUser(@"/" + model.BucketName + @"/", model.UserName);

            var response = new GenericResponse <string>()
            {
                IsSuccess    = true,
                Message      = "User created in IIM successfully.",
                ResponseCode = 200,
                Result       = "Success"
            };

            return(Ok(response));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create(PublisherModel model)
        {
            var username = ApplicationUtility.GetTokenAttribute(Request.Headers["Authorization"], "sub");
            var service  = new PublisherRepositoryService(connString);
            var pubId    = await service.CreatePublisher(model, username);

            PublisherAmazonAccount amazonAccountModel;

            if (model.CloudAccountRequired)
            {
                var bucketSevice = new AmazonS3Service();
                var bucketName   = GetName(model.PublisherName);
                await bucketSevice.CreateBucketToS3(bucketName);

                var iamService   = new AmazonIAMService();
                var iamUserName  = GetName(model.PublisherName);
                var accesKeyInfo = await iamService.CreateIAMUser("/", iamUserName);

                amazonAccountModel = new PublisherAmazonAccount()
                {
                    AccessKey   = accesKeyInfo.AccessKey,
                    Actor       = username,
                    BucketName  = bucketName,
                    IamUsername = iamUserName,
                    PublisherId = pubId,
                    SecretKey   = accesKeyInfo.SecurityKey
                };
                await service.CreatePublisherAmazonAccount(amazonAccountModel);
            }
            var response = new GenericResponse <int>()
            {
                IsSuccess    = true,
                Message      = "Publisher created successfully.",
                ResponseCode = 200,
                Result       = pubId
            };

            return(Ok(response));
        }