Giter Site home page Giter Site logo

azure-sdk-for-go-samples's Introduction

languages products page_type description
go
azure
sample
A collection of samples showing how to use the Azure SDK for Go.

Azure SDK for Go Samples

This repo contains a collection of sample usages of the new version of Azure/azure-sdk-for-go. All the samples are placed under sdk folder and the folder structures are corresponding to the service packages under the /sdk directory of the Azure/azure-sdk-for-go repo. You can refer to this doc to get started with Azure SDK for Go.

For general SDK help, please refer to the SDK README.

To run tests

Prerequisites

You will need Go 1.18 and latest version of resource management modules.

You will need to authenticate to Azure either by using Azure CLI to sign in or setting environment variables.

Using Azure CLI to Sign In

You could easily use az login in command line to sign in to Azure via your default browser. Detail instructions can be found in Sign in with Azure CLI.

Setting Environment Variables

If your code is going to run in a none-user-interactive environment, you can also authenticate by setting environment variables as below.

You will need the following values to authenticate to Azure

  • Subscription ID
  • Client ID
  • Client Secret
  • Tenant ID

These values can be obtained from the portal, here's the instructions:

  • Get Subscription ID

    1. Login into your Azure account
    2. Select Subscriptions in the left sidebar
    3. Select whichever subscription is needed
    4. Click on Overview
    5. Copy the Subscription ID
  • Get Client ID / Client Secret / Tenant ID

    For information on how to get Client ID, Client Secret, and Tenant ID, please refer to this document

  • Setting Environment Variables

    After you obtained the values, you need to set the following values as your environment variables

    • AZURE_CLIENT_ID
    • AZURE_CLIENT_SECRET
    • AZURE_TENANT_ID
    • AZURE_SUBSCRIPTION_ID

    To set the following environment variables on your development system:

    Windows (Note: Administrator access is required)

    1. Open the Control Panel
    2. Click System Security, then System
    3. Click Advanced system settings on the left
    4. Inside the System Properties window, click the Environment Variables… button.
    5. Click on the property you would like to change, then click the Edit… button. If the property name is not listed, then click the New… button.

    Linux-based OS :

      export AZURE_CLIENT_ID="__CLIENT_ID__"
      export AZURE_CLIENT_SECRET="__CLIENT_SECRET__"
      export AZURE_TENANT_ID="__TENANT_ID__"
      export AZURE_SUBSCRIPTION_ID="__SUBSCRIPTION_ID__"
    

Run tests

  1. Clone the repository.

    git clone https://github.com/Azure-Samples/azure-sdk-for-go-samples.git
    
  2. Set the environment variable.

    # bash
    export AZURE_SUBSCRIPTION_ID=<your Azure subscription id> 
    # If no value is set, the created resource will be deleted by default.
    # anything other than empty to keep the resources
    export KEEP_RESOURCE=1 
    
    # powershell
    $env:AZURE_SUBSCRIPTION_ID=<your Azure subscription id> 
    $env:KEEP_RESOURCE=1
    
  3. Choose one sample and run.

    cd azure-sdk-for-go-samples/sdk/resourcemanager/<service>/<single sample>
    go run main.go
    

Resources

License

This code is provided under the MIT license. See LICENSE for details.

Contribute

We welcome your contributions! For instructions and our code of conduct see CONTRIBUTING.md. And thank you!

azure-sdk-for-go-samples's People

Contributors

aahill avatar adamcrabtreemsft avatar alancere avatar arcturuszhang avatar billpratt avatar cxznmhdcxz avatar dependabot[bot] avatar esell avatar gechris avatar jerrypei1997 avatar jhendrixmsft avatar joshgav avatar laramume avatar lawrencegripper avatar marstr avatar mayelms avatar mcardosos avatar mtrilbybassett avatar radu-matei avatar rodrigc avatar sandeep-sen avatar seyadava avatar sozercan avatar sptramer avatar supernova-eng avatar tadelesh avatar tariq1890 avatar theregan avatar tzhanl avatar v-jaswel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azure-sdk-for-go-samples's Issues

[aad] add service principal authorization sample

Can we create a sample showing how to assign a service principal rights to a subscription, and rights to a specific resource? This would utilize RoleDefinitions and RoleAssignments from the authorization service. Thanks!

Sample for auth code using x/oauth2

Thanks for your contributions and feedback to the samples for Go on Azure!

This issue is a: (mark with an x)

- [ ] bug report (consider searching issues before submitting)
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Related errors and log messages

Expected/desired behavior

OS and Go version

Windows version, Linux distribution and version, macOS version.
Go version

Thanks again!

Dev and master branch should be synced often

Dev branch is running tests using the sdk and runtime dev branches. For that reason, a different dep file is needed so dep ensure can pull the correct repo branches. SO dev and master branches in this repo should be synced, with the only difference being the dep file

Thank you for your contribution and feedback! Help us review faster by providing the following information:

This issue is a: (mark with an x)

  • bug report
  • request for new sample
  • documentation issue or request
  • regression (a behavior that used to work and stopped in a new release)

