Esempio n. 1
0
        public static TemplateObjectTO ParseJson(dynamic json)
        {
            TemplateObjectTO result = null;
            dynamic          templateObjectTOJson = json[CloudStackTypes.TemplateObjectTO];

            if (templateObjectTOJson != null)
            {
                result = new TemplateObjectTO()
                {
                    imageDataStore = templateObjectTOJson.imageDataStore,
                    format         = (string)templateObjectTOJson.format,
                    name           = (string)templateObjectTOJson.name,
                    uuid           = (string)templateObjectTOJson.uuid,
                    path           = (string)templateObjectTOJson.path,
                    checksum       = (string)templateObjectTOJson.checksum,
                    size           = (string)templateObjectTOJson.size,
                    id             = (string)templateObjectTOJson.id
                };
                result.s3DataStoreTO    = S3TO.ParseJson(templateObjectTOJson.imageDataStore);
                result.nfsDataStoreTO   = NFSTO.ParseJson(templateObjectTOJson.imageDataStore);
                result.primaryDataStore = PrimaryDataStoreTO.ParseJson(templateObjectTOJson.imageDataStore);
            }

            return(result);
        }
Esempio n. 2
0
        public static S3TO ParseJson(dynamic json)
        {
            S3TO    result   = null;
            dynamic s3TOJson = json[CloudStackTypes.S3TO];

            if (s3TOJson != null)
            {
                result = new S3TO()
                {
                    bucketName = (string)s3TOJson.bucketName,
                    secretKey  = (string)s3TOJson.secretKey,
                    accessKey  = (string)s3TOJson.accessKey,
                    endpoint   = (string)s3TOJson.endPoint,
                    httpsFlag  = (bool)s3TOJson.httpsFlag
                };
                // Delete security credentials in original command.  Prevents logger from spilling the beans, as it were.
                s3TOJson.secretKey = string.Empty;
                s3TOJson.accessKey = string.Empty;
            }
            return(result);
        }
Esempio n. 3
0
 public static S3TO ParseJson(dynamic json)
 {
     S3TO result = null;
     if (json != null)
     {
         dynamic s3TOJson = json[CloudStackTypes.S3TO];
         if (s3TOJson != null)
         {
             result = new S3TO()
             {
                 bucketName = (string)s3TOJson.bucketName,
                 secretKey = (string)s3TOJson.secretKey,
                 accessKey = (string)s3TOJson.accessKey,
                 endpoint = (string)s3TOJson.endPoint,
                 httpsFlag = (bool)s3TOJson.httpsFlag
             };
             // Delete security credentials in original command. Prevents logger from spilling the beans, as it were.
             s3TOJson.secretKey = string.Empty;
             s3TOJson.accessKey = string.Empty;
         }
     }
     return result;
 }
        private static void DownloadS3ObjectToFile(string srcObjectKey, S3TO srcS3TO, string destFile)
        {
            AmazonS3Config S3Config = new AmazonS3Config
            {
                ServiceURL = srcS3TO.endpoint,
                CommunicationProtocol = Amazon.S3.Model.Protocol.HTTP
            };

            if (srcS3TO.httpsFlag)
            {
                S3Config.CommunicationProtocol = Protocol.HTTPS;
            }

            try
            {
                using (AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(srcS3TO.accessKey, srcS3TO.secretKey, S3Config))
                {
                    GetObjectRequest getObjectRequest = new GetObjectRequest().WithBucketName(srcS3TO.bucketName).WithKey(srcObjectKey);

                    using (S3Response getObjectResponse = client.GetObject(getObjectRequest))
                    {
                        using (Stream s = getObjectResponse.ResponseStream)
                        {
                            using (FileStream fs = new FileStream(destFile, FileMode.Create, FileAccess.Write))
                            {
                                byte[] data = new byte[524288];
                                int bytesRead = 0;
                                do
                                {
                                    bytesRead = s.Read(data, 0, data.Length);
                                    fs.Write(data, 0, bytesRead);
                                }
                                while (bytesRead > 0);
                                fs.Flush();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string errMsg = "Download from S3 url" + srcS3TO.endpoint + " said: " + ex.Message;
                logger.Error(errMsg, ex);
                throw new Exception(errMsg, ex);
            }
        }
Esempio n. 5
0
 public static S3TO ParseJson(dynamic json)
 {
     S3TO result = null;
     dynamic s3TOJson = json[CloudStackTypes.S3TO];
     if (s3TOJson != null)
     {
         result = new S3TO()
         {
             bucketName = (string)s3TOJson.bucketName,
             secretKey = (string)s3TOJson.secretKey,
             accessKey = (string)s3TOJson.accessKey,
             endpoint = (string)s3TOJson.endPoint,
             httpsFlag = (bool)s3TOJson.httpsFlag
         };
     }
     return result;
 }