Use new docker login

Signed-off-by: Marcos Lilljedahl <marcosnils@gmail.com>
This commit is contained in:
Marcos Lilljedahl
2022-07-13 12:07:31 -03:00
parent e0c0b2704c
commit a5a23bf2d9
3 changed files with 19 additions and 19 deletions

View File

@@ -10,17 +10,17 @@ ENV PATH $PATH:$GOPATH
ENV DOCKER_TLS_CERTDIR="" ENV DOCKER_TLS_CERTDIR=""
ENV DOCKER_CLI_EXPERIMENTAL=enabled ENV DOCKER_CLI_EXPERIMENTAL=enabled
ENV DOCKERAPP_VERSION=v0.9.1-beta3 ENV COMPOSE_VERSION=2.6.1
ENV COMPOSE_VERSION=1.26.0
RUN pip install docker-compose==${COMPOSE_VERSION}
RUN curl -fsSL --output /tmp/docker-app-linux.tar.gz https://github.com/docker/app/releases/download/${DOCKERAPP_VERSION}/docker-app-linux.tar.gz \ # Add bash completion and set bash as default shell
&& tar xf "/tmp/docker-app-linux.tar.gz" -C /tmp/ && mkdir -p /root/.docker/cli-plugins && mv /tmp/docker-app-plugin-linux /root/.docker/cli-plugins/docker-app && rm /tmp/docker-app* RUN mkdir -p /usr/lib/docker/cli-plugins \
&& curl -LsS https://github.com/docker/compose/releases/download/v$COMPOSE_VERSION/docker-compose-linux-x86_64 -o /usr/lib/docker/cli-plugins/docker-compose \
&& chmod +x /usr/lib/docker/cli-plugins/docker-compose
# Add bash completion and set bash as default shell # Add bash completion and set bash as default shell
RUN mkdir /etc/bash_completion.d \ RUN mkdir /etc/bash_completion.d \
&& curl https://raw.githubusercontent.com/docker/cli/master/contrib/completion/bash/docker -o /etc/bash_completion.d/docker \ && curl -sS https://raw.githubusercontent.com/docker/cli/master/contrib/completion/bash/docker -o /etc/bash_completion.d/docker \
&& sed -i "s/ash/bash/" /etc/passwd && sed -i "s/ash/bash/" /etc/passwd
# Replace modprobe with a no-op to get rid of spurious warnings # Replace modprobe with a no-op to get rid of spurious warnings

View File

@@ -33,9 +33,11 @@ import (
"google.golang.org/api/people/v1" "google.golang.org/api/people/v1"
) )
var core pwd.PWDApi var (
var e event.EventApi core pwd.PWDApi
var landings = map[string][]byte{} e event.EventApi
landings = map[string][]byte{}
)
//go:embed www/* //go:embed www/*
var embeddedFiles embed.FS var embeddedFiles embed.FS
@@ -53,7 +55,6 @@ type HandlerExtender func(h *mux.Router)
func init() { func init() {
prometheus.MustRegister(latencyHistogramVec) prometheus.MustRegister(latencyHistogramVec)
staticFiles, _ = fs.Sub(embeddedFiles, "www") staticFiles, _ = fs.Sub(embeddedFiles, "www")
} }
func Bootstrap(c pwd.PWDApi, ev event.EventApi) { func Bootstrap(c pwd.PWDApi, ev event.EventApi) {
@@ -278,8 +279,8 @@ func initOauthProviders(p *types.Playground) {
ClientSecret: p.DockerClientSecret, ClientSecret: p.DockerClientSecret,
Scopes: []string{"openid"}, Scopes: []string{"openid"},
Endpoint: oauth2.Endpoint{ Endpoint: oauth2.Endpoint{
AuthURL: fmt.Sprintf("https://%s/id/oauth/authorize/", endpoint), AuthURL: fmt.Sprintf("https://%s/authorize/", endpoint),
TokenURL: fmt.Sprintf("https://%s/id/oauth/token", endpoint), TokenURL: fmt.Sprintf("https://%s/oauth/token", endpoint),
}, },
} }

View File

@@ -162,7 +162,6 @@ func LoginCallback(rw http.ResponseWriter, req *http.Request) {
} }
person, err := p.People.Get("people/me").PersonFields("emailAddresses,names").Do() person, err := p.People.Get("people/me").PersonFields("emailAddresses,names").Do()
if err != nil { if err != nil {
log.Printf("Could not initialize people service . Got: %v\n", err) log.Printf("Could not initialize people service . Got: %v\n", err)
rw.WriteHeader(http.StatusInternalServerError) rw.WriteHeader(http.StatusInternalServerError)
@@ -180,23 +179,23 @@ func LoginCallback(rw http.ResponseWriter, req *http.Request) {
tc := oauth2.NewClient(ctx, ts) tc := oauth2.NewClient(ctx, ts)
endpoint := getDockerEndpoint(playground) endpoint := getDockerEndpoint(playground)
resp, err := tc.Get(fmt.Sprintf("https://%s/api/id/v1/openid/userinfo", endpoint)) resp, err := tc.Get(fmt.Sprintf("https://%s/userinfo", endpoint))
if err != nil { if err != nil {
log.Printf("Could not get user from docker. Got: %v\n", err) log.Printf("Could not get user from docker. Got: %v\n", err)
rw.WriteHeader(http.StatusInternalServerError) rw.WriteHeader(http.StatusInternalServerError)
return return
} }
userInfo := map[string]string{} userInfo := map[string]interface{}{}
if err := json.NewDecoder(resp.Body).Decode(&userInfo); err != nil { if err := json.NewDecoder(resp.Body).Decode(&userInfo); err != nil {
log.Printf("Could not decode user info. Got: %v\n", err) log.Printf("Could not decode user info. Got: %v\n", err)
rw.WriteHeader(http.StatusInternalServerError) rw.WriteHeader(http.StatusInternalServerError)
return return
} }
user.ProviderUserId = userInfo["sub"] user.ProviderUserId = strings.Split(userInfo["sub"].(string), "|")[1]
user.Name = userInfo["preferred_username"] user.Name = userInfo["https://hub.docker.com"].(map[string]interface{})["username"].(string)
user.Email = userInfo["email"] user.Email = userInfo["https://hub.docker.com"].(map[string]interface{})["email"].(string)
// Since DockerID doesn't return a user avatar, we try with twitter through avatars.io // Since DockerID doesn't return a user avatar, we try with twitter through avatars.io
// Worst case we get a generic avatar // Worst case we get a generic avatar
user.Avatar = fmt.Sprintf("https://avatars.io/twitter/%s", user.Name) user.Avatar = fmt.Sprintf("https://avatars.io/twitter/%s", user.Name)
@@ -262,5 +261,5 @@ func getDockerEndpoint(p *types.Playground) string {
if len(p.DockerHost) > 0 { if len(p.DockerHost) > 0 {
return p.DockerHost return p.DockerHost
} }
return "id.docker.com" return "login.docker.com"
} }