コード例 #1
0
            public async Task <CommonMessage> Allow(
                string userId,
                string resource,
                string action,
                string _namespace,
                CancellationToken cancellationToken = default)
            {
                var param = new AllowParam(resource, action)
                {
                    UserId    = userId,
                    Resource  = resource,
                    Namespace = _namespace
                };
                var res = await client.Request <AllowResponse>(param.CreateRequest(), cancellationToken);

                return(res.Result);
            }
コード例 #2
0
            /// <summary>
            /// 允许某个用户操作某个资源
            /// </summary>
            /// <param name="resource"></param>
            /// <param name="action"></param>
            /// <param name="userId"></param>
            /// <param name="role"></param>
            /// <param name="cancellationToken"></param>
            /// <returns></returns>
            /// TODO: 下个大版本去除
            /// WARNING: 去除 CancellationToken cancellationToken = default 参数以避免与重载函数冲突
            public async Task <CommonMessage> Allow(
                string resource,
                string action,
                string userId = null,
                string role   = null
                )
            {
                var param = new AllowParam(resource, action)
                {
                    UserId   = userId,
                    RoleCode = role,
                };
                await client.GetAccessToken();

                var res = await client.Request <AllowResponse>(param.CreateRequest());

                return(res.Result);
            }
コード例 #3
0
            /// <summary>
            /// 允许某个用户操作某个资源
            /// </summary>
            /// <param name="resource"></param>
            /// <param name="action"></param>
            /// <param name="userId"></param>
            /// <param name="role"></param>
            /// <param name="cancellationToken"></param>
            /// <returns></returns>
            public async Task <CommonMessage> Allow(
                string resource,
                string action,
                string userId = null,
                string role   = null,
                CancellationToken cancellationToken = default)
            {
                var param = new AllowParam()
                {
                    Resource = resource,
                    Action   = action,
                    UserId   = userId,
                    RoleCode = role,
                };
                await client.GetAccessToken();

                var res = await client.Request <AllowResponse>(param.CreateRequest(), cancellationToken);

                return(res.Result);
            }
コード例 #4
0
        public override ExitCode Execute()
        {
            // Get the base directory
            DirectoryReference BaseDir = new DirectoryReference(ParseParamValue("BaseDir"));

            if (!DirectoryReference.Exists(BaseDir))
            {
                throw new AutomationException("Base directory '{0}' does not exist", BaseDir);
            }

            // Find a list of restricted folders, and remove any names which are explicitly whitelisted
            HashSet <string> RestrictedNames = new HashSet <string>(PlatformExports.RestrictedFolderNames.Select(x => x.DisplayName), StringComparer.InvariantCultureIgnoreCase);

            foreach (string AllowParam in ParseParamValues("Allow"))
            {
                RestrictedNames.ExceptWith(AllowParam.Split('+'));
            }

            // Find all the folders which are problematic
            CommandUtils.Log("Searching for folders under {0} named {1}...", BaseDir, String.Join(", ", RestrictedNames));
            List <DirectoryInfo> ProblemFolders = new List <DirectoryInfo>();

            FindRestrictedFolders(new DirectoryInfo(BaseDir.FullName), RestrictedNames, ProblemFolders);

            // Print out all the restricted folders
            if (ProblemFolders.Count > 0)
            {
                CommandUtils.LogError("Found {0} {1} which should not be distributed:", ProblemFolders.Count, (ProblemFolders.Count == 1) ? "folder" : "folders");
                foreach (DirectoryInfo ProblemFolder in ProblemFolders)
                {
                    CommandUtils.LogError("    {0}{1}...", new DirectoryReference(ProblemFolder).MakeRelativeTo(BaseDir), Path.DirectorySeparatorChar);
                }
                return(ExitCode.Error_Unknown);
            }

            // Otherwise return success
            CommandUtils.Log("No restricted folders found under {0}", BaseDir);
            return(ExitCode.Success);
        }