Steps to reproduce:

Errors and log messages:

Expected behavior:

OS and Go versions:

Further info:

Create a single resource group per test package

Packages with more than a single example use the same resource group name. When running the examples with go test, the second example running cannot start properly creating the resource group because a resource group with the same name is being deleted on Azure. Maybe we could fix this with a single setup and teardown for all tests in the same package (all tests would run in exactly the same resource group, without deleting / creating it again in between).

Thanks for your contributions and feedback to the samples for Go on Azure!

This issue is a: (mark with an x)

- [ ] bug report (consider searching issues before submitting)
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Related errors and log messages

Expected/desired behavior

OS and Go version

Windows version, Linux distribution and version, macOS version.
Go version

Thanks again!

Add slack notifications

Thank you for your contribution and feedback! Help us review faster by providing the following information:

This issue is a: (mark with an x)

  • bug report
  • request for new sample
  • documentation issue or request
  • regression (a behavior that used to work and stopped in a new release)

Steps to reproduce:

Errors and log messages:

Expected behavior:

OS and Go versions:

Further info:

update env vars for public Travis

Thank you for your contribution and feedback! Help us review faster by providing the following information:

This issue is a: (mark with an x)

  • bug report
  • request for new sample
  • documentation issue or request
  • regression (a behavior that used to work and stopped in a new release)

update samples for v12

v12 will be released in the coming days and existing samples will need to be updated.

add README.md files to directories

Thank you for your contribution and feedback! Help us review faster by providing the following information:

This issue is a: (mark with an x)

  • bug report
  • request for new sample
  • documentation issue or request
  • regression (a behavior that used to work and stopped in a new release)

Further info:

The official Microsoft site documentation for Azure SDK for Go (docs.microsoft.com/go/azure) links to the following sample directories without a README.md:

There should be at least a short README in these directories so that users have more context after following links from the documentation site to the samples.

consolidate existing samples in this org

Container Instance examples cannot be run alone

All 4 examples depend on each other. They should be able to run on their own

Thanks for your contributions and feedback to the samples for Go on Azure!

This issue is a: (mark with an x)

- [ ] bug report (consider searching issues before submitting)
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Related errors and log messages

Expected/desired behavior

OS and Go version

Windows version, Linux distribution and version, macOS version.
Go version

Thanks again!

[network] migrate remaining network samples

Make sure existing samples are covered in network/ dir:

This issue is a: (mark with an x)

- [ ] bug report (consider searching issues before submitting)
- [x] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

PrintAndLog formatting

Hi, everyone!
Started working on #28 and stumbled upon PrintAndLog:

// PrintAndLog writes to stdout and to a logger.
func PrintAndLog(message string) {
	log.Println(message)
	fmt.Println(message)
}

The main issue I have with this is that I cannot pass formatted messages - do you think something like below would work?

// PrintfAndLog writes to stdout and to a logger.
func PrintfAndLog(format string, args ...interface{}) {
	log.Printf(format, args...)
	fmt.Printf(format, args...)
}

Also, why do we do both log.Print and fmt.Print?

Update: after using this with the actual test, I understand the need for both - the question is whether we also need to have one with the ability to format the message, as above - maybe PrintfAndLog?

Example of usage for method above here:

helpers.PrintAndLog(fmt.Sprintf("container group name: %v", *c.Name))

The question is whether this is a valid use case, or the print and log should only be used for well known // Output messages.

An alternative would be to use the testing package.

Thanks,
Radu M

add automated testing via Travis

Let's add automated testing via Travis so contributors and reviewers learn quickly if there are problems with their code.

We'll have to add secrets to Travis, and then I think our first step would be to run go test ./....

This issue is a: (mark with an x)

- [ ] bug report (consider searching issues before submitting)
- [x] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

[webapps] Azure Web Apps samples

Hi, everyone!
I'm starting to look at adding the web apps examples and I'm trying to understand what the most important operations would be, as the operation list for web apps is quite long.

Besides the usual create, list, delete operations, which ones do you think should be part of the samples (like creating a deployment slot, starting, stopping, swapping slots...)

Thanks,
Radu M

add flag to choose between OAuth grant types

The SDK and the iam/ directory in this repo support both the Client Credentials (az Service Principal) OAuth grant type and the Device Flow grant type. Currently the grant type is selected here:

func GetResourceManagementToken(grantType OAuthGrantType) (adal.OAuthTokenProvider, error) {
.

Can we make selection of the grant type configurable via flag and/or env var? Thanks!

Here's an article on the different grant types: https://alexbilbie.com/guide-to-oauth-2-grants/

This issue is a: (mark with an x)

- [ ] bug report (consider searching issues before submitting)
- [x] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

publish this repo

content in this repo isn't sensitive, so I think as soon as the structure is satisfactory we should make it public. thoughts? objections?

Starting a list of items to complete prior to publication:

  • Write README (#23)
  • Update code for SDK v12 (#29)
  • Make sure Travis tests run (#25)

/cc @sptramer @salameer @marstr

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.