-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:Azure/draftv2 into karenchen/flag-fix
- Loading branch information
Showing
25 changed files
with
652 additions
and
86 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Microsoft Open Source Code of Conduct | ||
|
||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). | ||
|
||
Resources: | ||
|
||
- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) | ||
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) | ||
- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Contributing | ||
|
||
This project welcomes contributions and suggestions. Most contributions require you to | ||
agree to a Contributor License Agreement (CLA) declaring that you have the right to, | ||
and actually do, grant us the rights to use your contribution. For details, visit | ||
https://cla.microsoft.com. | ||
|
||
When you submit a pull request, a CLA-bot will automatically determine whether you need | ||
to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the | ||
instructions provided by the bot. You will only need to do this once across all repositories using our CLA. | ||
|
||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). | ||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) | ||
or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!-- BEGIN MICROSOFT SECURITY.MD V0.0.5 BLOCK --> | ||
|
||
## Security | ||
|
||
Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). | ||
|
||
If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below. | ||
|
||
## Reporting Security Issues | ||
|
||
**Please do not report security vulnerabilities through public GitHub issues.** | ||
|
||
Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report). | ||
|
||
If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc). | ||
|
||
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). | ||
|
||
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: | ||
|
||
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) | ||
* Full paths of source file(s) related to the manifestation of the issue | ||
* The location of the affected source code (tag/branch/commit or direct URL) | ||
* Any special configuration required to reproduce the issue | ||
* Step-by-step instructions to reproduce the issue | ||
* Proof-of-concept or exploit code (if possible) | ||
* Impact of the issue, including how an attacker might exploit the issue | ||
|
||
This information will help us triage your report more quickly. | ||
|
||
If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs. | ||
|
||
## Preferred Languages | ||
|
||
We prefer all communications to be in English. | ||
|
||
## Policy | ||
|
||
Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd). | ||
|
||
<!-- END MICROSOFT SECURITY.MD BLOCK --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
log "github.com/sirupsen/logrus" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/Azure/draft/pkg/config" | ||
"github.com/Azure/draft/pkg/languages" | ||
"github.com/Azure/draft/pkg/linguist" | ||
) | ||
|
||
func TestRun(t *testing.T) { | ||
mockCC := &createCmd{} | ||
mockCC.createConfig = &config.CreateConfig{} | ||
mockCC.dest = "./.." | ||
mockCC.createConfig.DeployType = "helm" | ||
mockCC.createConfig.LanguageVariables = []config.UserInputs{} | ||
mockCC.createConfig.DeployVariables = []config.UserInputs{} | ||
mockPortInput := config.UserInputs{Name: "PORT", Value: "8080"} | ||
mockAppNameInput := config.UserInputs{Name: "APPNAME", Value: "testingCreateCommand"} | ||
mockCC.createConfig.DeployVariables = append(mockCC.createConfig.DeployVariables, mockPortInput, mockAppNameInput) | ||
mockCC.createConfig.LanguageVariables = append(mockCC.createConfig.LanguageVariables, mockPortInput) | ||
|
||
oldDockerfile, _ := ioutil.ReadFile("./../Dockerfile") | ||
oldDockerignore, _ := ioutil.ReadFile("./../.dockerignore") | ||
|
||
detectedLang, lowerLang, err := mockCC.mockDetectLanguage() | ||
|
||
assert.False(t, detectedLang == nil) | ||
assert.False(t, lowerLang == "") | ||
assert.True(t, err == nil) | ||
|
||
err = mockCC.generateDockerfile(detectedLang, lowerLang) | ||
assert.True(t, err == nil) | ||
|
||
|
||
err = mockCC.createDeployment() | ||
assert.True(t, err == nil) | ||
err = ioutil.WriteFile("./../Dockerfile", oldDockerfile, 0644) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
err = ioutil.WriteFile("./../.dockerignore", oldDockerignore, 0644) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
os.RemoveAll("./../charts") | ||
} | ||
|
||
func TestInitConfig(t *testing.T) { | ||
mockCC := &createCmd{} | ||
mockCC.createConfig = &config.CreateConfig{} | ||
mockCC.dest = "./.." | ||
mockCC.createConfigPath = "./../test/templates/config.yaml" | ||
|
||
err := mockCC.initConfig() | ||
assert.True(t, err == nil) | ||
assert.True(t, mockCC.createConfig != nil) | ||
} | ||
|
||
func (mcc *createCmd) mockDetectLanguage() (*config.DraftConfig, string, error) { | ||
hasGo := false | ||
hasGoMod := false | ||
var langs []*linguist.Language | ||
var err error | ||
|
||
if mcc.createConfig.LanguageType == "" { | ||
langs, err = linguist.ProcessDir(mcc.dest) | ||
log.Debugf("linguist.ProcessDir(%v) result:\n\nError: %v", mcc.dest, err) | ||
if err != nil { | ||
return nil, "", fmt.Errorf("there was an error detecting the language: %s", err) | ||
} | ||
|
||
for _, lang := range langs { | ||
log.Debugf("%s:\t%f (%s)", lang.Language, lang.Percent, lang.Color) | ||
} | ||
|
||
log.Debugf("detected %d langs", len(langs)) | ||
|
||
if len(langs) == 0 { | ||
return nil, "", ErrNoLanguageDetected | ||
} | ||
} | ||
|
||
mcc.supportedLangs = languages.CreateLanguages(mcc.dest) | ||
|
||
if mcc.createConfig.LanguageType != "" { | ||
log.Debug("using configuration language") | ||
lowerLang := strings.ToLower(mcc.createConfig.LanguageType) | ||
langConfig := mcc.supportedLangs.GetConfig(lowerLang) | ||
if langConfig == nil { | ||
return nil, "", ErrNoLanguageDetected | ||
} | ||
|
||
return langConfig, lowerLang, nil | ||
} | ||
|
||
for _, lang := range langs { | ||
detectedLang := linguist.Alias(lang) | ||
log.Infof("--> Draft detected %s (%f%%)\n", detectedLang.Language, detectedLang.Percent) | ||
lowerLang := strings.ToLower(detectedLang.Language) | ||
|
||
if mcc.supportedLangs.ContainsLanguage(lowerLang) { | ||
if lowerLang == "go" && hasGo && hasGoMod { | ||
log.Debug("detected go and go module") | ||
lowerLang = "gomodule" | ||
} | ||
|
||
langConfig := mcc.supportedLangs.GetConfig(lowerLang) | ||
return langConfig, lowerLang, nil | ||
} | ||
log.Infof("--> Could not find a pack for %s. Trying to find the next likely language match...\n", detectedLang.Language) | ||
} | ||
return nil, "", ErrNoLanguageDetected | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestRootInitConfig(t *testing.T) { | ||
initConfig() | ||
|
||
cfgFile := "./../test/templates/config.yaml" | ||
initConfig() | ||
|
||
assert.True(t, cfgFile != "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/Azure/draft/pkg/providers" | ||
"github.com/Azure/draft/pkg/spinner" | ||
) | ||
|
||
func TestSetUpConfig(t *testing.T) { | ||
mockSetUpCmd := &providers.SetUpCmd{} | ||
mockSetUpCmd.AppName = "testingSetUpCommand" | ||
mockSetUpCmd.Provider = "Google" | ||
mockSetUpCmd.Repo = "test/repo" | ||
mockSetUpCmd.ResourceGroupName = "testResourceGroup" | ||
mockSetUpCmd.SubscriptionID = "123456789" | ||
s := spinner.CreateSpinner("--> Setting up Github OIDC...") | ||
|
||
fillSetUpConfig(mockSetUpCmd) | ||
|
||
err := runProviderSetUp(mockSetUpCmd, s) | ||
|
||
assert.True(t, err == nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: my-app | ||
name: {{APPNAME}} | ||
labels: | ||
app: my-app | ||
app: {{APPNAME}} | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: my-app | ||
app: {{APPNAME}} | ||
template: | ||
metadata: | ||
labels: | ||
app: my-app | ||
app: {{APPNAME}} | ||
spec: | ||
containers: | ||
- name: my-app | ||
image: my-app | ||
- name: {{APPNAME}} | ||
image: {{APPNAME}}:latest | ||
ports: | ||
- containerPort: {{PORT}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: my-app | ||
name: {{APPNAME}} | ||
labels: | ||
app: my-app | ||
app: {{APPNAME}} | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: my-app | ||
- name: {{APPNAME}} | ||
image: {{APPNAME}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: my-app | ||
name: {{APPNAME}} | ||
spec: | ||
type: LoadBalancer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.