Explorar el Código

fix github login/register

Alexander Belanger hace 5 años
padre
commit
13eb7a6cb7

+ 1 - 1
.github/workflows/release.yaml

@@ -84,7 +84,7 @@ jobs:
         run: |
           go build -ldflags="-w -s -X 'github.com/porter-dev/porter/cli/cmd.Version=${{steps.tag_name.outputs.tag}}'" -a -tags cli -o ./porter ./cli &
           go build -ldflags="-w -s -X 'main.Version=${{steps.tag_name.outputs.tag}}'" -a -o ./docker-credential-porter ./cmd/docker-credential-porter/ &
-          go build -ldflags="-w -s" -a -o ./portersvr ./cmd/app/ &
+          go build -ldflags="-w -s -X 'main.Version=${{steps.tag_name.outputs.tag}}'" -a -o ./portersvr ./cmd/app/ &
           wait
         env:
           GOOS: linux

+ 2 - 0
cli/cmd/server.go

@@ -208,6 +208,8 @@ func startLocal(
 		"SQL_LITE_PATH=" + sqlLitePath,
 		"STATIC_FILE_PATH=" + staticFilePath,
 		"REDIS_ENABLED=false",
+		"GITHUB_ENABLED=false",
+		"PROVISIONER_ENABLED=false",
 	}...)
 
 	cmdPorter.Stdout = os.Stdout

+ 1 - 1
cli/cmd/version.go

@@ -7,7 +7,7 @@ import (
 )
 
 // Version will be linked by an ldflag during build
-var Version string = "v0.1.0-beta.3.4"
+var Version string = "0.2.0"
 
 var versionCmd = &cobra.Command{
 	Use:     "version",

+ 29 - 10
dashboard/src/main/auth/Login.tsx

@@ -16,6 +16,7 @@ type StateType = {
   password: string;
   emailError: boolean;
   credentialError: boolean;
+  hasGithub: boolean;
 };
 
 export default class Login extends Component<PropsType, StateType> {
@@ -24,6 +25,7 @@ export default class Login extends Component<PropsType, StateType> {
     password: "",
     emailError: false,
     credentialError: false,
+    hasGithub: true,
   };
 
   handleKeyDown = (e: any) => {
@@ -36,6 +38,13 @@ export default class Login extends Component<PropsType, StateType> {
     emailFromCLI
       ? this.setState({ email: emailFromCLI })
       : document.addEventListener("keydown", this.handleKeyDown);
+
+    // get capabilities to case on github
+    api.getCapabilities("", {}, {})
+    .then((res) => {
+      this.setState({hasGithub: res.data?.github})
+    })
+    .catch((err) => console.log(err));
   }
 
   componentWillUnmount() {
@@ -105,6 +114,25 @@ export default class Login extends Component<PropsType, StateType> {
     window.location.href = redirectUrl;
   };
 
+  renderGithubSection = () => {
+    if (this.state.hasGithub) {
+      return (
+        <>
+          <OAuthButton onClick={this.githubRedirect}>
+          <IconWrapper>
+            <Icon src={github} />
+            Log in with GitHub
+          </IconWrapper>
+          </OAuthButton>
+          <OrWrapper>
+            <Line />
+            <Or>or</Or>
+          </OrWrapper>
+        </>
+      )
+    }
+  }
+
   render() {
     let { email, password, credentialError, emailError } = this.state;
 
@@ -117,16 +145,7 @@ export default class Login extends Component<PropsType, StateType> {
           <FormWrapper>
             <Logo src={logo} />
             <Prompt>Log in to Porter</Prompt>
-            <OAuthButton onClick={this.githubRedirect}>
-              <IconWrapper>
-                <Icon src={github} />
-                Log in with GitHub
-              </IconWrapper>
-            </OAuthButton>
-            <OrWrapper>
-              <Line />
-              <Or>or</Or>
-            </OrWrapper>
+            {this.renderGithubSection()}
             <DarkMatter />
             <InputWrapper>
               <Input

+ 30 - 10
dashboard/src/main/auth/Register.tsx

@@ -17,6 +17,7 @@ type StateType = {
   confirmPassword: string;
   emailError: boolean;
   confirmPasswordError: boolean;
+  hasGithub: boolean;
 };
 
 export default class Register extends Component<PropsType, StateType> {
@@ -26,6 +27,7 @@ export default class Register extends Component<PropsType, StateType> {
     confirmPassword: "",
     emailError: false,
     confirmPasswordError: false,
+    hasGithub: true,
   };
 
   handleKeyDown = (e: any) => {
@@ -34,6 +36,13 @@ export default class Register extends Component<PropsType, StateType> {
 
   componentDidMount() {
     document.addEventListener("keydown", this.handleKeyDown);
+
+    // get capabilities to case on github
+    api.getCapabilities("", {}, {})
+    .then((res) => {      
+      this.setState({hasGithub: res.data?.github})
+    })
+    .catch((err) => console.log(err));
   }
 
   componentWillUnmount() {
@@ -106,6 +115,26 @@ export default class Register extends Component<PropsType, StateType> {
     }
   };
 
+  renderGithubSection = () => {
+    if (this.state.hasGithub) {
+      return (
+        <>
+          <OAuthButton onClick={this.githubRedirect}>
+              <IconWrapper>
+                <Icon src={github} />
+                Sign up with GitHub
+              </IconWrapper>
+            </OAuthButton>
+            <OrWrapper>
+              <Line />
+              <Or>or</Or>
+            </OrWrapper>
+        </>
+      )
+    }
+  }
+
+
   render() {
     let {
       email,
@@ -124,16 +153,7 @@ export default class Register extends Component<PropsType, StateType> {
           <FormWrapper>
             <Logo src={logo} />
             <Prompt>Sign up for Porter</Prompt>
-            <OAuthButton onClick={this.githubRedirect}>
-              <IconWrapper>
-                <Icon src={github} />
-                Sign up with GitHub
-              </IconWrapper>
-            </OAuthButton>
-            <OrWrapper>
-              <Line />
-              <Or>or</Or>
-            </OrWrapper>
+            {this.renderGithubSection()}
             <DarkMatter />
             <InputWrapper>
               <Input

+ 1 - 1
server/router/router.go

@@ -1357,7 +1357,7 @@ func New(a *api.App) *chi.Mux {
 		r.Method(
 			"GET",
 			"/capabilities",
-			requestlog.NewHandler(a.HandleGetCapabilities, l),
+			http.HandlerFunc(a.HandleGetCapabilities),
 		)
 	})