Exemplo n.º 1
0
        public object Post(AddGithubSSHKeyToCurrentUser request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);
            WebGithubProfile result;

            try {
                context.Open();
                context.LogInfo(this, string.Format("/github/sshkey POST"));

                GithubProfile user    = GithubProfile.FromId(context, context.UserId);
                UserTep       userTep = UserTep.FromId(context, context.UserId);
                userTep.LoadSSHPubKey();
                user.PublicSSHKey = userTep.SshPubKey;
                GithubClient githubClient = new GithubClient(context);
                if (!user.IsAuthorizationTokenValid())
                {
                    throw new UnauthorizedAccessException("Invalid token");
                }
                if (user.PublicSSHKey == null)
                {
                    throw new UnauthorizedAccessException("No available public ssh key");
                }
                githubClient.AddSshKey("Terradue ssh key", user.PublicSSHKey, user.Name, user.Token);
                context.LogDebug(this, string.Format("User {0} added Terradue ssh key to his github account", userTep.Username));
                result = new WebGithubProfile(user);
                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }

            return(result);
        }
Exemplo n.º 2
0
        public object Put(UpdateGithubUser request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);
            WebGithubProfile result;

            try {
                context.Open();
                context.LogInfo(this, string.Format("/github/user PUT Id='{0}'", request.Id));
                GithubProfile user = GithubProfile.FromId(context, request.Id);
                user = request.ToEntity(context, user);
                user.Store();
                user.Load(); //to get information from Github
                UserTep userTep = UserTep.FromId(context, context.UserId);
                userTep.LoadSSHPubKey();
                user.PublicSSHKey = userTep.SshPubKey;
                context.LogDebug(this, string.Format("Github account of user {0} has been updated", userTep.Username));
                result = new WebGithubProfile(user);
                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }

            return(result);
        }
Exemplo n.º 3
0
        public object Get(GetGithubUser request)
        {
            var context = TepWebContext.GetWebContext(PagePrivileges.UserView);
            WebGithubProfile result;

            try {
                context.Open();
                context.LogInfo(this, string.Format("/github/user/current GET"));
                GithubProfile user    = GithubProfile.FromId(context, context.UserId);
                UserTep       userTep = UserTep.FromId(context, context.UserId);
                userTep.LoadSSHPubKey();
                user.PublicSSHKey = userTep.SshPubKey;
                result            = new WebGithubProfile(user);
                context.Close();
            } catch (Exception e) {
                context.LogError(this, e.Message, e);
                context.Close();
                throw e;
            }

            return(result);
        }