Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug/dce deploy still requires gh token #57

Merged
merged 3 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## vNext
- Download deployment assets from the public url rather than using Github's GraphQL API

## v0.3.0
- Modified dce auth command to prompt for input and accept base64 encoded credentials string
Expand Down
3 changes: 1 addition & 2 deletions internal/constants/github.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
package constants

const RepoName string = "dce"
const RepoOwner string = "Optum"
const GithubAssetDownloadURL string = "https://github.com/Optum/dce/releases/latest/download/"
37 changes: 2 additions & 35 deletions internal/util/github.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package util

import (
"context"
"io"
"net/http"
"os"

"github.com/Optum/dce-cli/configs"
"github.com/Optum/dce-cli/internal/constants"
observ "github.com/Optum/dce-cli/internal/observation"
"github.com/shurcooL/githubv4"
"golang.org/x/oauth2"
)

type GithubUtil struct {
Expand All @@ -19,39 +16,9 @@ type GithubUtil struct {
}

func (u *GithubUtil) DownloadGithubReleaseAsset(assetName string) {
src := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: *u.Config.GithubToken},
)
oauthHTTPClient := oauth2.NewClient(context.Background(), src)
assetDownloadURL := constants.GithubAssetDownloadURL + assetName
req, err := http.NewRequest("GET", assetDownloadURL, nil)

variables := map[string]interface{}{
"assetName": githubv4.String(assetName),
"repoName": githubv4.String(constants.RepoName),
"repoOwner": githubv4.String(constants.RepoOwner),
}

var query struct {
Repository struct {
Releases struct {
Nodes []struct {
ReleaseAssets struct {
Nodes []struct {
URL string
}
} `graphql:"releaseAssets(last: 1, name: $assetName)"`
}
} `graphql:"releases(last: 1)"`
} `graphql:"repository(owner: $repoOwner, name: $repoName)"`
}

githubClient := githubv4.NewClient(oauthHTTPClient)
err := githubClient.Query(context.Background(), &query, variables)
if err != nil {
log.Fatalf("error: %v", err)
}
log.Debug("Github Query Response:", query.Repository.Releases.Nodes[0].ReleaseAssets.Nodes[0].URL)

req, err := http.NewRequest("GET", query.Repository.Releases.Nodes[0].ReleaseAssets.Nodes[0].URL, nil)
resp, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatalf("error: %v", err)
Expand Down