示例#1
0
        /// <summary>
        /// Creates a new access from a serialized string.
        /// An access contains info about the satellite-address, the passphrase and the API-Key.
        /// </summary>
        /// <param name="accessGrant">The serialized access grant</param>
        /// <param name="config">The configuration (optional)</param>
        public Access(string accessGrant, Config config = null)
        {
            Init(config);

            try
            {
                _accessResult = SWIG.storj_uplink.uplink_parse_access(accessGrant);
                if (_accessResult.error != null && !string.IsNullOrEmpty(_accessResult.error.message))
                {
                    throw new ArgumentException(_accessResult.error.message);
                }

                _access = _accessResult.access;

                _projectResult = SWIG.storj_uplink.uplink_config_open_project(_config, _access);
                if (_projectResult.error != null && !string.IsNullOrEmpty(_projectResult.error.message))
                {
                    throw new ArgumentException(_projectResult.error.message);
                }

                _project = _projectResult.project;
            }
            catch (Exception ex)
            {
                throw new ArgumentException(ex.Message);
            }
        }
示例#2
0
        /// <summary>
        /// Creates a new access based on the satellite-adress, the API-key and the secret passphrase and by using a specific config
        /// </summary>
        /// <param name="satelliteAddress">The satellite address</param>
        /// <param name="apiKey">The API-key</param>
        /// <param name="secret">The passphrase</param>
        /// <param name="config">The configuration</param>
        public Access(string satelliteAddress, string apiKey, string secret, Config config)
        {
            Init(config);

            try
            {
                _accessResult = SWIG.storj_uplink.uplink_config_request_access_with_passphrase(_config, satelliteAddress, apiKey, secret);
                if (_accessResult.error != null && !string.IsNullOrEmpty(_accessResult.error.message))
                {
                    throw new ArgumentException(_accessResult.error.message);
                }

                _access = _accessResult.access;

                _projectResult = SWIG.storj_uplink.uplink_open_project(_access);
                if (_projectResult.error != null && !string.IsNullOrEmpty(_projectResult.error.message))
                {
                    throw new ArgumentException(_projectResult.error.message);
                }

                _project = _projectResult.project;
            }
            catch (Exception ex)
            {
                throw new ArgumentException(ex.Message);
            }
        }
示例#3
0
        /// <summary>
        /// Shares an access with the given permissions
        /// </summary>
        /// <param name="permission">The permission describes, which actions are allowed</param>
        /// <param name="prefixes">The prefixes declare for which pathes the permissions are meant for</param>
        /// <returns>The restricted access</returns>
        public Access Share(Permission permission, List <SharePrefix> prefixes)
        {
            SWIG.storj_uplink.prepare_shareprefixes((uint)prefixes.Count);

            foreach (var prefix in prefixes)
            {
                SWIG.storj_uplink.append_shareprefix(prefix.Bucket, prefix.Prefix);
            }

            SWIG.UplinkAccessResult accessResult = SWIG.storj_uplink.access_share2(_access, permission.ToSWIG());
            if (accessResult.error != null && !string.IsNullOrEmpty(accessResult.error.message))
            {
                throw new ArgumentException(accessResult.error.message);
            }

            return(new Access(accessResult.access));
        }
示例#4
0
 public void Dispose()
 {
     if (_project != null)
     {
         SWIG.UplinkError closeError = SWIG.storj_uplink.uplink_close_project(_project);
         SWIG.storj_uplink.uplink_free_error(closeError);
         _project.Dispose();
         _project = null;
     }
     if (_accessResult != null)
     {
         SWIG.storj_uplink.uplink_free_access_result(_accessResult);
         _accessResult.Dispose();
         _accessResult = null;
     }
     if (_projectResult != null)
     {
         SWIG.storj_uplink.uplink_free_project_result(_projectResult);
         _projectResult.Dispose();
         _projectResult = null;
     }
 }