repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
spacemonkeygo/openssl
ctx.go
NewCertificateStore
func NewCertificateStore() (*CertificateStore, error) { s := C.X509_STORE_new() if s == nil { return nil, errors.New("failed to allocate X509_STORE") } store := &CertificateStore{store: s} runtime.SetFinalizer(store, func(s *CertificateStore) { C.X509_STORE_free(s.store) }) return store, nil }
go
func NewCertificateStore() (*CertificateStore, error) { s := C.X509_STORE_new() if s == nil { return nil, errors.New("failed to allocate X509_STORE") } store := &CertificateStore{store: s} runtime.SetFinalizer(store, func(s *CertificateStore) { C.X509_STORE_free(s.store) }) return store, nil }
[ "func", "NewCertificateStore", "(", ")", "(", "*", "CertificateStore", ",", "error", ")", "{", "s", ":=", "C", ".", "X509_STORE_new", "(", ")", "\n", "if", "s", "==", "nil", "{", "return", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n...
// Allocate a new, empty CertificateStore
[ "Allocate", "a", "new", "empty", "CertificateStore" ]
c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730
https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/ctx.go#L250-L260
train
spacemonkeygo/openssl
ctx.go
LoadCertificatesFromPEM
func (s *CertificateStore) LoadCertificatesFromPEM(data []byte) error { pems := SplitPEM(data) for _, pem := range pems { cert, err := LoadCertificateFromPEM(pem) if err != nil { return err } err = s.AddCertificate(cert) if err != nil { return err } } return nil }
go
func (s *CertificateStore) LoadCertificatesFromPEM(data []byte) error { pems := SplitPEM(data) for _, pem := range pems { cert, err := LoadCertificateFromPEM(pem) if err != nil { return err } err = s.AddCertificate(cert) if err != nil { return err } } return nil }
[ "func", "(", "s", "*", "CertificateStore", ")", "LoadCertificatesFromPEM", "(", "data", "[", "]", "byte", ")", "error", "{", "pems", ":=", "SplitPEM", "(", "data", ")", "\n", "for", "_", ",", "pem", ":=", "range", "pems", "{", "cert", ",", "err", ":=...
// Parse a chained PEM file, loading all certificates into the Store.
[ "Parse", "a", "chained", "PEM", "file", "loading", "all", "certificates", "into", "the", "Store", "." ]
c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730
https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/ctx.go#L263-L276
train
spacemonkeygo/openssl
ctx.go
GetCertificateStore
func (c *Ctx) GetCertificateStore() *CertificateStore { // we don't need to dealloc the cert store pointer here, because it points // to a ctx internal. so we do need to keep the ctx around return &CertificateStore{ store: C.SSL_CTX_get_cert_store(c.ctx), ctx: c} }
go
func (c *Ctx) GetCertificateStore() *CertificateStore { // we don't need to dealloc the cert store pointer here, because it points // to a ctx internal. so we do need to keep the ctx around return &CertificateStore{ store: C.SSL_CTX_get_cert_store(c.ctx), ctx: c} }
[ "func", "(", "c", "*", "Ctx", ")", "GetCertificateStore", "(", ")", "*", "CertificateStore", "{", "// we don't need to dealloc the cert store pointer here, because it points", "// to a ctx internal. so we do need to keep the ctx around", "return", "&", "CertificateStore", "{", "s...
// GetCertificateStore returns the context's certificate store that will be // used for peer validation.
[ "GetCertificateStore", "returns", "the", "context", "s", "certificate", "store", "that", "will", "be", "used", "for", "peer", "validation", "." ]
c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730
https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/ctx.go#L280-L286
train
spacemonkeygo/openssl
ctx.go
AddCertificate
func (s *CertificateStore) AddCertificate(cert *Certificate) error { runtime.LockOSThread() defer runtime.UnlockOSThread() s.certs = append(s.certs, cert) if int(C.X509_STORE_add_cert(s.store, cert.x)) != 1 { return errorFromErrorQueue() } return nil }
go
func (s *CertificateStore) AddCertificate(cert *Certificate) error { runtime.LockOSThread() defer runtime.UnlockOSThread() s.certs = append(s.certs, cert) if int(C.X509_STORE_add_cert(s.store, cert.x)) != 1 { return errorFromErrorQueue() } return nil }
[ "func", "(", "s", "*", "CertificateStore", ")", "AddCertificate", "(", "cert", "*", "Certificate", ")", "error", "{", "runtime", ".", "LockOSThread", "(", ")", "\n", "defer", "runtime", ".", "UnlockOSThread", "(", ")", "\n", "s", ".", "certs", "=", "appe...
// AddCertificate marks the provided Certificate as a trusted certificate in // the given CertificateStore.
[ "AddCertificate", "marks", "the", "provided", "Certificate", "as", "a", "trusted", "certificate", "in", "the", "given", "CertificateStore", "." ]
c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730
https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/ctx.go#L290-L298
train
spacemonkeygo/openssl
ctx.go
GetCurrentCert
func (self *CertificateStoreCtx) GetCurrentCert() *Certificate { x509 := C.X509_STORE_CTX_get_current_cert(self.ctx) if x509 == nil { return nil } // add a ref if 1 != C.X_X509_add_ref(x509) { return nil } cert := &Certificate{ x: x509, } runtime.SetFinalizer(cert, func(cert *Certificate) { C.X509_free(cert.x) }) return cert }
go
func (self *CertificateStoreCtx) GetCurrentCert() *Certificate { x509 := C.X509_STORE_CTX_get_current_cert(self.ctx) if x509 == nil { return nil } // add a ref if 1 != C.X_X509_add_ref(x509) { return nil } cert := &Certificate{ x: x509, } runtime.SetFinalizer(cert, func(cert *Certificate) { C.X509_free(cert.x) }) return cert }
[ "func", "(", "self", "*", "CertificateStoreCtx", ")", "GetCurrentCert", "(", ")", "*", "Certificate", "{", "x509", ":=", "C", ".", "X509_STORE_CTX_get_current_cert", "(", "self", ".", "ctx", ")", "\n", "if", "x509", "==", "nil", "{", "return", "nil", "\n",...
// the certicate returned is only valid for the lifetime of the underlying // X509_STORE_CTX
[ "the", "certicate", "returned", "is", "only", "valid", "for", "the", "lifetime", "of", "the", "underlying", "X509_STORE_CTX" ]
c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730
https://github.com/spacemonkeygo/openssl/blob/c2dcc5cca94ac8f7f3f0c20e20050d4cce9d9730/ctx.go#L324-L340
train
jaytaylor/html2text
html2text.go
NewPrettyTablesOptions
func NewPrettyTablesOptions() *PrettyTablesOptions { return &PrettyTablesOptions{ AutoFormatHeader: true, AutoWrapText: true, ReflowDuringAutoWrap: true, ColWidth: tablewriter.MAX_ROW_WIDTH, ColumnSeparator: tablewriter.COLUMN, RowSeparator: tablewriter.ROW, CenterSeparator: tablewriter.CENTER, HeaderAlignment: tablewriter.ALIGN_DEFAULT, FooterAlignment: tablewriter.ALIGN_DEFAULT, Alignment: tablewriter.ALIGN_DEFAULT, ColumnAlignment: []int{}, NewLine: tablewriter.NEWLINE, HeaderLine: true, RowLine: false, AutoMergeCells: false, Borders: tablewriter.Border{Left: true, Right: true, Bottom: true, Top: true}, } }
go
func NewPrettyTablesOptions() *PrettyTablesOptions { return &PrettyTablesOptions{ AutoFormatHeader: true, AutoWrapText: true, ReflowDuringAutoWrap: true, ColWidth: tablewriter.MAX_ROW_WIDTH, ColumnSeparator: tablewriter.COLUMN, RowSeparator: tablewriter.ROW, CenterSeparator: tablewriter.CENTER, HeaderAlignment: tablewriter.ALIGN_DEFAULT, FooterAlignment: tablewriter.ALIGN_DEFAULT, Alignment: tablewriter.ALIGN_DEFAULT, ColumnAlignment: []int{}, NewLine: tablewriter.NEWLINE, HeaderLine: true, RowLine: false, AutoMergeCells: false, Borders: tablewriter.Border{Left: true, Right: true, Bottom: true, Top: true}, } }
[ "func", "NewPrettyTablesOptions", "(", ")", "*", "PrettyTablesOptions", "{", "return", "&", "PrettyTablesOptions", "{", "AutoFormatHeader", ":", "true", ",", "AutoWrapText", ":", "true", ",", "ReflowDuringAutoWrap", ":", "true", ",", "ColWidth", ":", "tablewriter", ...
// NewPrettyTablesOptions creates PrettyTablesOptions with default settings
[ "NewPrettyTablesOptions", "creates", "PrettyTablesOptions", "with", "default", "settings" ]
01ec452cbe43774f989516272881441cae40c16b
https://github.com/jaytaylor/html2text/blob/01ec452cbe43774f989516272881441cae40c16b/html2text.go#L44-L63
train
jaytaylor/html2text
html2text.go
FromHTMLNode
func FromHTMLNode(doc *html.Node, o ...Options) (string, error) { var options Options if len(o) > 0 { options = o[0] } ctx := textifyTraverseContext{ buf: bytes.Buffer{}, options: options, } if err := ctx.traverse(doc); err != nil { return "", err } text := strings.TrimSpace(newlineRe.ReplaceAllString( strings.Replace(ctx.buf.String(), "\n ", "\n", -1), "\n\n"), ) return text, nil }
go
func FromHTMLNode(doc *html.Node, o ...Options) (string, error) { var options Options if len(o) > 0 { options = o[0] } ctx := textifyTraverseContext{ buf: bytes.Buffer{}, options: options, } if err := ctx.traverse(doc); err != nil { return "", err } text := strings.TrimSpace(newlineRe.ReplaceAllString( strings.Replace(ctx.buf.String(), "\n ", "\n", -1), "\n\n"), ) return text, nil }
[ "func", "FromHTMLNode", "(", "doc", "*", "html", ".", "Node", ",", "o", "...", "Options", ")", "(", "string", ",", "error", ")", "{", "var", "options", "Options", "\n", "if", "len", "(", "o", ")", ">", "0", "{", "options", "=", "o", "[", "0", "...
// FromHTMLNode renders text output from a pre-parsed HTML document.
[ "FromHTMLNode", "renders", "text", "output", "from", "a", "pre", "-", "parsed", "HTML", "document", "." ]
01ec452cbe43774f989516272881441cae40c16b
https://github.com/jaytaylor/html2text/blob/01ec452cbe43774f989516272881441cae40c16b/html2text.go#L66-L84
train
jaytaylor/html2text
html2text.go
FromReader
func FromReader(reader io.Reader, options ...Options) (string, error) { newReader, err := bom.NewReaderWithoutBom(reader) if err != nil { return "", err } doc, err := html.Parse(newReader) if err != nil { return "", err } return FromHTMLNode(doc, options...) }
go
func FromReader(reader io.Reader, options ...Options) (string, error) { newReader, err := bom.NewReaderWithoutBom(reader) if err != nil { return "", err } doc, err := html.Parse(newReader) if err != nil { return "", err } return FromHTMLNode(doc, options...) }
[ "func", "FromReader", "(", "reader", "io", ".", "Reader", ",", "options", "...", "Options", ")", "(", "string", ",", "error", ")", "{", "newReader", ",", "err", ":=", "bom", ".", "NewReaderWithoutBom", "(", "reader", ")", "\n", "if", "err", "!=", "nil"...
// FromReader renders text output after parsing HTML for the specified // io.Reader.
[ "FromReader", "renders", "text", "output", "after", "parsing", "HTML", "for", "the", "specified", "io", ".", "Reader", "." ]
01ec452cbe43774f989516272881441cae40c16b
https://github.com/jaytaylor/html2text/blob/01ec452cbe43774f989516272881441cae40c16b/html2text.go#L88-L98
train
jaytaylor/html2text
html2text.go
FromString
func FromString(input string, options ...Options) (string, error) { bs := bom.CleanBom([]byte(input)) text, err := FromReader(bytes.NewReader(bs), options...) if err != nil { return "", err } return text, nil }
go
func FromString(input string, options ...Options) (string, error) { bs := bom.CleanBom([]byte(input)) text, err := FromReader(bytes.NewReader(bs), options...) if err != nil { return "", err } return text, nil }
[ "func", "FromString", "(", "input", "string", ",", "options", "...", "Options", ")", "(", "string", ",", "error", ")", "{", "bs", ":=", "bom", ".", "CleanBom", "(", "[", "]", "byte", "(", "input", ")", ")", "\n", "text", ",", "err", ":=", "FromRead...
// FromString parses HTML from the input string, then renders the text form.
[ "FromString", "parses", "HTML", "from", "the", "input", "string", "then", "renders", "the", "text", "form", "." ]
01ec452cbe43774f989516272881441cae40c16b
https://github.com/jaytaylor/html2text/blob/01ec452cbe43774f989516272881441cae40c16b/html2text.go#L101-L108
train
jaytaylor/html2text
html2text.go
paragraphHandler
func (ctx *textifyTraverseContext) paragraphHandler(node *html.Node) error { if err := ctx.emit("\n\n"); err != nil { return err } if err := ctx.traverseChildren(node); err != nil { return err } return ctx.emit("\n\n") }
go
func (ctx *textifyTraverseContext) paragraphHandler(node *html.Node) error { if err := ctx.emit("\n\n"); err != nil { return err } if err := ctx.traverseChildren(node); err != nil { return err } return ctx.emit("\n\n") }
[ "func", "(", "ctx", "*", "textifyTraverseContext", ")", "paragraphHandler", "(", "node", "*", "html", ".", "Node", ")", "error", "{", "if", "err", ":=", "ctx", ".", "emit", "(", "\"", "\\n", "\\n", "\"", ")", ";", "err", "!=", "nil", "{", "return", ...
// paragraphHandler renders node children surrounded by double newlines.
[ "paragraphHandler", "renders", "node", "children", "surrounded", "by", "double", "newlines", "." ]
01ec452cbe43774f989516272881441cae40c16b
https://github.com/jaytaylor/html2text/blob/01ec452cbe43774f989516272881441cae40c16b/html2text.go#L291-L299
train
jaytaylor/html2text
html2text.go
handleTableElement
func (ctx *textifyTraverseContext) handleTableElement(node *html.Node) error { if !ctx.options.PrettyTables { panic("handleTableElement invoked when PrettyTables not active") } switch node.DataAtom { case atom.Table: if err := ctx.emit("\n\n"); err != nil { return err } // Re-intialize all table context. ctx.tableCtx.init() // Browse children, enriching context with table data. if err := ctx.traverseChildren(node); err != nil { return err } buf := &bytes.Buffer{} table := tablewriter.NewWriter(buf) if ctx.options.PrettyTablesOptions != nil { options := ctx.options.PrettyTablesOptions table.SetAutoFormatHeaders(options.AutoFormatHeader) table.SetAutoWrapText(options.AutoWrapText) table.SetReflowDuringAutoWrap(options.ReflowDuringAutoWrap) table.SetColWidth(options.ColWidth) table.SetColumnSeparator(options.ColumnSeparator) table.SetRowSeparator(options.RowSeparator) table.SetCenterSeparator(options.CenterSeparator) table.SetHeaderAlignment(options.HeaderAlignment) table.SetFooterAlignment(options.FooterAlignment) table.SetAlignment(options.Alignment) table.SetColumnAlignment(options.ColumnAlignment) table.SetNewLine(options.NewLine) table.SetHeaderLine(options.HeaderLine) table.SetRowLine(options.RowLine) table.SetAutoMergeCells(options.AutoMergeCells) table.SetBorders(options.Borders) } table.SetHeader(ctx.tableCtx.header) table.SetFooter(ctx.tableCtx.footer) table.AppendBulk(ctx.tableCtx.body) // Render the table using ASCII. table.Render() if err := ctx.emit(buf.String()); err != nil { return err } return ctx.emit("\n\n") case atom.Tfoot: ctx.tableCtx.isInFooter = true if err := ctx.traverseChildren(node); err != nil { return err } ctx.tableCtx.isInFooter = false case atom.Tr: ctx.tableCtx.body = append(ctx.tableCtx.body, []string{}) if err := ctx.traverseChildren(node); err != nil { return err } ctx.tableCtx.tmpRow++ case atom.Th: res, err := ctx.renderEachChild(node) if err != nil { return err } ctx.tableCtx.header = append(ctx.tableCtx.header, res) case atom.Td: res, err := ctx.renderEachChild(node) if err != nil { return err } if ctx.tableCtx.isInFooter { ctx.tableCtx.footer = append(ctx.tableCtx.footer, res) } else { ctx.tableCtx.body[ctx.tableCtx.tmpRow] = append(ctx.tableCtx.body[ctx.tableCtx.tmpRow], res) } } return nil }
go
func (ctx *textifyTraverseContext) handleTableElement(node *html.Node) error { if !ctx.options.PrettyTables { panic("handleTableElement invoked when PrettyTables not active") } switch node.DataAtom { case atom.Table: if err := ctx.emit("\n\n"); err != nil { return err } // Re-intialize all table context. ctx.tableCtx.init() // Browse children, enriching context with table data. if err := ctx.traverseChildren(node); err != nil { return err } buf := &bytes.Buffer{} table := tablewriter.NewWriter(buf) if ctx.options.PrettyTablesOptions != nil { options := ctx.options.PrettyTablesOptions table.SetAutoFormatHeaders(options.AutoFormatHeader) table.SetAutoWrapText(options.AutoWrapText) table.SetReflowDuringAutoWrap(options.ReflowDuringAutoWrap) table.SetColWidth(options.ColWidth) table.SetColumnSeparator(options.ColumnSeparator) table.SetRowSeparator(options.RowSeparator) table.SetCenterSeparator(options.CenterSeparator) table.SetHeaderAlignment(options.HeaderAlignment) table.SetFooterAlignment(options.FooterAlignment) table.SetAlignment(options.Alignment) table.SetColumnAlignment(options.ColumnAlignment) table.SetNewLine(options.NewLine) table.SetHeaderLine(options.HeaderLine) table.SetRowLine(options.RowLine) table.SetAutoMergeCells(options.AutoMergeCells) table.SetBorders(options.Borders) } table.SetHeader(ctx.tableCtx.header) table.SetFooter(ctx.tableCtx.footer) table.AppendBulk(ctx.tableCtx.body) // Render the table using ASCII. table.Render() if err := ctx.emit(buf.String()); err != nil { return err } return ctx.emit("\n\n") case atom.Tfoot: ctx.tableCtx.isInFooter = true if err := ctx.traverseChildren(node); err != nil { return err } ctx.tableCtx.isInFooter = false case atom.Tr: ctx.tableCtx.body = append(ctx.tableCtx.body, []string{}) if err := ctx.traverseChildren(node); err != nil { return err } ctx.tableCtx.tmpRow++ case atom.Th: res, err := ctx.renderEachChild(node) if err != nil { return err } ctx.tableCtx.header = append(ctx.tableCtx.header, res) case atom.Td: res, err := ctx.renderEachChild(node) if err != nil { return err } if ctx.tableCtx.isInFooter { ctx.tableCtx.footer = append(ctx.tableCtx.footer, res) } else { ctx.tableCtx.body[ctx.tableCtx.tmpRow] = append(ctx.tableCtx.body[ctx.tableCtx.tmpRow], res) } } return nil }
[ "func", "(", "ctx", "*", "textifyTraverseContext", ")", "handleTableElement", "(", "node", "*", "html", ".", "Node", ")", "error", "{", "if", "!", "ctx", ".", "options", ".", "PrettyTables", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n\n", "switc...
// handleTableElement is only to be invoked when options.PrettyTables is active.
[ "handleTableElement", "is", "only", "to", "be", "invoked", "when", "options", ".", "PrettyTables", "is", "active", "." ]
01ec452cbe43774f989516272881441cae40c16b
https://github.com/jaytaylor/html2text/blob/01ec452cbe43774f989516272881441cae40c16b/html2text.go#L302-L390
train
jaytaylor/html2text
html2text.go
renderEachChild
func (ctx *textifyTraverseContext) renderEachChild(node *html.Node) (string, error) { buf := &bytes.Buffer{} for c := node.FirstChild; c != nil; c = c.NextSibling { s, err := FromHTMLNode(c, ctx.options) if err != nil { return "", err } if _, err = buf.WriteString(s); err != nil { return "", err } if c.NextSibling != nil { if err = buf.WriteByte('\n'); err != nil { return "", err } } } return buf.String(), nil }
go
func (ctx *textifyTraverseContext) renderEachChild(node *html.Node) (string, error) { buf := &bytes.Buffer{} for c := node.FirstChild; c != nil; c = c.NextSibling { s, err := FromHTMLNode(c, ctx.options) if err != nil { return "", err } if _, err = buf.WriteString(s); err != nil { return "", err } if c.NextSibling != nil { if err = buf.WriteByte('\n'); err != nil { return "", err } } } return buf.String(), nil }
[ "func", "(", "ctx", "*", "textifyTraverseContext", ")", "renderEachChild", "(", "node", "*", "html", ".", "Node", ")", "(", "string", ",", "error", ")", "{", "buf", ":=", "&", "bytes", ".", "Buffer", "{", "}", "\n", "for", "c", ":=", "node", ".", "...
// renderEachChild visits each direct child of a node and collects the sequence of // textuual representaitons separated by a single newline.
[ "renderEachChild", "visits", "each", "direct", "child", "of", "a", "node", "and", "collects", "the", "sequence", "of", "textuual", "representaitons", "separated", "by", "a", "single", "newline", "." ]
01ec452cbe43774f989516272881441cae40c16b
https://github.com/jaytaylor/html2text/blob/01ec452cbe43774f989516272881441cae40c16b/html2text.go#L508-L525
train
sparrc/go-ping
ping.go
NewPinger
func NewPinger(addr string) (*Pinger, error) { ipaddr, err := net.ResolveIPAddr("ip", addr) if err != nil { return nil, err } var ipv4 bool if isIPv4(ipaddr.IP) { ipv4 = true } else if isIPv6(ipaddr.IP) { ipv4 = false } r := rand.New(rand.NewSource(time.Now().UnixNano())) return &Pinger{ ipaddr: ipaddr, addr: addr, Interval: time.Second, Timeout: time.Second * 100000, Count: -1, id: r.Intn(math.MaxInt16), network: "udp", ipv4: ipv4, Size: timeSliceLength, Tracker: r.Int63n(math.MaxInt64), done: make(chan bool), }, nil }
go
func NewPinger(addr string) (*Pinger, error) { ipaddr, err := net.ResolveIPAddr("ip", addr) if err != nil { return nil, err } var ipv4 bool if isIPv4(ipaddr.IP) { ipv4 = true } else if isIPv6(ipaddr.IP) { ipv4 = false } r := rand.New(rand.NewSource(time.Now().UnixNano())) return &Pinger{ ipaddr: ipaddr, addr: addr, Interval: time.Second, Timeout: time.Second * 100000, Count: -1, id: r.Intn(math.MaxInt16), network: "udp", ipv4: ipv4, Size: timeSliceLength, Tracker: r.Int63n(math.MaxInt64), done: make(chan bool), }, nil }
[ "func", "NewPinger", "(", "addr", "string", ")", "(", "*", "Pinger", ",", "error", ")", "{", "ipaddr", ",", "err", ":=", "net", ".", "ResolveIPAddr", "(", "\"", "\"", ",", "addr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "e...
// NewPinger returns a new Pinger struct pointer
[ "NewPinger", "returns", "a", "new", "Pinger", "struct", "pointer" ]
ef3ab45e41b017889941ea5bb796dd502d2b5a1b
https://github.com/sparrc/go-ping/blob/ef3ab45e41b017889941ea5bb796dd502d2b5a1b/ping.go#L73-L100
train
sparrc/go-ping
ping.go
SetIPAddr
func (p *Pinger) SetIPAddr(ipaddr *net.IPAddr) { var ipv4 bool if isIPv4(ipaddr.IP) { ipv4 = true } else if isIPv6(ipaddr.IP) { ipv4 = false } p.ipaddr = ipaddr p.addr = ipaddr.String() p.ipv4 = ipv4 }
go
func (p *Pinger) SetIPAddr(ipaddr *net.IPAddr) { var ipv4 bool if isIPv4(ipaddr.IP) { ipv4 = true } else if isIPv6(ipaddr.IP) { ipv4 = false } p.ipaddr = ipaddr p.addr = ipaddr.String() p.ipv4 = ipv4 }
[ "func", "(", "p", "*", "Pinger", ")", "SetIPAddr", "(", "ipaddr", "*", "net", ".", "IPAddr", ")", "{", "var", "ipv4", "bool", "\n", "if", "isIPv4", "(", "ipaddr", ".", "IP", ")", "{", "ipv4", "=", "true", "\n", "}", "else", "if", "isIPv6", "(", ...
// SetIPAddr sets the ip address of the target host.
[ "SetIPAddr", "sets", "the", "ip", "address", "of", "the", "target", "host", "." ]
ef3ab45e41b017889941ea5bb796dd502d2b5a1b
https://github.com/sparrc/go-ping/blob/ef3ab45e41b017889941ea5bb796dd502d2b5a1b/ping.go#L213-L224
train
sparrc/go-ping
ping.go
Statistics
func (p *Pinger) Statistics() *Statistics { loss := float64(p.PacketsSent-p.PacketsRecv) / float64(p.PacketsSent) * 100 var min, max, total time.Duration if len(p.rtts) > 0 { min = p.rtts[0] max = p.rtts[0] } for _, rtt := range p.rtts { if rtt < min { min = rtt } if rtt > max { max = rtt } total += rtt } s := Statistics{ PacketsSent: p.PacketsSent, PacketsRecv: p.PacketsRecv, PacketLoss: loss, Rtts: p.rtts, Addr: p.addr, IPAddr: p.ipaddr, MaxRtt: max, MinRtt: min, } if len(p.rtts) > 0 { s.AvgRtt = total / time.Duration(len(p.rtts)) var sumsquares time.Duration for _, rtt := range p.rtts { sumsquares += (rtt - s.AvgRtt) * (rtt - s.AvgRtt) } s.StdDevRtt = time.Duration(math.Sqrt( float64(sumsquares / time.Duration(len(p.rtts))))) } return &s }
go
func (p *Pinger) Statistics() *Statistics { loss := float64(p.PacketsSent-p.PacketsRecv) / float64(p.PacketsSent) * 100 var min, max, total time.Duration if len(p.rtts) > 0 { min = p.rtts[0] max = p.rtts[0] } for _, rtt := range p.rtts { if rtt < min { min = rtt } if rtt > max { max = rtt } total += rtt } s := Statistics{ PacketsSent: p.PacketsSent, PacketsRecv: p.PacketsRecv, PacketLoss: loss, Rtts: p.rtts, Addr: p.addr, IPAddr: p.ipaddr, MaxRtt: max, MinRtt: min, } if len(p.rtts) > 0 { s.AvgRtt = total / time.Duration(len(p.rtts)) var sumsquares time.Duration for _, rtt := range p.rtts { sumsquares += (rtt - s.AvgRtt) * (rtt - s.AvgRtt) } s.StdDevRtt = time.Duration(math.Sqrt( float64(sumsquares / time.Duration(len(p.rtts))))) } return &s }
[ "func", "(", "p", "*", "Pinger", ")", "Statistics", "(", ")", "*", "Statistics", "{", "loss", ":=", "float64", "(", "p", ".", "PacketsSent", "-", "p", ".", "PacketsRecv", ")", "/", "float64", "(", "p", ".", "PacketsSent", ")", "*", "100", "\n", "va...
// Statistics returns the statistics of the pinger. This can be run while the // pinger is running or after it is finished. OnFinish calls this function to // get it's finished statistics.
[ "Statistics", "returns", "the", "statistics", "of", "the", "pinger", ".", "This", "can", "be", "run", "while", "the", "pinger", "is", "running", "or", "after", "it", "is", "finished", ".", "OnFinish", "calls", "this", "function", "to", "get", "it", "s", ...
ef3ab45e41b017889941ea5bb796dd502d2b5a1b
https://github.com/sparrc/go-ping/blob/ef3ab45e41b017889941ea5bb796dd502d2b5a1b/ping.go#L349-L385
train
Azure/go-autorest
autorest/preparer.go
Prepare
func (pf PreparerFunc) Prepare(r *http.Request) (*http.Request, error) { return pf(r) }
go
func (pf PreparerFunc) Prepare(r *http.Request) (*http.Request, error) { return pf(r) }
[ "func", "(", "pf", "PreparerFunc", ")", "Prepare", "(", "r", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Request", ",", "error", ")", "{", "return", "pf", "(", "r", ")", "\n", "}" ]
// Prepare implements the Preparer interface on PreparerFunc.
[ "Prepare", "implements", "the", "Preparer", "interface", "on", "PreparerFunc", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L51-L53
train
Azure/go-autorest
autorest/preparer.go
CreatePreparer
func CreatePreparer(decorators ...PrepareDecorator) Preparer { return DecoratePreparer( Preparer(PreparerFunc(func(r *http.Request) (*http.Request, error) { return r, nil })), decorators...) }
go
func CreatePreparer(decorators ...PrepareDecorator) Preparer { return DecoratePreparer( Preparer(PreparerFunc(func(r *http.Request) (*http.Request, error) { return r, nil })), decorators...) }
[ "func", "CreatePreparer", "(", "decorators", "...", "PrepareDecorator", ")", "Preparer", "{", "return", "DecoratePreparer", "(", "Preparer", "(", "PreparerFunc", "(", "func", "(", "r", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Request", ",", ...
// CreatePreparer creates, decorates, and returns a Preparer. // Without decorators, the returned Preparer returns the passed http.Request unmodified. // Preparers are safe to share and re-use.
[ "CreatePreparer", "creates", "decorates", "and", "returns", "a", "Preparer", ".", "Without", "decorators", "the", "returned", "Preparer", "returns", "the", "passed", "http", ".", "Request", "unmodified", ".", "Preparers", "are", "safe", "to", "share", "and", "re...
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L62-L66
train
Azure/go-autorest
autorest/preparer.go
Prepare
func Prepare(r *http.Request, decorators ...PrepareDecorator) (*http.Request, error) { if r == nil { return nil, NewError("autorest", "Prepare", "Invoked without an http.Request") } return CreatePreparer(decorators...).Prepare(r) }
go
func Prepare(r *http.Request, decorators ...PrepareDecorator) (*http.Request, error) { if r == nil { return nil, NewError("autorest", "Prepare", "Invoked without an http.Request") } return CreatePreparer(decorators...).Prepare(r) }
[ "func", "Prepare", "(", "r", "*", "http", ".", "Request", ",", "decorators", "...", "PrepareDecorator", ")", "(", "*", "http", ".", "Request", ",", "error", ")", "{", "if", "r", "==", "nil", "{", "return", "nil", ",", "NewError", "(", "\"", "\"", "...
// Prepare accepts an http.Request and a, possibly empty, set of PrepareDecorators. // It creates a Preparer from the decorators which it then applies to the passed http.Request.
[ "Prepare", "accepts", "an", "http", ".", "Request", "and", "a", "possibly", "empty", "set", "of", "PrepareDecorators", ".", "It", "creates", "a", "Preparer", "from", "the", "decorators", "which", "it", "then", "applies", "to", "the", "passed", "http", ".", ...
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L81-L86
train
Azure/go-autorest
autorest/preparer.go
WithNothing
func WithNothing() PrepareDecorator { return func(p Preparer) Preparer { return PreparerFunc(func(r *http.Request) (*http.Request, error) { return p.Prepare(r) }) } }
go
func WithNothing() PrepareDecorator { return func(p Preparer) Preparer { return PreparerFunc(func(r *http.Request) (*http.Request, error) { return p.Prepare(r) }) } }
[ "func", "WithNothing", "(", ")", "PrepareDecorator", "{", "return", "func", "(", "p", "Preparer", ")", "Preparer", "{", "return", "PreparerFunc", "(", "func", "(", "r", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Request", ",", "error", "...
// WithNothing returns a "do nothing" PrepareDecorator that makes no changes to the passed // http.Request.
[ "WithNothing", "returns", "a", "do", "nothing", "PrepareDecorator", "that", "makes", "no", "changes", "to", "the", "passed", "http", ".", "Request", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L90-L96
train
Azure/go-autorest
autorest/preparer.go
WithMethod
func WithMethod(method string) PrepareDecorator { return func(p Preparer) Preparer { return PreparerFunc(func(r *http.Request) (*http.Request, error) { r.Method = method return p.Prepare(r) }) } }
go
func WithMethod(method string) PrepareDecorator { return func(p Preparer) Preparer { return PreparerFunc(func(r *http.Request) (*http.Request, error) { r.Method = method return p.Prepare(r) }) } }
[ "func", "WithMethod", "(", "method", "string", ")", "PrepareDecorator", "{", "return", "func", "(", "p", "Preparer", ")", "Preparer", "{", "return", "PreparerFunc", "(", "func", "(", "r", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Request"...
// WithMethod returns a PrepareDecorator that sets the HTTP method of the passed request. The // decorator does not validate that the passed method string is a known HTTP method.
[ "WithMethod", "returns", "a", "PrepareDecorator", "that", "sets", "the", "HTTP", "method", "of", "the", "passed", "request", ".", "The", "decorator", "does", "not", "validate", "that", "the", "passed", "method", "string", "is", "a", "known", "HTTP", "method", ...
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L175-L182
train
Azure/go-autorest
autorest/preparer.go
WithBaseURL
func WithBaseURL(baseURL string) PrepareDecorator { return func(p Preparer) Preparer { return PreparerFunc(func(r *http.Request) (*http.Request, error) { r, err := p.Prepare(r) if err == nil { var u *url.URL if u, err = url.Parse(baseURL); err != nil { return r, err } if u.Scheme == "" { err = fmt.Errorf("autorest: No scheme detected in URL %s", baseURL) } if err == nil { r.URL = u } } return r, err }) } }
go
func WithBaseURL(baseURL string) PrepareDecorator { return func(p Preparer) Preparer { return PreparerFunc(func(r *http.Request) (*http.Request, error) { r, err := p.Prepare(r) if err == nil { var u *url.URL if u, err = url.Parse(baseURL); err != nil { return r, err } if u.Scheme == "" { err = fmt.Errorf("autorest: No scheme detected in URL %s", baseURL) } if err == nil { r.URL = u } } return r, err }) } }
[ "func", "WithBaseURL", "(", "baseURL", "string", ")", "PrepareDecorator", "{", "return", "func", "(", "p", "Preparer", ")", "Preparer", "{", "return", "PreparerFunc", "(", "func", "(", "r", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Reques...
// WithBaseURL returns a PrepareDecorator that populates the http.Request with a url.URL constructed // from the supplied baseUrl.
[ "WithBaseURL", "returns", "a", "PrepareDecorator", "that", "populates", "the", "http", ".", "Request", "with", "a", "url", ".", "URL", "constructed", "from", "the", "supplied", "baseUrl", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L207-L226
train
Azure/go-autorest
autorest/preparer.go
WithFile
func WithFile(f io.ReadCloser) PrepareDecorator { return func(p Preparer) Preparer { return PreparerFunc(func(r *http.Request) (*http.Request, error) { r, err := p.Prepare(r) if err == nil { b, err := ioutil.ReadAll(f) if err != nil { return r, err } r.Body = ioutil.NopCloser(bytes.NewReader(b)) r.ContentLength = int64(len(b)) } return r, err }) } }
go
func WithFile(f io.ReadCloser) PrepareDecorator { return func(p Preparer) Preparer { return PreparerFunc(func(r *http.Request) (*http.Request, error) { r, err := p.Prepare(r) if err == nil { b, err := ioutil.ReadAll(f) if err != nil { return r, err } r.Body = ioutil.NopCloser(bytes.NewReader(b)) r.ContentLength = int64(len(b)) } return r, err }) } }
[ "func", "WithFile", "(", "f", "io", ".", "ReadCloser", ")", "PrepareDecorator", "{", "return", "func", "(", "p", "Preparer", ")", "Preparer", "{", "return", "PreparerFunc", "(", "func", "(", "r", "*", "http", ".", "Request", ")", "(", "*", "http", ".",...
// WithFile returns a PrepareDecorator that sends file in request body.
[ "WithFile", "returns", "a", "PrepareDecorator", "that", "sends", "file", "in", "request", "body", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L300-L315
train
Azure/go-autorest
autorest/preparer.go
WithString
func WithString(v string) PrepareDecorator { return func(p Preparer) Preparer { return PreparerFunc(func(r *http.Request) (*http.Request, error) { r, err := p.Prepare(r) if err == nil { r.ContentLength = int64(len(v)) r.Body = ioutil.NopCloser(strings.NewReader(v)) } return r, err }) } }
go
func WithString(v string) PrepareDecorator { return func(p Preparer) Preparer { return PreparerFunc(func(r *http.Request) (*http.Request, error) { r, err := p.Prepare(r) if err == nil { r.ContentLength = int64(len(v)) r.Body = ioutil.NopCloser(strings.NewReader(v)) } return r, err }) } }
[ "func", "WithString", "(", "v", "string", ")", "PrepareDecorator", "{", "return", "func", "(", "p", "Preparer", ")", "Preparer", "{", "return", "PreparerFunc", "(", "func", "(", "r", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Request", "...
// WithString returns a PrepareDecorator that encodes the passed string into the body of the request // and sets the Content-Length header.
[ "WithString", "returns", "a", "PrepareDecorator", "that", "encodes", "the", "passed", "string", "into", "the", "body", "of", "the", "request", "and", "sets", "the", "Content", "-", "Length", "header", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L349-L360
train
Azure/go-autorest
autorest/preparer.go
WithJSON
func WithJSON(v interface{}) PrepareDecorator { return func(p Preparer) Preparer { return PreparerFunc(func(r *http.Request) (*http.Request, error) { r, err := p.Prepare(r) if err == nil { b, err := json.Marshal(v) if err == nil { r.ContentLength = int64(len(b)) r.Body = ioutil.NopCloser(bytes.NewReader(b)) } } return r, err }) } }
go
func WithJSON(v interface{}) PrepareDecorator { return func(p Preparer) Preparer { return PreparerFunc(func(r *http.Request) (*http.Request, error) { r, err := p.Prepare(r) if err == nil { b, err := json.Marshal(v) if err == nil { r.ContentLength = int64(len(b)) r.Body = ioutil.NopCloser(bytes.NewReader(b)) } } return r, err }) } }
[ "func", "WithJSON", "(", "v", "interface", "{", "}", ")", "PrepareDecorator", "{", "return", "func", "(", "p", "Preparer", ")", "Preparer", "{", "return", "PreparerFunc", "(", "func", "(", "r", "*", "http", ".", "Request", ")", "(", "*", "http", ".", ...
// WithJSON returns a PrepareDecorator that encodes the data passed as JSON into the body of the // request and sets the Content-Length header.
[ "WithJSON", "returns", "a", "PrepareDecorator", "that", "encodes", "the", "data", "passed", "as", "JSON", "into", "the", "body", "of", "the", "request", "and", "sets", "the", "Content", "-", "Length", "header", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/preparer.go#L364-L378
train
Azure/go-autorest
autorest/azure/environments.go
EnvironmentFromName
func EnvironmentFromName(name string) (Environment, error) { // IMPORTANT // As per @radhikagupta5: // This is technical debt, fundamentally here because Kubernetes is not currently accepting // contributions to the providers. Once that is an option, the provider should be updated to // directly call `EnvironmentFromFile`. Until then, we rely on dispatching Azure Stack environment creation // from this method based on the name that is provided to us. if strings.EqualFold(name, "AZURESTACKCLOUD") { return EnvironmentFromFile(os.Getenv(EnvironmentFilepathName)) } name = strings.ToUpper(name) env, ok := environments[name] if !ok { return env, fmt.Errorf("autorest/azure: There is no cloud environment matching the name %q", name) } return env, nil }
go
func EnvironmentFromName(name string) (Environment, error) { // IMPORTANT // As per @radhikagupta5: // This is technical debt, fundamentally here because Kubernetes is not currently accepting // contributions to the providers. Once that is an option, the provider should be updated to // directly call `EnvironmentFromFile`. Until then, we rely on dispatching Azure Stack environment creation // from this method based on the name that is provided to us. if strings.EqualFold(name, "AZURESTACKCLOUD") { return EnvironmentFromFile(os.Getenv(EnvironmentFilepathName)) } name = strings.ToUpper(name) env, ok := environments[name] if !ok { return env, fmt.Errorf("autorest/azure: There is no cloud environment matching the name %q", name) } return env, nil }
[ "func", "EnvironmentFromName", "(", "name", "string", ")", "(", "Environment", ",", "error", ")", "{", "// IMPORTANT", "// As per @radhikagupta5:", "// This is technical debt, fundamentally here because Kubernetes is not currently accepting", "// contributions to the providers. Once th...
// EnvironmentFromName returns an Environment based on the common name specified.
[ "EnvironmentFromName", "returns", "an", "Environment", "based", "on", "the", "common", "name", "specified", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/environments.go#L207-L225
train
Azure/go-autorest
autorest/azure/environments.go
EnvironmentFromFile
func EnvironmentFromFile(location string) (unmarshaled Environment, err error) { fileContents, err := ioutil.ReadFile(location) if err != nil { return } err = json.Unmarshal(fileContents, &unmarshaled) return }
go
func EnvironmentFromFile(location string) (unmarshaled Environment, err error) { fileContents, err := ioutil.ReadFile(location) if err != nil { return } err = json.Unmarshal(fileContents, &unmarshaled) return }
[ "func", "EnvironmentFromFile", "(", "location", "string", ")", "(", "unmarshaled", "Environment", ",", "err", "error", ")", "{", "fileContents", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "location", ")", "\n", "if", "err", "!=", "nil", "{", "return...
// EnvironmentFromFile loads an Environment from a configuration file available on disk. // This function is particularly useful in the Hybrid Cloud model, where one must define their own // endpoints.
[ "EnvironmentFromFile", "loads", "an", "Environment", "from", "a", "configuration", "file", "available", "on", "disk", ".", "This", "function", "is", "particularly", "useful", "in", "the", "Hybrid", "Cloud", "model", "where", "one", "must", "define", "their", "ow...
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/environments.go#L230-L239
train
Azure/go-autorest
autorest/responder.go
Respond
func Respond(r *http.Response, decorators ...RespondDecorator) error { if r == nil { return nil } return CreateResponder(decorators...).Respond(r) }
go
func Respond(r *http.Response, decorators ...RespondDecorator) error { if r == nil { return nil } return CreateResponder(decorators...).Respond(r) }
[ "func", "Respond", "(", "r", "*", "http", ".", "Response", ",", "decorators", "...", "RespondDecorator", ")", "error", "{", "if", "r", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "CreateResponder", "(", "decorators", "...", ")", ".", ...
// Respond accepts an http.Response and a, possibly empty, set of RespondDecorators. // It creates a Responder from the decorators it then applies to the passed http.Response.
[ "Respond", "accepts", "an", "http", ".", "Response", "and", "a", "possibly", "empty", "set", "of", "RespondDecorators", ".", "It", "creates", "a", "Responder", "from", "the", "decorators", "it", "then", "applies", "to", "the", "passed", "http", ".", "Respons...
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L74-L79
train
Azure/go-autorest
autorest/responder.go
ByIgnoring
func ByIgnoring() RespondDecorator { return func(r Responder) Responder { return ResponderFunc(func(resp *http.Response) error { return r.Respond(resp) }) } }
go
func ByIgnoring() RespondDecorator { return func(r Responder) Responder { return ResponderFunc(func(resp *http.Response) error { return r.Respond(resp) }) } }
[ "func", "ByIgnoring", "(", ")", "RespondDecorator", "{", "return", "func", "(", "r", "Responder", ")", "Responder", "{", "return", "ResponderFunc", "(", "func", "(", "resp", "*", "http", ".", "Response", ")", "error", "{", "return", "r", ".", "Respond", ...
// ByIgnoring returns a RespondDecorator that ignores the passed http.Response passing it unexamined // to the next RespondDecorator.
[ "ByIgnoring", "returns", "a", "RespondDecorator", "that", "ignores", "the", "passed", "http", ".", "Response", "passing", "it", "unexamined", "to", "the", "next", "RespondDecorator", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L83-L89
train
Azure/go-autorest
autorest/responder.go
ByCopying
func ByCopying(b *bytes.Buffer) RespondDecorator { return func(r Responder) Responder { return ResponderFunc(func(resp *http.Response) error { err := r.Respond(resp) if err == nil && resp != nil && resp.Body != nil { resp.Body = TeeReadCloser(resp.Body, b) } return err }) } }
go
func ByCopying(b *bytes.Buffer) RespondDecorator { return func(r Responder) Responder { return ResponderFunc(func(resp *http.Response) error { err := r.Respond(resp) if err == nil && resp != nil && resp.Body != nil { resp.Body = TeeReadCloser(resp.Body, b) } return err }) } }
[ "func", "ByCopying", "(", "b", "*", "bytes", ".", "Buffer", ")", "RespondDecorator", "{", "return", "func", "(", "r", "Responder", ")", "Responder", "{", "return", "ResponderFunc", "(", "func", "(", "resp", "*", "http", ".", "Response", ")", "error", "{"...
// ByCopying copies the contents of the http.Response Body into the passed bytes.Buffer as // the Body is read.
[ "ByCopying", "copies", "the", "contents", "of", "the", "http", ".", "Response", "Body", "into", "the", "passed", "bytes", ".", "Buffer", "as", "the", "Body", "is", "read", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L93-L103
train
Azure/go-autorest
autorest/responder.go
ByClosing
func ByClosing() RespondDecorator { return func(r Responder) Responder { return ResponderFunc(func(resp *http.Response) error { err := r.Respond(resp) if resp != nil && resp.Body != nil { if err := resp.Body.Close(); err != nil { return fmt.Errorf("Error closing the response body: %v", err) } } return err }) } }
go
func ByClosing() RespondDecorator { return func(r Responder) Responder { return ResponderFunc(func(resp *http.Response) error { err := r.Respond(resp) if resp != nil && resp.Body != nil { if err := resp.Body.Close(); err != nil { return fmt.Errorf("Error closing the response body: %v", err) } } return err }) } }
[ "func", "ByClosing", "(", ")", "RespondDecorator", "{", "return", "func", "(", "r", "Responder", ")", "Responder", "{", "return", "ResponderFunc", "(", "func", "(", "resp", "*", "http", ".", "Response", ")", "error", "{", "err", ":=", "r", ".", "Respond"...
// ByClosing returns a RespondDecorator that first invokes the passed Responder after which it // closes the response body. Since the passed Responder is invoked prior to closing the response // body, the decorator may occur anywhere within the set.
[ "ByClosing", "returns", "a", "RespondDecorator", "that", "first", "invokes", "the", "passed", "Responder", "after", "which", "it", "closes", "the", "response", "body", ".", "Since", "the", "passed", "Responder", "is", "invoked", "prior", "to", "closing", "the", ...
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L126-L138
train
Azure/go-autorest
autorest/responder.go
ByUnmarshallingJSON
func ByUnmarshallingJSON(v interface{}) RespondDecorator { return func(r Responder) Responder { return ResponderFunc(func(resp *http.Response) error { err := r.Respond(resp) if err == nil { b, errInner := ioutil.ReadAll(resp.Body) // Some responses might include a BOM, remove for successful unmarshalling b = bytes.TrimPrefix(b, []byte("\xef\xbb\xbf")) if errInner != nil { err = fmt.Errorf("Error occurred reading http.Response#Body - Error = '%v'", errInner) } else if len(strings.Trim(string(b), " ")) > 0 { errInner = json.Unmarshal(b, v) if errInner != nil { err = fmt.Errorf("Error occurred unmarshalling JSON - Error = '%v' JSON = '%s'", errInner, string(b)) } } } return err }) } }
go
func ByUnmarshallingJSON(v interface{}) RespondDecorator { return func(r Responder) Responder { return ResponderFunc(func(resp *http.Response) error { err := r.Respond(resp) if err == nil { b, errInner := ioutil.ReadAll(resp.Body) // Some responses might include a BOM, remove for successful unmarshalling b = bytes.TrimPrefix(b, []byte("\xef\xbb\xbf")) if errInner != nil { err = fmt.Errorf("Error occurred reading http.Response#Body - Error = '%v'", errInner) } else if len(strings.Trim(string(b), " ")) > 0 { errInner = json.Unmarshal(b, v) if errInner != nil { err = fmt.Errorf("Error occurred unmarshalling JSON - Error = '%v' JSON = '%s'", errInner, string(b)) } } } return err }) } }
[ "func", "ByUnmarshallingJSON", "(", "v", "interface", "{", "}", ")", "RespondDecorator", "{", "return", "func", "(", "r", "Responder", ")", "Responder", "{", "return", "ResponderFunc", "(", "func", "(", "resp", "*", "http", ".", "Response", ")", "error", "...
// ByUnmarshallingJSON returns a RespondDecorator that decodes a JSON document returned in the // response Body into the value pointed to by v.
[ "ByUnmarshallingJSON", "returns", "a", "RespondDecorator", "that", "decodes", "a", "JSON", "document", "returned", "in", "the", "response", "Body", "into", "the", "value", "pointed", "to", "by", "v", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L158-L178
train
Azure/go-autorest
autorest/responder.go
ByUnmarshallingXML
func ByUnmarshallingXML(v interface{}) RespondDecorator { return func(r Responder) Responder { return ResponderFunc(func(resp *http.Response) error { err := r.Respond(resp) if err == nil { b, errInner := ioutil.ReadAll(resp.Body) if errInner != nil { err = fmt.Errorf("Error occurred reading http.Response#Body - Error = '%v'", errInner) } else { errInner = xml.Unmarshal(b, v) if errInner != nil { err = fmt.Errorf("Error occurred unmarshalling Xml - Error = '%v' Xml = '%s'", errInner, string(b)) } } } return err }) } }
go
func ByUnmarshallingXML(v interface{}) RespondDecorator { return func(r Responder) Responder { return ResponderFunc(func(resp *http.Response) error { err := r.Respond(resp) if err == nil { b, errInner := ioutil.ReadAll(resp.Body) if errInner != nil { err = fmt.Errorf("Error occurred reading http.Response#Body - Error = '%v'", errInner) } else { errInner = xml.Unmarshal(b, v) if errInner != nil { err = fmt.Errorf("Error occurred unmarshalling Xml - Error = '%v' Xml = '%s'", errInner, string(b)) } } } return err }) } }
[ "func", "ByUnmarshallingXML", "(", "v", "interface", "{", "}", ")", "RespondDecorator", "{", "return", "func", "(", "r", "Responder", ")", "Responder", "{", "return", "ResponderFunc", "(", "func", "(", "resp", "*", "http", ".", "Response", ")", "error", "{...
// ByUnmarshallingXML returns a RespondDecorator that decodes a XML document returned in the // response Body into the value pointed to by v.
[ "ByUnmarshallingXML", "returns", "a", "RespondDecorator", "that", "decodes", "a", "XML", "document", "returned", "in", "the", "response", "Body", "into", "the", "value", "pointed", "to", "by", "v", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L182-L200
train
Azure/go-autorest
autorest/responder.go
WithErrorUnlessStatusCode
func WithErrorUnlessStatusCode(codes ...int) RespondDecorator { return func(r Responder) Responder { return ResponderFunc(func(resp *http.Response) error { err := r.Respond(resp) if err == nil && !ResponseHasStatusCode(resp, codes...) { derr := NewErrorWithResponse("autorest", "WithErrorUnlessStatusCode", resp, "%v %v failed with %s", resp.Request.Method, resp.Request.URL, resp.Status) if resp.Body != nil { defer resp.Body.Close() b, _ := ioutil.ReadAll(resp.Body) derr.ServiceError = b resp.Body = ioutil.NopCloser(bytes.NewReader(b)) } err = derr } return err }) } }
go
func WithErrorUnlessStatusCode(codes ...int) RespondDecorator { return func(r Responder) Responder { return ResponderFunc(func(resp *http.Response) error { err := r.Respond(resp) if err == nil && !ResponseHasStatusCode(resp, codes...) { derr := NewErrorWithResponse("autorest", "WithErrorUnlessStatusCode", resp, "%v %v failed with %s", resp.Request.Method, resp.Request.URL, resp.Status) if resp.Body != nil { defer resp.Body.Close() b, _ := ioutil.ReadAll(resp.Body) derr.ServiceError = b resp.Body = ioutil.NopCloser(bytes.NewReader(b)) } err = derr } return err }) } }
[ "func", "WithErrorUnlessStatusCode", "(", "codes", "...", "int", ")", "RespondDecorator", "{", "return", "func", "(", "r", "Responder", ")", "Responder", "{", "return", "ResponderFunc", "(", "func", "(", "resp", "*", "http", ".", "Response", ")", "error", "{...
// WithErrorUnlessStatusCode returns a RespondDecorator that emits an error unless the response // StatusCode is among the set passed. On error, response body is fully read into a buffer and // presented in the returned error, as well as in the response body.
[ "WithErrorUnlessStatusCode", "returns", "a", "RespondDecorator", "that", "emits", "an", "error", "unless", "the", "response", "StatusCode", "is", "among", "the", "set", "passed", ".", "On", "error", "response", "body", "is", "fully", "read", "into", "a", "buffer...
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L205-L225
train
Azure/go-autorest
autorest/responder.go
ExtractHeader
func ExtractHeader(header string, resp *http.Response) []string { if resp != nil && resp.Header != nil { return resp.Header[http.CanonicalHeaderKey(header)] } return nil }
go
func ExtractHeader(header string, resp *http.Response) []string { if resp != nil && resp.Header != nil { return resp.Header[http.CanonicalHeaderKey(header)] } return nil }
[ "func", "ExtractHeader", "(", "header", "string", ",", "resp", "*", "http", ".", "Response", ")", "[", "]", "string", "{", "if", "resp", "!=", "nil", "&&", "resp", ".", "Header", "!=", "nil", "{", "return", "resp", ".", "Header", "[", "http", ".", ...
// ExtractHeader extracts all values of the specified header from the http.Response. It returns an // empty string slice if the passed http.Response is nil or the header does not exist.
[ "ExtractHeader", "extracts", "all", "values", "of", "the", "specified", "header", "from", "the", "http", ".", "Response", ".", "It", "returns", "an", "empty", "string", "slice", "if", "the", "passed", "http", ".", "Response", "is", "nil", "or", "the", "hea...
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L235-L240
train
Azure/go-autorest
autorest/responder.go
ExtractHeaderValue
func ExtractHeaderValue(header string, resp *http.Response) string { h := ExtractHeader(header, resp) if len(h) > 0 { return h[0] } return "" }
go
func ExtractHeaderValue(header string, resp *http.Response) string { h := ExtractHeader(header, resp) if len(h) > 0 { return h[0] } return "" }
[ "func", "ExtractHeaderValue", "(", "header", "string", ",", "resp", "*", "http", ".", "Response", ")", "string", "{", "h", ":=", "ExtractHeader", "(", "header", ",", "resp", ")", "\n", "if", "len", "(", "h", ")", ">", "0", "{", "return", "h", "[", ...
// ExtractHeaderValue extracts the first value of the specified header from the http.Response. It // returns an empty string if the passed http.Response is nil or the header does not exist.
[ "ExtractHeaderValue", "extracts", "the", "first", "value", "of", "the", "specified", "header", "from", "the", "http", ".", "Response", ".", "It", "returns", "an", "empty", "string", "if", "the", "passed", "http", ".", "Response", "is", "nil", "or", "the", ...
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/responder.go#L244-L250
train
Azure/go-autorest
autorest/azure/azure.go
UnmarshalJSON
func (se *ServiceError) UnmarshalJSON(b []byte) error { // per the OData v4 spec the details field must be an array of JSON objects. // unfortunately not all services adhear to the spec and just return a single // object instead of an array with one object. so we have to perform some // shenanigans to accommodate both cases. // http://docs.oasis-open.org/odata/odata-json-format/v4.0/os/odata-json-format-v4.0-os.html#_Toc372793091 type serviceError1 struct { Code string `json:"code"` Message string `json:"message"` Target *string `json:"target"` Details []map[string]interface{} `json:"details"` InnerError map[string]interface{} `json:"innererror"` AdditionalInfo []map[string]interface{} `json:"additionalInfo"` } type serviceError2 struct { Code string `json:"code"` Message string `json:"message"` Target *string `json:"target"` Details map[string]interface{} `json:"details"` InnerError map[string]interface{} `json:"innererror"` AdditionalInfo []map[string]interface{} `json:"additionalInfo"` } se1 := serviceError1{} err := json.Unmarshal(b, &se1) if err == nil { se.populate(se1.Code, se1.Message, se1.Target, se1.Details, se1.InnerError, se1.AdditionalInfo) return nil } se2 := serviceError2{} err = json.Unmarshal(b, &se2) if err == nil { se.populate(se2.Code, se2.Message, se2.Target, nil, se2.InnerError, se2.AdditionalInfo) se.Details = append(se.Details, se2.Details) return nil } return err }
go
func (se *ServiceError) UnmarshalJSON(b []byte) error { // per the OData v4 spec the details field must be an array of JSON objects. // unfortunately not all services adhear to the spec and just return a single // object instead of an array with one object. so we have to perform some // shenanigans to accommodate both cases. // http://docs.oasis-open.org/odata/odata-json-format/v4.0/os/odata-json-format-v4.0-os.html#_Toc372793091 type serviceError1 struct { Code string `json:"code"` Message string `json:"message"` Target *string `json:"target"` Details []map[string]interface{} `json:"details"` InnerError map[string]interface{} `json:"innererror"` AdditionalInfo []map[string]interface{} `json:"additionalInfo"` } type serviceError2 struct { Code string `json:"code"` Message string `json:"message"` Target *string `json:"target"` Details map[string]interface{} `json:"details"` InnerError map[string]interface{} `json:"innererror"` AdditionalInfo []map[string]interface{} `json:"additionalInfo"` } se1 := serviceError1{} err := json.Unmarshal(b, &se1) if err == nil { se.populate(se1.Code, se1.Message, se1.Target, se1.Details, se1.InnerError, se1.AdditionalInfo) return nil } se2 := serviceError2{} err = json.Unmarshal(b, &se2) if err == nil { se.populate(se2.Code, se2.Message, se2.Target, nil, se2.InnerError, se2.AdditionalInfo) se.Details = append(se.Details, se2.Details) return nil } return err }
[ "func", "(", "se", "*", "ServiceError", ")", "UnmarshalJSON", "(", "b", "[", "]", "byte", ")", "error", "{", "// per the OData v4 spec the details field must be an array of JSON objects.", "// unfortunately not all services adhear to the spec and just return a single", "// object i...
// UnmarshalJSON implements the json.Unmarshaler interface for the ServiceError type.
[ "UnmarshalJSON", "implements", "the", "json", ".", "Unmarshaler", "interface", "for", "the", "ServiceError", "type", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/azure.go#L90-L130
train
Azure/go-autorest
autorest/azure/azure.go
Error
func (e RequestError) Error() string { return fmt.Sprintf("autorest/azure: Service returned an error. Status=%v %v", e.StatusCode, e.ServiceError) }
go
func (e RequestError) Error() string { return fmt.Sprintf("autorest/azure: Service returned an error. Status=%v %v", e.StatusCode, e.ServiceError) }
[ "func", "(", "e", "RequestError", ")", "Error", "(", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "e", ".", "StatusCode", ",", "e", ".", "ServiceError", ")", "\n", "}" ]
// Error returns a human-friendly error message from service error.
[ "Error", "returns", "a", "human", "-", "friendly", "error", "message", "from", "service", "error", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/azure.go#L153-L156
train
Azure/go-autorest
autorest/azure/azure.go
WithReturnClientID
func WithReturnClientID(b bool) autorest.PrepareDecorator { return autorest.WithHeader(HeaderReturnClientID, strconv.FormatBool(b)) }
go
func WithReturnClientID(b bool) autorest.PrepareDecorator { return autorest.WithHeader(HeaderReturnClientID, strconv.FormatBool(b)) }
[ "func", "WithReturnClientID", "(", "b", "bool", ")", "autorest", ".", "PrepareDecorator", "{", "return", "autorest", ".", "WithHeader", "(", "HeaderReturnClientID", ",", "strconv", ".", "FormatBool", "(", "b", ")", ")", "\n", "}" ]
// WithReturnClientID returns a PrepareDecorator that adds an HTTP extension header of // x-ms-return-client-request-id whose boolean value indicates if the value of the // x-ms-client-request-id header should be included in the http.Response.
[ "WithReturnClientID", "returns", "a", "PrepareDecorator", "that", "adds", "an", "HTTP", "extension", "header", "of", "x", "-", "ms", "-", "return", "-", "client", "-", "request", "-", "id", "whose", "boolean", "value", "indicates", "if", "the", "value", "of"...
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/azure.go#L253-L255
train
Azure/go-autorest
autorest/azure/azure.go
WithErrorUnlessStatusCode
func WithErrorUnlessStatusCode(codes ...int) autorest.RespondDecorator { return func(r autorest.Responder) autorest.Responder { return autorest.ResponderFunc(func(resp *http.Response) error { err := r.Respond(resp) if err == nil && !autorest.ResponseHasStatusCode(resp, codes...) { var e RequestError defer resp.Body.Close() // Copy and replace the Body in case it does not contain an error object. // This will leave the Body available to the caller. b, decodeErr := autorest.CopyAndDecode(autorest.EncodedAsJSON, resp.Body, &e) resp.Body = ioutil.NopCloser(&b) if decodeErr != nil { return fmt.Errorf("autorest/azure: error response cannot be parsed: %q error: %v", b.String(), decodeErr) } if e.ServiceError == nil { // Check if error is unwrapped ServiceError if err := json.Unmarshal(b.Bytes(), &e.ServiceError); err != nil { return err } } if e.ServiceError.Message == "" { // if we're here it means the returned error wasn't OData v4 compliant. // try to unmarshal the body as raw JSON in hopes of getting something. rawBody := map[string]interface{}{} if err := json.Unmarshal(b.Bytes(), &rawBody); err != nil { return err } e.ServiceError = &ServiceError{ Code: "Unknown", Message: "Unknown service error", } if len(rawBody) > 0 { e.ServiceError.Details = []map[string]interface{}{rawBody} } } e.Response = resp e.RequestID = ExtractRequestID(resp) if e.StatusCode == nil { e.StatusCode = resp.StatusCode } err = &e } return err }) } }
go
func WithErrorUnlessStatusCode(codes ...int) autorest.RespondDecorator { return func(r autorest.Responder) autorest.Responder { return autorest.ResponderFunc(func(resp *http.Response) error { err := r.Respond(resp) if err == nil && !autorest.ResponseHasStatusCode(resp, codes...) { var e RequestError defer resp.Body.Close() // Copy and replace the Body in case it does not contain an error object. // This will leave the Body available to the caller. b, decodeErr := autorest.CopyAndDecode(autorest.EncodedAsJSON, resp.Body, &e) resp.Body = ioutil.NopCloser(&b) if decodeErr != nil { return fmt.Errorf("autorest/azure: error response cannot be parsed: %q error: %v", b.String(), decodeErr) } if e.ServiceError == nil { // Check if error is unwrapped ServiceError if err := json.Unmarshal(b.Bytes(), &e.ServiceError); err != nil { return err } } if e.ServiceError.Message == "" { // if we're here it means the returned error wasn't OData v4 compliant. // try to unmarshal the body as raw JSON in hopes of getting something. rawBody := map[string]interface{}{} if err := json.Unmarshal(b.Bytes(), &rawBody); err != nil { return err } e.ServiceError = &ServiceError{ Code: "Unknown", Message: "Unknown service error", } if len(rawBody) > 0 { e.ServiceError.Details = []map[string]interface{}{rawBody} } } e.Response = resp e.RequestID = ExtractRequestID(resp) if e.StatusCode == nil { e.StatusCode = resp.StatusCode } err = &e } return err }) } }
[ "func", "WithErrorUnlessStatusCode", "(", "codes", "...", "int", ")", "autorest", ".", "RespondDecorator", "{", "return", "func", "(", "r", "autorest", ".", "Responder", ")", "autorest", ".", "Responder", "{", "return", "autorest", ".", "ResponderFunc", "(", "...
// WithErrorUnlessStatusCode returns a RespondDecorator that emits an // azure.RequestError by reading the response body unless the response HTTP status code // is among the set passed. // // If there is a chance service may return responses other than the Azure error // format and the response cannot be parsed into an error, a decoding error will // be returned containing the response body. In any case, the Responder will // return an error if the status code is not satisfied. // // If this Responder returns an error, the response body will be replaced with // an in-memory reader, which needs no further closing.
[ "WithErrorUnlessStatusCode", "returns", "a", "RespondDecorator", "that", "emits", "an", "azure", ".", "RequestError", "by", "reading", "the", "response", "body", "unless", "the", "response", "HTTP", "status", "code", "is", "among", "the", "set", "passed", ".", "...
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/azure.go#L280-L326
train
Azure/go-autorest
autorest/azure/auth/auth.go
GetSettingsFromEnvironment
func GetSettingsFromEnvironment() (s EnvironmentSettings, err error) { s = EnvironmentSettings{ Values: map[string]string{}, } s.setValue(SubscriptionID) s.setValue(TenantID) s.setValue(ClientID) s.setValue(ClientSecret) s.setValue(CertificatePath) s.setValue(CertificatePassword) s.setValue(Username) s.setValue(Password) s.setValue(EnvironmentName) s.setValue(Resource) if v := s.Values[EnvironmentName]; v == "" { s.Environment = azure.PublicCloud } else { s.Environment, err = azure.EnvironmentFromName(v) } if s.Values[Resource] == "" { s.Values[Resource] = s.Environment.ResourceManagerEndpoint } return }
go
func GetSettingsFromEnvironment() (s EnvironmentSettings, err error) { s = EnvironmentSettings{ Values: map[string]string{}, } s.setValue(SubscriptionID) s.setValue(TenantID) s.setValue(ClientID) s.setValue(ClientSecret) s.setValue(CertificatePath) s.setValue(CertificatePassword) s.setValue(Username) s.setValue(Password) s.setValue(EnvironmentName) s.setValue(Resource) if v := s.Values[EnvironmentName]; v == "" { s.Environment = azure.PublicCloud } else { s.Environment, err = azure.EnvironmentFromName(v) } if s.Values[Resource] == "" { s.Values[Resource] = s.Environment.ResourceManagerEndpoint } return }
[ "func", "GetSettingsFromEnvironment", "(", ")", "(", "s", "EnvironmentSettings", ",", "err", "error", ")", "{", "s", "=", "EnvironmentSettings", "{", "Values", ":", "map", "[", "string", "]", "string", "{", "}", ",", "}", "\n", "s", ".", "setValue", "(",...
// GetSettingsFromEnvironment returns the available authentication settings from the environment.
[ "GetSettingsFromEnvironment", "returns", "the", "available", "authentication", "settings", "from", "the", "environment", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L93-L116
train
Azure/go-autorest
autorest/azure/auth/auth.go
setValue
func (settings EnvironmentSettings) setValue(key string) { if v := os.Getenv(key); v != "" { settings.Values[key] = v } }
go
func (settings EnvironmentSettings) setValue(key string) { if v := os.Getenv(key); v != "" { settings.Values[key] = v } }
[ "func", "(", "settings", "EnvironmentSettings", ")", "setValue", "(", "key", "string", ")", "{", "if", "v", ":=", "os", ".", "Getenv", "(", "key", ")", ";", "v", "!=", "\"", "\"", "{", "settings", ".", "Values", "[", "key", "]", "=", "v", "\n", "...
// adds the specified environment variable value to the Values map if it exists
[ "adds", "the", "specified", "environment", "variable", "value", "to", "the", "Values", "map", "if", "it", "exists" ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L124-L128
train
Azure/go-autorest
autorest/azure/auth/auth.go
getClientAndTenant
func (settings EnvironmentSettings) getClientAndTenant() (string, string) { clientID := settings.Values[ClientID] tenantID := settings.Values[TenantID] return clientID, tenantID }
go
func (settings EnvironmentSettings) getClientAndTenant() (string, string) { clientID := settings.Values[ClientID] tenantID := settings.Values[TenantID] return clientID, tenantID }
[ "func", "(", "settings", "EnvironmentSettings", ")", "getClientAndTenant", "(", ")", "(", "string", ",", "string", ")", "{", "clientID", ":=", "settings", ".", "Values", "[", "ClientID", "]", "\n", "tenantID", ":=", "settings", ".", "Values", "[", "TenantID"...
// helper to return client and tenant IDs
[ "helper", "to", "return", "client", "and", "tenant", "IDs" ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L131-L135
train
Azure/go-autorest
autorest/azure/auth/auth.go
GetClientCredentials
func (settings EnvironmentSettings) GetClientCredentials() (ClientCredentialsConfig, error) { secret := settings.Values[ClientSecret] if secret == "" { return ClientCredentialsConfig{}, errors.New("missing client secret") } clientID, tenantID := settings.getClientAndTenant() config := NewClientCredentialsConfig(clientID, secret, tenantID) config.AADEndpoint = settings.Environment.ActiveDirectoryEndpoint config.Resource = settings.Values[Resource] return config, nil }
go
func (settings EnvironmentSettings) GetClientCredentials() (ClientCredentialsConfig, error) { secret := settings.Values[ClientSecret] if secret == "" { return ClientCredentialsConfig{}, errors.New("missing client secret") } clientID, tenantID := settings.getClientAndTenant() config := NewClientCredentialsConfig(clientID, secret, tenantID) config.AADEndpoint = settings.Environment.ActiveDirectoryEndpoint config.Resource = settings.Values[Resource] return config, nil }
[ "func", "(", "settings", "EnvironmentSettings", ")", "GetClientCredentials", "(", ")", "(", "ClientCredentialsConfig", ",", "error", ")", "{", "secret", ":=", "settings", ".", "Values", "[", "ClientSecret", "]", "\n", "if", "secret", "==", "\"", "\"", "{", "...
// GetClientCredentials creates a config object from the available client credentials. // An error is returned if no client credentials are available.
[ "GetClientCredentials", "creates", "a", "config", "object", "from", "the", "available", "client", "credentials", ".", "An", "error", "is", "returned", "if", "no", "client", "credentials", "are", "available", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L139-L149
train
Azure/go-autorest
autorest/azure/auth/auth.go
GetClientCertificate
func (settings EnvironmentSettings) GetClientCertificate() (ClientCertificateConfig, error) { certPath := settings.Values[CertificatePath] if certPath == "" { return ClientCertificateConfig{}, errors.New("missing certificate path") } certPwd := settings.Values[CertificatePassword] clientID, tenantID := settings.getClientAndTenant() config := NewClientCertificateConfig(certPath, certPwd, clientID, tenantID) config.AADEndpoint = settings.Environment.ActiveDirectoryEndpoint config.Resource = settings.Values[Resource] return config, nil }
go
func (settings EnvironmentSettings) GetClientCertificate() (ClientCertificateConfig, error) { certPath := settings.Values[CertificatePath] if certPath == "" { return ClientCertificateConfig{}, errors.New("missing certificate path") } certPwd := settings.Values[CertificatePassword] clientID, tenantID := settings.getClientAndTenant() config := NewClientCertificateConfig(certPath, certPwd, clientID, tenantID) config.AADEndpoint = settings.Environment.ActiveDirectoryEndpoint config.Resource = settings.Values[Resource] return config, nil }
[ "func", "(", "settings", "EnvironmentSettings", ")", "GetClientCertificate", "(", ")", "(", "ClientCertificateConfig", ",", "error", ")", "{", "certPath", ":=", "settings", ".", "Values", "[", "CertificatePath", "]", "\n", "if", "certPath", "==", "\"", "\"", "...
// GetClientCertificate creates a config object from the available certificate credentials. // An error is returned if no certificate credentials are available.
[ "GetClientCertificate", "creates", "a", "config", "object", "from", "the", "available", "certificate", "credentials", ".", "An", "error", "is", "returned", "if", "no", "certificate", "credentials", "are", "available", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L153-L164
train
Azure/go-autorest
autorest/azure/auth/auth.go
GetMSI
func (settings EnvironmentSettings) GetMSI() MSIConfig { config := NewMSIConfig() config.Resource = settings.Values[Resource] config.ClientID = settings.Values[ClientID] return config }
go
func (settings EnvironmentSettings) GetMSI() MSIConfig { config := NewMSIConfig() config.Resource = settings.Values[Resource] config.ClientID = settings.Values[ClientID] return config }
[ "func", "(", "settings", "EnvironmentSettings", ")", "GetMSI", "(", ")", "MSIConfig", "{", "config", ":=", "NewMSIConfig", "(", ")", "\n", "config", ".", "Resource", "=", "settings", ".", "Values", "[", "Resource", "]", "\n", "config", ".", "ClientID", "="...
// GetMSI creates a MSI config object from the available client ID.
[ "GetMSI", "creates", "a", "MSI", "config", "object", "from", "the", "available", "client", "ID", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L182-L187
train
Azure/go-autorest
autorest/azure/auth/auth.go
GetDeviceFlow
func (settings EnvironmentSettings) GetDeviceFlow() DeviceFlowConfig { clientID, tenantID := settings.getClientAndTenant() config := NewDeviceFlowConfig(clientID, tenantID) config.AADEndpoint = settings.Environment.ActiveDirectoryEndpoint config.Resource = settings.Values[Resource] return config }
go
func (settings EnvironmentSettings) GetDeviceFlow() DeviceFlowConfig { clientID, tenantID := settings.getClientAndTenant() config := NewDeviceFlowConfig(clientID, tenantID) config.AADEndpoint = settings.Environment.ActiveDirectoryEndpoint config.Resource = settings.Values[Resource] return config }
[ "func", "(", "settings", "EnvironmentSettings", ")", "GetDeviceFlow", "(", ")", "DeviceFlowConfig", "{", "clientID", ",", "tenantID", ":=", "settings", ".", "getClientAndTenant", "(", ")", "\n", "config", ":=", "NewDeviceFlowConfig", "(", "clientID", ",", "tenantI...
// GetDeviceFlow creates a device-flow config object from the available client and tenant IDs.
[ "GetDeviceFlow", "creates", "a", "device", "-", "flow", "config", "object", "from", "the", "available", "client", "and", "tenant", "IDs", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L190-L196
train
Azure/go-autorest
autorest/azure/auth/auth.go
NewAuthorizerFromFile
func NewAuthorizerFromFile(baseURI string) (autorest.Authorizer, error) { settings, err := GetSettingsFromFile() if err != nil { return nil, err } if a, err := settings.ClientCredentialsAuthorizer(baseURI); err == nil { return a, err } if a, err := settings.ClientCertificateAuthorizer(baseURI); err == nil { return a, err } return nil, errors.New("auth file missing client and certificate credentials") }
go
func NewAuthorizerFromFile(baseURI string) (autorest.Authorizer, error) { settings, err := GetSettingsFromFile() if err != nil { return nil, err } if a, err := settings.ClientCredentialsAuthorizer(baseURI); err == nil { return a, err } if a, err := settings.ClientCertificateAuthorizer(baseURI); err == nil { return a, err } return nil, errors.New("auth file missing client and certificate credentials") }
[ "func", "NewAuthorizerFromFile", "(", "baseURI", "string", ")", "(", "autorest", ".", "Authorizer", ",", "error", ")", "{", "settings", ",", "err", ":=", "GetSettingsFromFile", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "...
// NewAuthorizerFromFile creates an Authorizer configured from a configuration file in the following order. // 1. Client credentials // 2. Client certificate
[ "NewAuthorizerFromFile", "creates", "an", "Authorizer", "configured", "from", "a", "configuration", "file", "in", "the", "following", "order", ".", "1", ".", "Client", "credentials", "2", ".", "Client", "certificate" ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L226-L238
train
Azure/go-autorest
autorest/azure/auth/auth.go
NewAuthorizerFromFileWithResource
func NewAuthorizerFromFileWithResource(resource string) (autorest.Authorizer, error) { s, err := GetSettingsFromFile() if err != nil { return nil, err } if a, err := s.ClientCredentialsAuthorizerWithResource(resource); err == nil { return a, err } if a, err := s.ClientCertificateAuthorizerWithResource(resource); err == nil { return a, err } return nil, errors.New("auth file missing client and certificate credentials") }
go
func NewAuthorizerFromFileWithResource(resource string) (autorest.Authorizer, error) { s, err := GetSettingsFromFile() if err != nil { return nil, err } if a, err := s.ClientCredentialsAuthorizerWithResource(resource); err == nil { return a, err } if a, err := s.ClientCertificateAuthorizerWithResource(resource); err == nil { return a, err } return nil, errors.New("auth file missing client and certificate credentials") }
[ "func", "NewAuthorizerFromFileWithResource", "(", "resource", "string", ")", "(", "autorest", ".", "Authorizer", ",", "error", ")", "{", "s", ",", "err", ":=", "GetSettingsFromFile", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err...
// NewAuthorizerFromFileWithResource creates an Authorizer configured from a configuration file in the following order. // 1. Client credentials // 2. Client certificate
[ "NewAuthorizerFromFileWithResource", "creates", "an", "Authorizer", "configured", "from", "a", "configuration", "file", "in", "the", "following", "order", ".", "1", ".", "Client", "credentials", "2", ".", "Client", "certificate" ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L243-L255
train
Azure/go-autorest
autorest/azure/auth/auth.go
NewAuthorizerFromCLI
func NewAuthorizerFromCLI() (autorest.Authorizer, error) { settings, err := GetSettingsFromEnvironment() if err != nil { return nil, err } if settings.Values[Resource] == "" { settings.Values[Resource] = settings.Environment.ResourceManagerEndpoint } return NewAuthorizerFromCLIWithResource(settings.Values[Resource]) }
go
func NewAuthorizerFromCLI() (autorest.Authorizer, error) { settings, err := GetSettingsFromEnvironment() if err != nil { return nil, err } if settings.Values[Resource] == "" { settings.Values[Resource] = settings.Environment.ResourceManagerEndpoint } return NewAuthorizerFromCLIWithResource(settings.Values[Resource]) }
[ "func", "NewAuthorizerFromCLI", "(", ")", "(", "autorest", ".", "Authorizer", ",", "error", ")", "{", "settings", ",", "err", ":=", "GetSettingsFromEnvironment", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n...
// NewAuthorizerFromCLI creates an Authorizer configured from Azure CLI 2.0 for local development scenarios.
[ "NewAuthorizerFromCLI", "creates", "an", "Authorizer", "configured", "from", "Azure", "CLI", "2", ".", "0", "for", "local", "development", "scenarios", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L258-L269
train
Azure/go-autorest
autorest/azure/auth/auth.go
NewAuthorizerFromCLIWithResource
func NewAuthorizerFromCLIWithResource(resource string) (autorest.Authorizer, error) { token, err := cli.GetTokenFromCLI(resource) if err != nil { return nil, err } adalToken, err := token.ToADALToken() if err != nil { return nil, err } return autorest.NewBearerAuthorizer(&adalToken), nil }
go
func NewAuthorizerFromCLIWithResource(resource string) (autorest.Authorizer, error) { token, err := cli.GetTokenFromCLI(resource) if err != nil { return nil, err } adalToken, err := token.ToADALToken() if err != nil { return nil, err } return autorest.NewBearerAuthorizer(&adalToken), nil }
[ "func", "NewAuthorizerFromCLIWithResource", "(", "resource", "string", ")", "(", "autorest", ".", "Authorizer", ",", "error", ")", "{", "token", ",", "err", ":=", "cli", ".", "GetTokenFromCLI", "(", "resource", ")", "\n", "if", "err", "!=", "nil", "{", "re...
// NewAuthorizerFromCLIWithResource creates an Authorizer configured from Azure CLI 2.0 for local development scenarios.
[ "NewAuthorizerFromCLIWithResource", "creates", "an", "Authorizer", "configured", "from", "Azure", "CLI", "2", ".", "0", "for", "local", "development", "scenarios", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L272-L284
train
Azure/go-autorest
autorest/azure/auth/auth.go
GetSettingsFromFile
func GetSettingsFromFile() (FileSettings, error) { s := FileSettings{} fileLocation := os.Getenv("AZURE_AUTH_LOCATION") if fileLocation == "" { return s, errors.New("environment variable AZURE_AUTH_LOCATION is not set") } contents, err := ioutil.ReadFile(fileLocation) if err != nil { return s, err } // Auth file might be encoded decoded, err := decode(contents) if err != nil { return s, err } authFile := map[string]interface{}{} err = json.Unmarshal(decoded, &authFile) if err != nil { return s, err } s.Values = map[string]string{} s.setKeyValue(ClientID, authFile["clientId"]) s.setKeyValue(ClientSecret, authFile["clientSecret"]) s.setKeyValue(CertificatePath, authFile["clientCertificate"]) s.setKeyValue(CertificatePassword, authFile["clientCertificatePassword"]) s.setKeyValue(SubscriptionID, authFile["subscriptionId"]) s.setKeyValue(TenantID, authFile["tenantId"]) s.setKeyValue(ActiveDirectoryEndpoint, authFile["activeDirectoryEndpointUrl"]) s.setKeyValue(ResourceManagerEndpoint, authFile["resourceManagerEndpointUrl"]) s.setKeyValue(GraphResourceID, authFile["activeDirectoryGraphResourceId"]) s.setKeyValue(SQLManagementEndpoint, authFile["sqlManagementEndpointUrl"]) s.setKeyValue(GalleryEndpoint, authFile["galleryEndpointUrl"]) s.setKeyValue(ManagementEndpoint, authFile["managementEndpointUrl"]) return s, nil }
go
func GetSettingsFromFile() (FileSettings, error) { s := FileSettings{} fileLocation := os.Getenv("AZURE_AUTH_LOCATION") if fileLocation == "" { return s, errors.New("environment variable AZURE_AUTH_LOCATION is not set") } contents, err := ioutil.ReadFile(fileLocation) if err != nil { return s, err } // Auth file might be encoded decoded, err := decode(contents) if err != nil { return s, err } authFile := map[string]interface{}{} err = json.Unmarshal(decoded, &authFile) if err != nil { return s, err } s.Values = map[string]string{} s.setKeyValue(ClientID, authFile["clientId"]) s.setKeyValue(ClientSecret, authFile["clientSecret"]) s.setKeyValue(CertificatePath, authFile["clientCertificate"]) s.setKeyValue(CertificatePassword, authFile["clientCertificatePassword"]) s.setKeyValue(SubscriptionID, authFile["subscriptionId"]) s.setKeyValue(TenantID, authFile["tenantId"]) s.setKeyValue(ActiveDirectoryEndpoint, authFile["activeDirectoryEndpointUrl"]) s.setKeyValue(ResourceManagerEndpoint, authFile["resourceManagerEndpointUrl"]) s.setKeyValue(GraphResourceID, authFile["activeDirectoryGraphResourceId"]) s.setKeyValue(SQLManagementEndpoint, authFile["sqlManagementEndpointUrl"]) s.setKeyValue(GalleryEndpoint, authFile["galleryEndpointUrl"]) s.setKeyValue(ManagementEndpoint, authFile["managementEndpointUrl"]) return s, nil }
[ "func", "GetSettingsFromFile", "(", ")", "(", "FileSettings", ",", "error", ")", "{", "s", ":=", "FileSettings", "{", "}", "\n", "fileLocation", ":=", "os", ".", "Getenv", "(", "\"", "\"", ")", "\n", "if", "fileLocation", "==", "\"", "\"", "{", "return...
// GetSettingsFromFile returns the available authentication settings from an Azure CLI authentication file.
[ "GetSettingsFromFile", "returns", "the", "available", "authentication", "settings", "from", "an", "Azure", "CLI", "authentication", "file", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L287-L325
train
Azure/go-autorest
autorest/azure/auth/auth.go
setKeyValue
func (settings FileSettings) setKeyValue(key string, val interface{}) { if val != nil { settings.Values[key] = val.(string) } }
go
func (settings FileSettings) setKeyValue(key string, val interface{}) { if val != nil { settings.Values[key] = val.(string) } }
[ "func", "(", "settings", "FileSettings", ")", "setKeyValue", "(", "key", "string", ",", "val", "interface", "{", "}", ")", "{", "if", "val", "!=", "nil", "{", "settings", ".", "Values", "[", "key", "]", "=", "val", ".", "(", "string", ")", "\n", "}...
// adds the specified value to the Values map if it isn't nil
[ "adds", "the", "specified", "value", "to", "the", "Values", "map", "if", "it", "isn", "t", "nil" ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L338-L342
train
Azure/go-autorest
autorest/azure/auth/auth.go
getAADEndpoint
func (settings FileSettings) getAADEndpoint() string { if v, ok := settings.Values[ActiveDirectoryEndpoint]; ok { return v } return azure.PublicCloud.ActiveDirectoryEndpoint }
go
func (settings FileSettings) getAADEndpoint() string { if v, ok := settings.Values[ActiveDirectoryEndpoint]; ok { return v } return azure.PublicCloud.ActiveDirectoryEndpoint }
[ "func", "(", "settings", "FileSettings", ")", "getAADEndpoint", "(", ")", "string", "{", "if", "v", ",", "ok", ":=", "settings", ".", "Values", "[", "ActiveDirectoryEndpoint", "]", ";", "ok", "{", "return", "v", "\n", "}", "\n", "return", "azure", ".", ...
// returns the specified AAD endpoint or the public cloud endpoint if unspecified
[ "returns", "the", "specified", "AAD", "endpoint", "or", "the", "public", "cloud", "endpoint", "if", "unspecified" ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L345-L350
train
Azure/go-autorest
autorest/azure/auth/auth.go
ServicePrincipalTokenFromClientCredentials
func (settings FileSettings) ServicePrincipalTokenFromClientCredentials(baseURI string) (*adal.ServicePrincipalToken, error) { resource, err := settings.getResourceForToken(baseURI) if err != nil { return nil, err } return settings.ServicePrincipalTokenFromClientCredentialsWithResource(resource) }
go
func (settings FileSettings) ServicePrincipalTokenFromClientCredentials(baseURI string) (*adal.ServicePrincipalToken, error) { resource, err := settings.getResourceForToken(baseURI) if err != nil { return nil, err } return settings.ServicePrincipalTokenFromClientCredentialsWithResource(resource) }
[ "func", "(", "settings", "FileSettings", ")", "ServicePrincipalTokenFromClientCredentials", "(", "baseURI", "string", ")", "(", "*", "adal", ".", "ServicePrincipalToken", ",", "error", ")", "{", "resource", ",", "err", ":=", "settings", ".", "getResourceForToken", ...
// ServicePrincipalTokenFromClientCredentials creates a ServicePrincipalToken from the available client credentials.
[ "ServicePrincipalTokenFromClientCredentials", "creates", "a", "ServicePrincipalToken", "from", "the", "available", "client", "credentials", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L353-L359
train
Azure/go-autorest
autorest/azure/auth/auth.go
ClientCredentialsAuthorizer
func (settings FileSettings) ClientCredentialsAuthorizer(baseURI string) (autorest.Authorizer, error) { resource, err := settings.getResourceForToken(baseURI) if err != nil { return nil, err } return settings.ClientCredentialsAuthorizerWithResource(resource) }
go
func (settings FileSettings) ClientCredentialsAuthorizer(baseURI string) (autorest.Authorizer, error) { resource, err := settings.getResourceForToken(baseURI) if err != nil { return nil, err } return settings.ClientCredentialsAuthorizerWithResource(resource) }
[ "func", "(", "settings", "FileSettings", ")", "ClientCredentialsAuthorizer", "(", "baseURI", "string", ")", "(", "autorest", ".", "Authorizer", ",", "error", ")", "{", "resource", ",", "err", ":=", "settings", ".", "getResourceForToken", "(", "baseURI", ")", "...
// ClientCredentialsAuthorizer creates an authorizer from the available client credentials.
[ "ClientCredentialsAuthorizer", "creates", "an", "authorizer", "from", "the", "available", "client", "credentials", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L362-L368
train
Azure/go-autorest
autorest/azure/auth/auth.go
ServicePrincipalTokenFromClientCredentialsWithResource
func (settings FileSettings) ServicePrincipalTokenFromClientCredentialsWithResource(resource string) (*adal.ServicePrincipalToken, error) { if _, ok := settings.Values[ClientSecret]; !ok { return nil, errors.New("missing client secret") } config, err := adal.NewOAuthConfig(settings.getAADEndpoint(), settings.Values[TenantID]) if err != nil { return nil, err } return adal.NewServicePrincipalToken(*config, settings.Values[ClientID], settings.Values[ClientSecret], resource) }
go
func (settings FileSettings) ServicePrincipalTokenFromClientCredentialsWithResource(resource string) (*adal.ServicePrincipalToken, error) { if _, ok := settings.Values[ClientSecret]; !ok { return nil, errors.New("missing client secret") } config, err := adal.NewOAuthConfig(settings.getAADEndpoint(), settings.Values[TenantID]) if err != nil { return nil, err } return adal.NewServicePrincipalToken(*config, settings.Values[ClientID], settings.Values[ClientSecret], resource) }
[ "func", "(", "settings", "FileSettings", ")", "ServicePrincipalTokenFromClientCredentialsWithResource", "(", "resource", "string", ")", "(", "*", "adal", ".", "ServicePrincipalToken", ",", "error", ")", "{", "if", "_", ",", "ok", ":=", "settings", ".", "Values", ...
// ServicePrincipalTokenFromClientCredentialsWithResource creates a ServicePrincipalToken // from the available client credentials and the specified resource.
[ "ServicePrincipalTokenFromClientCredentialsWithResource", "creates", "a", "ServicePrincipalToken", "from", "the", "available", "client", "credentials", "and", "the", "specified", "resource", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L372-L381
train
Azure/go-autorest
autorest/azure/auth/auth.go
ClientCredentialsAuthorizerWithResource
func (settings FileSettings) ClientCredentialsAuthorizerWithResource(resource string) (autorest.Authorizer, error) { spToken, err := settings.ServicePrincipalTokenFromClientCredentialsWithResource(resource) if err != nil { return nil, err } return autorest.NewBearerAuthorizer(spToken), nil }
go
func (settings FileSettings) ClientCredentialsAuthorizerWithResource(resource string) (autorest.Authorizer, error) { spToken, err := settings.ServicePrincipalTokenFromClientCredentialsWithResource(resource) if err != nil { return nil, err } return autorest.NewBearerAuthorizer(spToken), nil }
[ "func", "(", "settings", "FileSettings", ")", "ClientCredentialsAuthorizerWithResource", "(", "resource", "string", ")", "(", "autorest", ".", "Authorizer", ",", "error", ")", "{", "spToken", ",", "err", ":=", "settings", ".", "ServicePrincipalTokenFromClientCredentia...
// ClientCredentialsAuthorizerWithResource creates an authorizer from the available client credentials and the specified resource.
[ "ClientCredentialsAuthorizerWithResource", "creates", "an", "authorizer", "from", "the", "available", "client", "credentials", "and", "the", "specified", "resource", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L394-L400
train
Azure/go-autorest
autorest/azure/auth/auth.go
ServicePrincipalTokenFromClientCertificate
func (settings FileSettings) ServicePrincipalTokenFromClientCertificate(baseURI string) (*adal.ServicePrincipalToken, error) { resource, err := settings.getResourceForToken(baseURI) if err != nil { return nil, err } return settings.ServicePrincipalTokenFromClientCertificateWithResource(resource) }
go
func (settings FileSettings) ServicePrincipalTokenFromClientCertificate(baseURI string) (*adal.ServicePrincipalToken, error) { resource, err := settings.getResourceForToken(baseURI) if err != nil { return nil, err } return settings.ServicePrincipalTokenFromClientCertificateWithResource(resource) }
[ "func", "(", "settings", "FileSettings", ")", "ServicePrincipalTokenFromClientCertificate", "(", "baseURI", "string", ")", "(", "*", "adal", ".", "ServicePrincipalToken", ",", "error", ")", "{", "resource", ",", "err", ":=", "settings", ".", "getResourceForToken", ...
// ServicePrincipalTokenFromClientCertificate creates a ServicePrincipalToken from the available certificate credentials.
[ "ServicePrincipalTokenFromClientCertificate", "creates", "a", "ServicePrincipalToken", "from", "the", "available", "certificate", "credentials", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L403-L409
train
Azure/go-autorest
autorest/azure/auth/auth.go
ClientCertificateAuthorizer
func (settings FileSettings) ClientCertificateAuthorizer(baseURI string) (autorest.Authorizer, error) { resource, err := settings.getResourceForToken(baseURI) if err != nil { return nil, err } return settings.ClientCertificateAuthorizerWithResource(resource) }
go
func (settings FileSettings) ClientCertificateAuthorizer(baseURI string) (autorest.Authorizer, error) { resource, err := settings.getResourceForToken(baseURI) if err != nil { return nil, err } return settings.ClientCertificateAuthorizerWithResource(resource) }
[ "func", "(", "settings", "FileSettings", ")", "ClientCertificateAuthorizer", "(", "baseURI", "string", ")", "(", "autorest", ".", "Authorizer", ",", "error", ")", "{", "resource", ",", "err", ":=", "settings", ".", "getResourceForToken", "(", "baseURI", ")", "...
// ClientCertificateAuthorizer creates an authorizer from the available certificate credentials.
[ "ClientCertificateAuthorizer", "creates", "an", "authorizer", "from", "the", "available", "certificate", "credentials", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L412-L418
train
Azure/go-autorest
autorest/azure/auth/auth.go
ServicePrincipalTokenFromClientCertificateWithResource
func (settings FileSettings) ServicePrincipalTokenFromClientCertificateWithResource(resource string) (*adal.ServicePrincipalToken, error) { cfg, err := settings.clientCertificateConfigWithResource(resource) if err != nil { return nil, err } return cfg.ServicePrincipalToken() }
go
func (settings FileSettings) ServicePrincipalTokenFromClientCertificateWithResource(resource string) (*adal.ServicePrincipalToken, error) { cfg, err := settings.clientCertificateConfigWithResource(resource) if err != nil { return nil, err } return cfg.ServicePrincipalToken() }
[ "func", "(", "settings", "FileSettings", ")", "ServicePrincipalTokenFromClientCertificateWithResource", "(", "resource", "string", ")", "(", "*", "adal", ".", "ServicePrincipalToken", ",", "error", ")", "{", "cfg", ",", "err", ":=", "settings", ".", "clientCertifica...
// ServicePrincipalTokenFromClientCertificateWithResource creates a ServicePrincipalToken from the available certificate credentials.
[ "ServicePrincipalTokenFromClientCertificateWithResource", "creates", "a", "ServicePrincipalToken", "from", "the", "available", "certificate", "credentials", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L421-L427
train
Azure/go-autorest
autorest/azure/auth/auth.go
ClientCertificateAuthorizerWithResource
func (settings FileSettings) ClientCertificateAuthorizerWithResource(resource string) (autorest.Authorizer, error) { cfg, err := settings.clientCertificateConfigWithResource(resource) if err != nil { return nil, err } return cfg.Authorizer() }
go
func (settings FileSettings) ClientCertificateAuthorizerWithResource(resource string) (autorest.Authorizer, error) { cfg, err := settings.clientCertificateConfigWithResource(resource) if err != nil { return nil, err } return cfg.Authorizer() }
[ "func", "(", "settings", "FileSettings", ")", "ClientCertificateAuthorizerWithResource", "(", "resource", "string", ")", "(", "autorest", ".", "Authorizer", ",", "error", ")", "{", "cfg", ",", "err", ":=", "settings", ".", "clientCertificateConfigWithResource", "(",...
// ClientCertificateAuthorizerWithResource creates an authorizer from the available certificate credentials and the specified resource.
[ "ClientCertificateAuthorizerWithResource", "creates", "an", "authorizer", "from", "the", "available", "certificate", "credentials", "and", "the", "specified", "resource", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L430-L436
train
Azure/go-autorest
autorest/azure/auth/auth.go
NewClientCredentialsConfig
func NewClientCredentialsConfig(clientID string, clientSecret string, tenantID string) ClientCredentialsConfig { return ClientCredentialsConfig{ ClientID: clientID, ClientSecret: clientSecret, TenantID: tenantID, Resource: azure.PublicCloud.ResourceManagerEndpoint, AADEndpoint: azure.PublicCloud.ActiveDirectoryEndpoint, } }
go
func NewClientCredentialsConfig(clientID string, clientSecret string, tenantID string) ClientCredentialsConfig { return ClientCredentialsConfig{ ClientID: clientID, ClientSecret: clientSecret, TenantID: tenantID, Resource: azure.PublicCloud.ResourceManagerEndpoint, AADEndpoint: azure.PublicCloud.ActiveDirectoryEndpoint, } }
[ "func", "NewClientCredentialsConfig", "(", "clientID", "string", ",", "clientSecret", "string", ",", "tenantID", "string", ")", "ClientCredentialsConfig", "{", "return", "ClientCredentialsConfig", "{", "ClientID", ":", "clientID", ",", "ClientSecret", ":", "clientSecret...
// NewClientCredentialsConfig creates an AuthorizerConfig object configured to obtain an Authorizer through Client Credentials. // Defaults to Public Cloud and Resource Manager Endpoint.
[ "NewClientCredentialsConfig", "creates", "an", "AuthorizerConfig", "object", "configured", "to", "obtain", "an", "Authorizer", "through", "Client", "Credentials", ".", "Defaults", "to", "Public", "Cloud", "and", "Resource", "Manager", "Endpoint", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L485-L493
train
Azure/go-autorest
autorest/azure/auth/auth.go
NewClientCertificateConfig
func NewClientCertificateConfig(certificatePath string, certificatePassword string, clientID string, tenantID string) ClientCertificateConfig { return ClientCertificateConfig{ CertificatePath: certificatePath, CertificatePassword: certificatePassword, ClientID: clientID, TenantID: tenantID, Resource: azure.PublicCloud.ResourceManagerEndpoint, AADEndpoint: azure.PublicCloud.ActiveDirectoryEndpoint, } }
go
func NewClientCertificateConfig(certificatePath string, certificatePassword string, clientID string, tenantID string) ClientCertificateConfig { return ClientCertificateConfig{ CertificatePath: certificatePath, CertificatePassword: certificatePassword, ClientID: clientID, TenantID: tenantID, Resource: azure.PublicCloud.ResourceManagerEndpoint, AADEndpoint: azure.PublicCloud.ActiveDirectoryEndpoint, } }
[ "func", "NewClientCertificateConfig", "(", "certificatePath", "string", ",", "certificatePassword", "string", ",", "clientID", "string", ",", "tenantID", "string", ")", "ClientCertificateConfig", "{", "return", "ClientCertificateConfig", "{", "CertificatePath", ":", "cert...
// NewClientCertificateConfig creates a ClientCertificateConfig object configured to obtain an Authorizer through client certificate. // Defaults to Public Cloud and Resource Manager Endpoint.
[ "NewClientCertificateConfig", "creates", "a", "ClientCertificateConfig", "object", "configured", "to", "obtain", "an", "Authorizer", "through", "client", "certificate", ".", "Defaults", "to", "Public", "Cloud", "and", "Resource", "Manager", "Endpoint", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L497-L506
train
Azure/go-autorest
autorest/azure/auth/auth.go
NewUsernamePasswordConfig
func NewUsernamePasswordConfig(username string, password string, clientID string, tenantID string) UsernamePasswordConfig { return UsernamePasswordConfig{ Username: username, Password: password, ClientID: clientID, TenantID: tenantID, Resource: azure.PublicCloud.ResourceManagerEndpoint, AADEndpoint: azure.PublicCloud.ActiveDirectoryEndpoint, } }
go
func NewUsernamePasswordConfig(username string, password string, clientID string, tenantID string) UsernamePasswordConfig { return UsernamePasswordConfig{ Username: username, Password: password, ClientID: clientID, TenantID: tenantID, Resource: azure.PublicCloud.ResourceManagerEndpoint, AADEndpoint: azure.PublicCloud.ActiveDirectoryEndpoint, } }
[ "func", "NewUsernamePasswordConfig", "(", "username", "string", ",", "password", "string", ",", "clientID", "string", ",", "tenantID", "string", ")", "UsernamePasswordConfig", "{", "return", "UsernamePasswordConfig", "{", "Username", ":", "username", ",", "Password", ...
// NewUsernamePasswordConfig creates an UsernamePasswordConfig object configured to obtain an Authorizer through username and password. // Defaults to Public Cloud and Resource Manager Endpoint.
[ "NewUsernamePasswordConfig", "creates", "an", "UsernamePasswordConfig", "object", "configured", "to", "obtain", "an", "Authorizer", "through", "username", "and", "password", ".", "Defaults", "to", "Public", "Cloud", "and", "Resource", "Manager", "Endpoint", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L510-L519
train
Azure/go-autorest
autorest/azure/auth/auth.go
NewDeviceFlowConfig
func NewDeviceFlowConfig(clientID string, tenantID string) DeviceFlowConfig { return DeviceFlowConfig{ ClientID: clientID, TenantID: tenantID, Resource: azure.PublicCloud.ResourceManagerEndpoint, AADEndpoint: azure.PublicCloud.ActiveDirectoryEndpoint, } }
go
func NewDeviceFlowConfig(clientID string, tenantID string) DeviceFlowConfig { return DeviceFlowConfig{ ClientID: clientID, TenantID: tenantID, Resource: azure.PublicCloud.ResourceManagerEndpoint, AADEndpoint: azure.PublicCloud.ActiveDirectoryEndpoint, } }
[ "func", "NewDeviceFlowConfig", "(", "clientID", "string", ",", "tenantID", "string", ")", "DeviceFlowConfig", "{", "return", "DeviceFlowConfig", "{", "ClientID", ":", "clientID", ",", "TenantID", ":", "tenantID", ",", "Resource", ":", "azure", ".", "PublicCloud", ...
// NewDeviceFlowConfig creates a DeviceFlowConfig object configured to obtain an Authorizer through device flow. // Defaults to Public Cloud and Resource Manager Endpoint.
[ "NewDeviceFlowConfig", "creates", "a", "DeviceFlowConfig", "object", "configured", "to", "obtain", "an", "Authorizer", "through", "device", "flow", ".", "Defaults", "to", "Public", "Cloud", "and", "Resource", "Manager", "Endpoint", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L530-L537
train
Azure/go-autorest
autorest/azure/auth/auth.go
ServicePrincipalToken
func (ccc ClientCredentialsConfig) ServicePrincipalToken() (*adal.ServicePrincipalToken, error) { oauthConfig, err := adal.NewOAuthConfig(ccc.AADEndpoint, ccc.TenantID) if err != nil { return nil, err } return adal.NewServicePrincipalToken(*oauthConfig, ccc.ClientID, ccc.ClientSecret, ccc.Resource) }
go
func (ccc ClientCredentialsConfig) ServicePrincipalToken() (*adal.ServicePrincipalToken, error) { oauthConfig, err := adal.NewOAuthConfig(ccc.AADEndpoint, ccc.TenantID) if err != nil { return nil, err } return adal.NewServicePrincipalToken(*oauthConfig, ccc.ClientID, ccc.ClientSecret, ccc.Resource) }
[ "func", "(", "ccc", "ClientCredentialsConfig", ")", "ServicePrincipalToken", "(", ")", "(", "*", "adal", ".", "ServicePrincipalToken", ",", "error", ")", "{", "oauthConfig", ",", "err", ":=", "adal", ".", "NewOAuthConfig", "(", "ccc", ".", "AADEndpoint", ",", ...
// ServicePrincipalToken creates a ServicePrincipalToken from client credentials.
[ "ServicePrincipalToken", "creates", "a", "ServicePrincipalToken", "from", "client", "credentials", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L554-L560
train
Azure/go-autorest
autorest/azure/auth/auth.go
Authorizer
func (ccc ClientCredentialsConfig) Authorizer() (autorest.Authorizer, error) { spToken, err := ccc.ServicePrincipalToken() if err != nil { return nil, fmt.Errorf("failed to get oauth token from client credentials: %v", err) } return autorest.NewBearerAuthorizer(spToken), nil }
go
func (ccc ClientCredentialsConfig) Authorizer() (autorest.Authorizer, error) { spToken, err := ccc.ServicePrincipalToken() if err != nil { return nil, fmt.Errorf("failed to get oauth token from client credentials: %v", err) } return autorest.NewBearerAuthorizer(spToken), nil }
[ "func", "(", "ccc", "ClientCredentialsConfig", ")", "Authorizer", "(", ")", "(", "autorest", ".", "Authorizer", ",", "error", ")", "{", "spToken", ",", "err", ":=", "ccc", ".", "ServicePrincipalToken", "(", ")", "\n", "if", "err", "!=", "nil", "{", "retu...
// Authorizer gets the authorizer from client credentials.
[ "Authorizer", "gets", "the", "authorizer", "from", "client", "credentials", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L563-L569
train
Azure/go-autorest
autorest/azure/auth/auth.go
ServicePrincipalToken
func (ccc ClientCertificateConfig) ServicePrincipalToken() (*adal.ServicePrincipalToken, error) { oauthConfig, err := adal.NewOAuthConfig(ccc.AADEndpoint, ccc.TenantID) if err != nil { return nil, err } certData, err := ioutil.ReadFile(ccc.CertificatePath) if err != nil { return nil, fmt.Errorf("failed to read the certificate file (%s): %v", ccc.CertificatePath, err) } certificate, rsaPrivateKey, err := decodePkcs12(certData, ccc.CertificatePassword) if err != nil { return nil, fmt.Errorf("failed to decode pkcs12 certificate while creating spt: %v", err) } return adal.NewServicePrincipalTokenFromCertificate(*oauthConfig, ccc.ClientID, certificate, rsaPrivateKey, ccc.Resource) }
go
func (ccc ClientCertificateConfig) ServicePrincipalToken() (*adal.ServicePrincipalToken, error) { oauthConfig, err := adal.NewOAuthConfig(ccc.AADEndpoint, ccc.TenantID) if err != nil { return nil, err } certData, err := ioutil.ReadFile(ccc.CertificatePath) if err != nil { return nil, fmt.Errorf("failed to read the certificate file (%s): %v", ccc.CertificatePath, err) } certificate, rsaPrivateKey, err := decodePkcs12(certData, ccc.CertificatePassword) if err != nil { return nil, fmt.Errorf("failed to decode pkcs12 certificate while creating spt: %v", err) } return adal.NewServicePrincipalTokenFromCertificate(*oauthConfig, ccc.ClientID, certificate, rsaPrivateKey, ccc.Resource) }
[ "func", "(", "ccc", "ClientCertificateConfig", ")", "ServicePrincipalToken", "(", ")", "(", "*", "adal", ".", "ServicePrincipalToken", ",", "error", ")", "{", "oauthConfig", ",", "err", ":=", "adal", ".", "NewOAuthConfig", "(", "ccc", ".", "AADEndpoint", ",", ...
// ServicePrincipalToken creates a ServicePrincipalToken from client certificate.
[ "ServicePrincipalToken", "creates", "a", "ServicePrincipalToken", "from", "client", "certificate", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L582-L596
train
Azure/go-autorest
autorest/azure/auth/auth.go
Authorizer
func (dfc DeviceFlowConfig) Authorizer() (autorest.Authorizer, error) { spToken, err := dfc.ServicePrincipalToken() if err != nil { return nil, fmt.Errorf("failed to get oauth token from device flow: %v", err) } return autorest.NewBearerAuthorizer(spToken), nil }
go
func (dfc DeviceFlowConfig) Authorizer() (autorest.Authorizer, error) { spToken, err := dfc.ServicePrincipalToken() if err != nil { return nil, fmt.Errorf("failed to get oauth token from device flow: %v", err) } return autorest.NewBearerAuthorizer(spToken), nil }
[ "func", "(", "dfc", "DeviceFlowConfig", ")", "Authorizer", "(", ")", "(", "autorest", ".", "Authorizer", ",", "error", ")", "{", "spToken", ",", "err", ":=", "dfc", ".", "ServicePrincipalToken", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", ...
// Authorizer gets the authorizer from device flow.
[ "Authorizer", "gets", "the", "authorizer", "from", "device", "flow", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L616-L622
train
Azure/go-autorest
autorest/azure/auth/auth.go
ServicePrincipalToken
func (dfc DeviceFlowConfig) ServicePrincipalToken() (*adal.ServicePrincipalToken, error) { oauthConfig, err := adal.NewOAuthConfig(dfc.AADEndpoint, dfc.TenantID) if err != nil { return nil, err } oauthClient := &autorest.Client{} deviceCode, err := adal.InitiateDeviceAuth(oauthClient, *oauthConfig, dfc.ClientID, dfc.Resource) if err != nil { return nil, fmt.Errorf("failed to start device auth flow: %s", err) } log.Println(*deviceCode.Message) token, err := adal.WaitForUserCompletion(oauthClient, deviceCode) if err != nil { return nil, fmt.Errorf("failed to finish device auth flow: %s", err) } return adal.NewServicePrincipalTokenFromManualToken(*oauthConfig, dfc.ClientID, dfc.Resource, *token) }
go
func (dfc DeviceFlowConfig) ServicePrincipalToken() (*adal.ServicePrincipalToken, error) { oauthConfig, err := adal.NewOAuthConfig(dfc.AADEndpoint, dfc.TenantID) if err != nil { return nil, err } oauthClient := &autorest.Client{} deviceCode, err := adal.InitiateDeviceAuth(oauthClient, *oauthConfig, dfc.ClientID, dfc.Resource) if err != nil { return nil, fmt.Errorf("failed to start device auth flow: %s", err) } log.Println(*deviceCode.Message) token, err := adal.WaitForUserCompletion(oauthClient, deviceCode) if err != nil { return nil, fmt.Errorf("failed to finish device auth flow: %s", err) } return adal.NewServicePrincipalTokenFromManualToken(*oauthConfig, dfc.ClientID, dfc.Resource, *token) }
[ "func", "(", "dfc", "DeviceFlowConfig", ")", "ServicePrincipalToken", "(", ")", "(", "*", "adal", ".", "ServicePrincipalToken", ",", "error", ")", "{", "oauthConfig", ",", "err", ":=", "adal", ".", "NewOAuthConfig", "(", "dfc", ".", "AADEndpoint", ",", "dfc"...
// ServicePrincipalToken gets the service principal token from device flow.
[ "ServicePrincipalToken", "gets", "the", "service", "principal", "token", "from", "device", "flow", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L625-L641
train
Azure/go-autorest
autorest/azure/auth/auth.go
ServicePrincipalToken
func (ups UsernamePasswordConfig) ServicePrincipalToken() (*adal.ServicePrincipalToken, error) { oauthConfig, err := adal.NewOAuthConfig(ups.AADEndpoint, ups.TenantID) if err != nil { return nil, err } return adal.NewServicePrincipalTokenFromUsernamePassword(*oauthConfig, ups.ClientID, ups.Username, ups.Password, ups.Resource) }
go
func (ups UsernamePasswordConfig) ServicePrincipalToken() (*adal.ServicePrincipalToken, error) { oauthConfig, err := adal.NewOAuthConfig(ups.AADEndpoint, ups.TenantID) if err != nil { return nil, err } return adal.NewServicePrincipalTokenFromUsernamePassword(*oauthConfig, ups.ClientID, ups.Username, ups.Password, ups.Resource) }
[ "func", "(", "ups", "UsernamePasswordConfig", ")", "ServicePrincipalToken", "(", ")", "(", "*", "adal", ".", "ServicePrincipalToken", ",", "error", ")", "{", "oauthConfig", ",", "err", ":=", "adal", ".", "NewOAuthConfig", "(", "ups", ".", "AADEndpoint", ",", ...
// ServicePrincipalToken creates a ServicePrincipalToken from username and password.
[ "ServicePrincipalToken", "creates", "a", "ServicePrincipalToken", "from", "username", "and", "password", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L668-L674
train
Azure/go-autorest
autorest/azure/auth/auth.go
Authorizer
func (ups UsernamePasswordConfig) Authorizer() (autorest.Authorizer, error) { spToken, err := ups.ServicePrincipalToken() if err != nil { return nil, fmt.Errorf("failed to get oauth token from username and password auth: %v", err) } return autorest.NewBearerAuthorizer(spToken), nil }
go
func (ups UsernamePasswordConfig) Authorizer() (autorest.Authorizer, error) { spToken, err := ups.ServicePrincipalToken() if err != nil { return nil, fmt.Errorf("failed to get oauth token from username and password auth: %v", err) } return autorest.NewBearerAuthorizer(spToken), nil }
[ "func", "(", "ups", "UsernamePasswordConfig", ")", "Authorizer", "(", ")", "(", "autorest", ".", "Authorizer", ",", "error", ")", "{", "spToken", ",", "err", ":=", "ups", ".", "ServicePrincipalToken", "(", ")", "\n", "if", "err", "!=", "nil", "{", "retur...
// Authorizer gets the authorizer from a username and a password.
[ "Authorizer", "gets", "the", "authorizer", "from", "a", "username", "and", "a", "password", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L677-L683
train
Azure/go-autorest
autorest/azure/auth/auth.go
Authorizer
func (mc MSIConfig) Authorizer() (autorest.Authorizer, error) { msiEndpoint, err := adal.GetMSIVMEndpoint() if err != nil { return nil, err } var spToken *adal.ServicePrincipalToken if mc.ClientID == "" { spToken, err = adal.NewServicePrincipalTokenFromMSI(msiEndpoint, mc.Resource) if err != nil { return nil, fmt.Errorf("failed to get oauth token from MSI: %v", err) } } else { spToken, err = adal.NewServicePrincipalTokenFromMSIWithUserAssignedID(msiEndpoint, mc.Resource, mc.ClientID) if err != nil { return nil, fmt.Errorf("failed to get oauth token from MSI for user assigned identity: %v", err) } } return autorest.NewBearerAuthorizer(spToken), nil }
go
func (mc MSIConfig) Authorizer() (autorest.Authorizer, error) { msiEndpoint, err := adal.GetMSIVMEndpoint() if err != nil { return nil, err } var spToken *adal.ServicePrincipalToken if mc.ClientID == "" { spToken, err = adal.NewServicePrincipalTokenFromMSI(msiEndpoint, mc.Resource) if err != nil { return nil, fmt.Errorf("failed to get oauth token from MSI: %v", err) } } else { spToken, err = adal.NewServicePrincipalTokenFromMSIWithUserAssignedID(msiEndpoint, mc.Resource, mc.ClientID) if err != nil { return nil, fmt.Errorf("failed to get oauth token from MSI for user assigned identity: %v", err) } } return autorest.NewBearerAuthorizer(spToken), nil }
[ "func", "(", "mc", "MSIConfig", ")", "Authorizer", "(", ")", "(", "autorest", ".", "Authorizer", ",", "error", ")", "{", "msiEndpoint", ",", "err", ":=", "adal", ".", "GetMSIVMEndpoint", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ...
// Authorizer gets the authorizer from MSI.
[ "Authorizer", "gets", "the", "authorizer", "from", "MSI", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/auth/auth.go#L692-L712
train
Azure/go-autorest
tracing/tracing.go
NewTransport
func NewTransport() *ochttp.Transport { return &ochttp.Transport{ Propagation: &tracecontext.HTTPFormat{}, GetStartOptions: getStartOptions, } }
go
func NewTransport() *ochttp.Transport { return &ochttp.Transport{ Propagation: &tracecontext.HTTPFormat{}, GetStartOptions: getStartOptions, } }
[ "func", "NewTransport", "(", ")", "*", "ochttp", ".", "Transport", "{", "return", "&", "ochttp", ".", "Transport", "{", "Propagation", ":", "&", "tracecontext", ".", "HTTPFormat", "{", "}", ",", "GetStartOptions", ":", "getStartOptions", ",", "}", "\n", "}...
// NewTransport returns a new instance of a tracing-aware RoundTripper.
[ "NewTransport", "returns", "a", "new", "instance", "of", "a", "tracing", "-", "aware", "RoundTripper", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/tracing/tracing.go#L68-L73
train
Azure/go-autorest
tracing/tracing.go
Disable
func Disable() { disableStats() sampler = trace.NeverSample() if traceExporter != nil { trace.UnregisterExporter(traceExporter) } enabled = false }
go
func Disable() { disableStats() sampler = trace.NeverSample() if traceExporter != nil { trace.UnregisterExporter(traceExporter) } enabled = false }
[ "func", "Disable", "(", ")", "{", "disableStats", "(", ")", "\n", "sampler", "=", "trace", ".", "NeverSample", "(", ")", "\n", "if", "traceExporter", "!=", "nil", "{", "trace", ".", "UnregisterExporter", "(", "traceExporter", ")", "\n", "}", "\n", "enabl...
// Disable will disable instrumentation for metrics and traces.
[ "Disable", "will", "disable", "instrumentation", "for", "metrics", "and", "traces", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/tracing/tracing.go#L90-L97
train
Azure/go-autorest
tracing/tracing.go
EnableWithAIForwarding
func EnableWithAIForwarding(agentEndpoint string) (err error) { err = Enable() if err != nil { return err } traceExporter, err := ocagent.NewExporter(ocagent.WithInsecure(), ocagent.WithAddress(agentEndpoint)) if err != nil { return err } trace.RegisterExporter(traceExporter) return }
go
func EnableWithAIForwarding(agentEndpoint string) (err error) { err = Enable() if err != nil { return err } traceExporter, err := ocagent.NewExporter(ocagent.WithInsecure(), ocagent.WithAddress(agentEndpoint)) if err != nil { return err } trace.RegisterExporter(traceExporter) return }
[ "func", "EnableWithAIForwarding", "(", "agentEndpoint", "string", ")", "(", "err", "error", ")", "{", "err", "=", "Enable", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "traceExporter", ",", "err", ":=", "ocagent", ...
// EnableWithAIForwarding will start instrumentation and will connect to app insights forwarder // exporter making the metrics and traces available in app insights.
[ "EnableWithAIForwarding", "will", "start", "instrumentation", "and", "will", "connect", "to", "app", "insights", "forwarder", "exporter", "making", "the", "metrics", "and", "traces", "available", "in", "app", "insights", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/tracing/tracing.go#L101-L113
train
Azure/go-autorest
tracing/tracing.go
initStats
func initStats() (err error) { clientViews := []*view.View{ ochttp.ClientCompletedCount, ochttp.ClientRoundtripLatencyDistribution, ochttp.ClientReceivedBytesDistribution, ochttp.ClientSentBytesDistribution, } for _, cv := range clientViews { vn := fmt.Sprintf("Azure/go-autorest/tracing-%s", cv.Name) views[vn] = cv.WithName(vn) err = view.Register(views[vn]) if err != nil { return err } } return }
go
func initStats() (err error) { clientViews := []*view.View{ ochttp.ClientCompletedCount, ochttp.ClientRoundtripLatencyDistribution, ochttp.ClientReceivedBytesDistribution, ochttp.ClientSentBytesDistribution, } for _, cv := range clientViews { vn := fmt.Sprintf("Azure/go-autorest/tracing-%s", cv.Name) views[vn] = cv.WithName(vn) err = view.Register(views[vn]) if err != nil { return err } } return }
[ "func", "initStats", "(", ")", "(", "err", "error", ")", "{", "clientViews", ":=", "[", "]", "*", "view", ".", "View", "{", "ochttp", ".", "ClientCompletedCount", ",", "ochttp", ".", "ClientRoundtripLatencyDistribution", ",", "ochttp", ".", "ClientReceivedByte...
// initStats registers the views for the http metrics
[ "initStats", "registers", "the", "views", "for", "the", "http", "metrics" ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/tracing/tracing.go#L123-L139
train
Azure/go-autorest
tracing/tracing.go
StartSpan
func StartSpan(ctx context.Context, name string) context.Context { ctx, _ = trace.StartSpan(ctx, name, trace.WithSampler(sampler)) return ctx }
go
func StartSpan(ctx context.Context, name string) context.Context { ctx, _ = trace.StartSpan(ctx, name, trace.WithSampler(sampler)) return ctx }
[ "func", "StartSpan", "(", "ctx", "context", ".", "Context", ",", "name", "string", ")", "context", ".", "Context", "{", "ctx", ",", "_", "=", "trace", ".", "StartSpan", "(", "ctx", ",", "name", ",", "trace", ".", "WithSampler", "(", "sampler", ")", "...
// StartSpan starts a trace span
[ "StartSpan", "starts", "a", "trace", "span" ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/tracing/tracing.go#L149-L152
train
Azure/go-autorest
tracing/tracing.go
EndSpan
func EndSpan(ctx context.Context, httpStatusCode int, err error) { span := trace.FromContext(ctx) if span == nil { return } if err != nil { span.SetStatus(trace.Status{Message: err.Error(), Code: toTraceStatusCode(httpStatusCode)}) } span.End() }
go
func EndSpan(ctx context.Context, httpStatusCode int, err error) { span := trace.FromContext(ctx) if span == nil { return } if err != nil { span.SetStatus(trace.Status{Message: err.Error(), Code: toTraceStatusCode(httpStatusCode)}) } span.End() }
[ "func", "EndSpan", "(", "ctx", "context", ".", "Context", ",", "httpStatusCode", "int", ",", "err", "error", ")", "{", "span", ":=", "trace", ".", "FromContext", "(", "ctx", ")", "\n\n", "if", "span", "==", "nil", "{", "return", "\n", "}", "\n\n", "i...
// EndSpan ends a previously started span stored in the context
[ "EndSpan", "ends", "a", "previously", "started", "span", "stored", "in", "the", "context" ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/tracing/tracing.go#L155-L166
train
Azure/go-autorest
autorest/adal/persist.go
SaveToken
func SaveToken(path string, mode os.FileMode, token Token) error { dir := filepath.Dir(path) err := os.MkdirAll(dir, os.ModePerm) if err != nil { return fmt.Errorf("failed to create directory (%s) to store token in: %v", dir, err) } newFile, err := ioutil.TempFile(dir, "token") if err != nil { return fmt.Errorf("failed to create the temp file to write the token: %v", err) } tempPath := newFile.Name() if err := json.NewEncoder(newFile).Encode(token); err != nil { return fmt.Errorf("failed to encode token to file (%s) while saving token: %v", tempPath, err) } if err := newFile.Close(); err != nil { return fmt.Errorf("failed to close temp file %s: %v", tempPath, err) } // Atomic replace to avoid multi-writer file corruptions if err := os.Rename(tempPath, path); err != nil { return fmt.Errorf("failed to move temporary token to desired output location. src=%s dst=%s: %v", tempPath, path, err) } if err := os.Chmod(path, mode); err != nil { return fmt.Errorf("failed to chmod the token file %s: %v", path, err) } return nil }
go
func SaveToken(path string, mode os.FileMode, token Token) error { dir := filepath.Dir(path) err := os.MkdirAll(dir, os.ModePerm) if err != nil { return fmt.Errorf("failed to create directory (%s) to store token in: %v", dir, err) } newFile, err := ioutil.TempFile(dir, "token") if err != nil { return fmt.Errorf("failed to create the temp file to write the token: %v", err) } tempPath := newFile.Name() if err := json.NewEncoder(newFile).Encode(token); err != nil { return fmt.Errorf("failed to encode token to file (%s) while saving token: %v", tempPath, err) } if err := newFile.Close(); err != nil { return fmt.Errorf("failed to close temp file %s: %v", tempPath, err) } // Atomic replace to avoid multi-writer file corruptions if err := os.Rename(tempPath, path); err != nil { return fmt.Errorf("failed to move temporary token to desired output location. src=%s dst=%s: %v", tempPath, path, err) } if err := os.Chmod(path, mode); err != nil { return fmt.Errorf("failed to chmod the token file %s: %v", path, err) } return nil }
[ "func", "SaveToken", "(", "path", "string", ",", "mode", "os", ".", "FileMode", ",", "token", "Token", ")", "error", "{", "dir", ":=", "filepath", ".", "Dir", "(", "path", ")", "\n", "err", ":=", "os", ".", "MkdirAll", "(", "dir", ",", "os", ".", ...
// SaveToken persists an oauth token at the given location on disk. // It moves the new file into place so it can safely be used to replace an existing file // that maybe accessed by multiple processes.
[ "SaveToken", "persists", "an", "oauth", "token", "at", "the", "given", "location", "on", "disk", ".", "It", "moves", "the", "new", "file", "into", "place", "so", "it", "can", "safely", "be", "used", "to", "replace", "an", "existing", "file", "that", "may...
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/adal/persist.go#L45-L73
train
Azure/go-autorest
autorest/authorization.go
NewAPIKeyAuthorizer
func NewAPIKeyAuthorizer(headers map[string]interface{}, queryParameters map[string]interface{}) *APIKeyAuthorizer { return &APIKeyAuthorizer{headers: headers, queryParameters: queryParameters} }
go
func NewAPIKeyAuthorizer(headers map[string]interface{}, queryParameters map[string]interface{}) *APIKeyAuthorizer { return &APIKeyAuthorizer{headers: headers, queryParameters: queryParameters} }
[ "func", "NewAPIKeyAuthorizer", "(", "headers", "map", "[", "string", "]", "interface", "{", "}", ",", "queryParameters", "map", "[", "string", "]", "interface", "{", "}", ")", "*", "APIKeyAuthorizer", "{", "return", "&", "APIKeyAuthorizer", "{", "headers", "...
// NewAPIKeyAuthorizer creates an ApiKeyAuthorizer with headers.
[ "NewAPIKeyAuthorizer", "creates", "an", "ApiKeyAuthorizer", "with", "headers", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/authorization.go#L71-L73
train
Azure/go-autorest
autorest/authorization.go
WithAuthorization
func (aka *APIKeyAuthorizer) WithAuthorization() PrepareDecorator { return func(p Preparer) Preparer { return DecoratePreparer(p, WithHeaders(aka.headers), WithQueryParameters(aka.queryParameters)) } }
go
func (aka *APIKeyAuthorizer) WithAuthorization() PrepareDecorator { return func(p Preparer) Preparer { return DecoratePreparer(p, WithHeaders(aka.headers), WithQueryParameters(aka.queryParameters)) } }
[ "func", "(", "aka", "*", "APIKeyAuthorizer", ")", "WithAuthorization", "(", ")", "PrepareDecorator", "{", "return", "func", "(", "p", "Preparer", ")", "Preparer", "{", "return", "DecoratePreparer", "(", "p", ",", "WithHeaders", "(", "aka", ".", "headers", ")...
// WithAuthorization returns a PrepareDecorator that adds an HTTP headers and Query Parameters.
[ "WithAuthorization", "returns", "a", "PrepareDecorator", "that", "adds", "an", "HTTP", "headers", "and", "Query", "Parameters", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/authorization.go#L76-L80
train
Azure/go-autorest
autorest/authorization.go
WithAuthorization
func (ba *BearerAuthorizer) WithAuthorization() PrepareDecorator { return func(p Preparer) Preparer { return PreparerFunc(func(r *http.Request) (*http.Request, error) { r, err := p.Prepare(r) if err == nil { // the ordering is important here, prefer RefresherWithContext if available if refresher, ok := ba.tokenProvider.(adal.RefresherWithContext); ok { err = refresher.EnsureFreshWithContext(r.Context()) } else if refresher, ok := ba.tokenProvider.(adal.Refresher); ok { err = refresher.EnsureFresh() } if err != nil { var resp *http.Response if tokError, ok := err.(adal.TokenRefreshError); ok { resp = tokError.Response() } return r, NewErrorWithError(err, "azure.BearerAuthorizer", "WithAuthorization", resp, "Failed to refresh the Token for request to %s", r.URL) } return Prepare(r, WithHeader(headerAuthorization, fmt.Sprintf("Bearer %s", ba.tokenProvider.OAuthToken()))) } return r, err }) } }
go
func (ba *BearerAuthorizer) WithAuthorization() PrepareDecorator { return func(p Preparer) Preparer { return PreparerFunc(func(r *http.Request) (*http.Request, error) { r, err := p.Prepare(r) if err == nil { // the ordering is important here, prefer RefresherWithContext if available if refresher, ok := ba.tokenProvider.(adal.RefresherWithContext); ok { err = refresher.EnsureFreshWithContext(r.Context()) } else if refresher, ok := ba.tokenProvider.(adal.Refresher); ok { err = refresher.EnsureFresh() } if err != nil { var resp *http.Response if tokError, ok := err.(adal.TokenRefreshError); ok { resp = tokError.Response() } return r, NewErrorWithError(err, "azure.BearerAuthorizer", "WithAuthorization", resp, "Failed to refresh the Token for request to %s", r.URL) } return Prepare(r, WithHeader(headerAuthorization, fmt.Sprintf("Bearer %s", ba.tokenProvider.OAuthToken()))) } return r, err }) } }
[ "func", "(", "ba", "*", "BearerAuthorizer", ")", "WithAuthorization", "(", ")", "PrepareDecorator", "{", "return", "func", "(", "p", "Preparer", ")", "Preparer", "{", "return", "PreparerFunc", "(", "func", "(", "r", "*", "http", ".", "Request", ")", "(", ...
// WithAuthorization returns a PrepareDecorator that adds an HTTP Authorization header whose // value is "Bearer " followed by the token. // // By default, the token will be automatically refreshed through the Refresher interface.
[ "WithAuthorization", "returns", "a", "PrepareDecorator", "that", "adds", "an", "HTTP", "Authorization", "header", "whose", "value", "is", "Bearer", "followed", "by", "the", "token", ".", "By", "default", "the", "token", "will", "be", "automatically", "refreshed", ...
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/authorization.go#L115-L139
train
Azure/go-autorest
autorest/authorization.go
NewBearerAuthorizerCallback
func NewBearerAuthorizerCallback(sender Sender, callback BearerAuthorizerCallbackFunc) *BearerAuthorizerCallback { if sender == nil { sender = &http.Client{Transport: tracing.Transport} } return &BearerAuthorizerCallback{sender: sender, callback: callback} }
go
func NewBearerAuthorizerCallback(sender Sender, callback BearerAuthorizerCallbackFunc) *BearerAuthorizerCallback { if sender == nil { sender = &http.Client{Transport: tracing.Transport} } return &BearerAuthorizerCallback{sender: sender, callback: callback} }
[ "func", "NewBearerAuthorizerCallback", "(", "sender", "Sender", ",", "callback", "BearerAuthorizerCallbackFunc", ")", "*", "BearerAuthorizerCallback", "{", "if", "sender", "==", "nil", "{", "sender", "=", "&", "http", ".", "Client", "{", "Transport", ":", "tracing...
// NewBearerAuthorizerCallback creates a bearer authorization callback. The callback // is invoked when the HTTP request is submitted.
[ "NewBearerAuthorizerCallback", "creates", "a", "bearer", "authorization", "callback", ".", "The", "callback", "is", "invoked", "when", "the", "HTTP", "request", "is", "submitted", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/authorization.go#L152-L157
train
Azure/go-autorest
autorest/authorization.go
WithAuthorization
func (bacb *BearerAuthorizerCallback) WithAuthorization() PrepareDecorator { return func(p Preparer) Preparer { return PreparerFunc(func(r *http.Request) (*http.Request, error) { r, err := p.Prepare(r) if err == nil { // make a copy of the request and remove the body as it's not // required and avoids us having to create a copy of it. rCopy := *r removeRequestBody(&rCopy) resp, err := bacb.sender.Do(&rCopy) if err == nil && resp.StatusCode == 401 { defer resp.Body.Close() if hasBearerChallenge(resp) { bc, err := newBearerChallenge(resp) if err != nil { return r, err } if bacb.callback != nil { ba, err := bacb.callback(bc.values[tenantID], bc.values["resource"]) if err != nil { return r, err } return Prepare(r, ba.WithAuthorization()) } } } } return r, err }) } }
go
func (bacb *BearerAuthorizerCallback) WithAuthorization() PrepareDecorator { return func(p Preparer) Preparer { return PreparerFunc(func(r *http.Request) (*http.Request, error) { r, err := p.Prepare(r) if err == nil { // make a copy of the request and remove the body as it's not // required and avoids us having to create a copy of it. rCopy := *r removeRequestBody(&rCopy) resp, err := bacb.sender.Do(&rCopy) if err == nil && resp.StatusCode == 401 { defer resp.Body.Close() if hasBearerChallenge(resp) { bc, err := newBearerChallenge(resp) if err != nil { return r, err } if bacb.callback != nil { ba, err := bacb.callback(bc.values[tenantID], bc.values["resource"]) if err != nil { return r, err } return Prepare(r, ba.WithAuthorization()) } } } } return r, err }) } }
[ "func", "(", "bacb", "*", "BearerAuthorizerCallback", ")", "WithAuthorization", "(", ")", "PrepareDecorator", "{", "return", "func", "(", "p", "Preparer", ")", "Preparer", "{", "return", "PreparerFunc", "(", "func", "(", "r", "*", "http", ".", "Request", ")"...
// WithAuthorization returns a PrepareDecorator that adds an HTTP Authorization header whose value // is "Bearer " followed by the token. The BearerAuthorizer is obtained via a user-supplied callback. // // By default, the token will be automatically refreshed through the Refresher interface.
[ "WithAuthorization", "returns", "a", "PrepareDecorator", "that", "adds", "an", "HTTP", "Authorization", "header", "whose", "value", "is", "Bearer", "followed", "by", "the", "token", ".", "The", "BearerAuthorizer", "is", "obtained", "via", "a", "user", "-", "supp...
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/authorization.go#L163-L194
train
Azure/go-autorest
autorest/authorization.go
hasBearerChallenge
func hasBearerChallenge(resp *http.Response) bool { authHeader := resp.Header.Get(bearerChallengeHeader) if len(authHeader) == 0 || strings.Index(authHeader, bearer) < 0 { return false } return true }
go
func hasBearerChallenge(resp *http.Response) bool { authHeader := resp.Header.Get(bearerChallengeHeader) if len(authHeader) == 0 || strings.Index(authHeader, bearer) < 0 { return false } return true }
[ "func", "hasBearerChallenge", "(", "resp", "*", "http", ".", "Response", ")", "bool", "{", "authHeader", ":=", "resp", ".", "Header", ".", "Get", "(", "bearerChallengeHeader", ")", "\n", "if", "len", "(", "authHeader", ")", "==", "0", "||", "strings", "....
// returns true if the HTTP response contains a bearer challenge
[ "returns", "true", "if", "the", "HTTP", "response", "contains", "a", "bearer", "challenge" ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/authorization.go#L197-L203
train
Azure/go-autorest
autorest/authorization.go
WithAuthorization
func (egta EventGridKeyAuthorizer) WithAuthorization() PrepareDecorator { headers := map[string]interface{}{ "aeg-sas-key": egta.topicKey, } return NewAPIKeyAuthorizerWithHeaders(headers).WithAuthorization() }
go
func (egta EventGridKeyAuthorizer) WithAuthorization() PrepareDecorator { headers := map[string]interface{}{ "aeg-sas-key": egta.topicKey, } return NewAPIKeyAuthorizerWithHeaders(headers).WithAuthorization() }
[ "func", "(", "egta", "EventGridKeyAuthorizer", ")", "WithAuthorization", "(", ")", "PrepareDecorator", "{", "headers", ":=", "map", "[", "string", "]", "interface", "{", "}", "{", "\"", "\"", ":", "egta", ".", "topicKey", ",", "}", "\n", "return", "NewAPIK...
// WithAuthorization returns a PrepareDecorator that adds the aeg-sas-key authentication header.
[ "WithAuthorization", "returns", "a", "PrepareDecorator", "that", "adds", "the", "aeg", "-", "sas", "-", "key", "authentication", "header", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/authorization.go#L258-L263
train
Azure/go-autorest
autorest/authorization.go
NewBasicAuthorizer
func NewBasicAuthorizer(userName, password string) *BasicAuthorizer { return &BasicAuthorizer{ userName: userName, password: password, } }
go
func NewBasicAuthorizer(userName, password string) *BasicAuthorizer { return &BasicAuthorizer{ userName: userName, password: password, } }
[ "func", "NewBasicAuthorizer", "(", "userName", ",", "password", "string", ")", "*", "BasicAuthorizer", "{", "return", "&", "BasicAuthorizer", "{", "userName", ":", "userName", ",", "password", ":", "password", ",", "}", "\n", "}" ]
// NewBasicAuthorizer creates a new BasicAuthorizer with the specified username and password.
[ "NewBasicAuthorizer", "creates", "a", "new", "BasicAuthorizer", "with", "the", "specified", "username", "and", "password", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/authorization.go#L273-L278
train
Azure/go-autorest
autorest/client.go
Do
func (c Client) Do(r *http.Request) (*http.Response, error) { if r.UserAgent() == "" { r, _ = Prepare(r, WithUserAgent(c.UserAgent)) } // NOTE: c.WithInspection() must be last in the list so that it can inspect all preceding operations r, err := Prepare(r, c.WithAuthorization(), c.WithInspection()) if err != nil { var resp *http.Response if detErr, ok := err.(DetailedError); ok { // if the authorization failed (e.g. invalid credentials) there will // be a response associated with the error, be sure to return it. resp = detErr.Response } return resp, NewErrorWithError(err, "autorest/Client", "Do", nil, "Preparing request failed") } logger.Instance.WriteRequest(r, logger.Filter{ Header: func(k string, v []string) (bool, []string) { // remove the auth token from the log if strings.EqualFold(k, "Authorization") || strings.EqualFold(k, "Ocp-Apim-Subscription-Key") { v = []string{"**REDACTED**"} } return true, v }, }) resp, err := SendWithSender(c.sender(tls.RenegotiateNever), r) logger.Instance.WriteResponse(resp, logger.Filter{}) Respond(resp, c.ByInspecting()) return resp, err }
go
func (c Client) Do(r *http.Request) (*http.Response, error) { if r.UserAgent() == "" { r, _ = Prepare(r, WithUserAgent(c.UserAgent)) } // NOTE: c.WithInspection() must be last in the list so that it can inspect all preceding operations r, err := Prepare(r, c.WithAuthorization(), c.WithInspection()) if err != nil { var resp *http.Response if detErr, ok := err.(DetailedError); ok { // if the authorization failed (e.g. invalid credentials) there will // be a response associated with the error, be sure to return it. resp = detErr.Response } return resp, NewErrorWithError(err, "autorest/Client", "Do", nil, "Preparing request failed") } logger.Instance.WriteRequest(r, logger.Filter{ Header: func(k string, v []string) (bool, []string) { // remove the auth token from the log if strings.EqualFold(k, "Authorization") || strings.EqualFold(k, "Ocp-Apim-Subscription-Key") { v = []string{"**REDACTED**"} } return true, v }, }) resp, err := SendWithSender(c.sender(tls.RenegotiateNever), r) logger.Instance.WriteResponse(resp, logger.Filter{}) Respond(resp, c.ByInspecting()) return resp, err }
[ "func", "(", "c", "Client", ")", "Do", "(", "r", "*", "http", ".", "Request", ")", "(", "*", "http", ".", "Response", ",", "error", ")", "{", "if", "r", ".", "UserAgent", "(", ")", "==", "\"", "\"", "{", "r", ",", "_", "=", "Prepare", "(", ...
// Do implements the Sender interface by invoking the active Sender after applying authorization. // If Sender is not set, it uses a new instance of http.Client. In both cases it will, if UserAgent // is set, apply set the User-Agent header.
[ "Do", "implements", "the", "Sender", "interface", "by", "invoking", "the", "active", "Sender", "after", "applying", "authorization", ".", "If", "Sender", "is", "not", "set", "it", "uses", "a", "new", "instance", "of", "http", ".", "Client", ".", "In", "bot...
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/client.go#L215-L246
train
Azure/go-autorest
autorest/client.go
sender
func (c Client) sender(renengotiation tls.RenegotiationSupport) Sender { if c.Sender == nil { // Use behaviour compatible with DefaultTransport, but require TLS minimum version. var defaultTransport = http.DefaultTransport.(*http.Transport) transport := tracing.Transport // for non-default values of TLS renegotiation create a new tracing transport. // updating tracing.Transport affects all clients which is not what we want. if renengotiation != tls.RenegotiateNever { transport = tracing.NewTransport() } transport.Base = &http.Transport{ Proxy: defaultTransport.Proxy, DialContext: defaultTransport.DialContext, MaxIdleConns: defaultTransport.MaxIdleConns, IdleConnTimeout: defaultTransport.IdleConnTimeout, TLSHandshakeTimeout: defaultTransport.TLSHandshakeTimeout, ExpectContinueTimeout: defaultTransport.ExpectContinueTimeout, TLSClientConfig: &tls.Config{ MinVersion: tls.VersionTLS12, Renegotiation: renengotiation, }, } j, _ := cookiejar.New(nil) return &http.Client{Jar: j, Transport: transport} } return c.Sender }
go
func (c Client) sender(renengotiation tls.RenegotiationSupport) Sender { if c.Sender == nil { // Use behaviour compatible with DefaultTransport, but require TLS minimum version. var defaultTransport = http.DefaultTransport.(*http.Transport) transport := tracing.Transport // for non-default values of TLS renegotiation create a new tracing transport. // updating tracing.Transport affects all clients which is not what we want. if renengotiation != tls.RenegotiateNever { transport = tracing.NewTransport() } transport.Base = &http.Transport{ Proxy: defaultTransport.Proxy, DialContext: defaultTransport.DialContext, MaxIdleConns: defaultTransport.MaxIdleConns, IdleConnTimeout: defaultTransport.IdleConnTimeout, TLSHandshakeTimeout: defaultTransport.TLSHandshakeTimeout, ExpectContinueTimeout: defaultTransport.ExpectContinueTimeout, TLSClientConfig: &tls.Config{ MinVersion: tls.VersionTLS12, Renegotiation: renengotiation, }, } j, _ := cookiejar.New(nil) return &http.Client{Jar: j, Transport: transport} } return c.Sender }
[ "func", "(", "c", "Client", ")", "sender", "(", "renengotiation", "tls", ".", "RenegotiationSupport", ")", "Sender", "{", "if", "c", ".", "Sender", "==", "nil", "{", "// Use behaviour compatible with DefaultTransport, but require TLS minimum version.", "var", "defaultTr...
// sender returns the Sender to which to send requests.
[ "sender", "returns", "the", "Sender", "to", "which", "to", "send", "requests", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/client.go#L249-L276
train
Azure/go-autorest
autorest/client.go
authorizer
func (c Client) authorizer() Authorizer { if c.Authorizer == nil { return NullAuthorizer{} } return c.Authorizer }
go
func (c Client) authorizer() Authorizer { if c.Authorizer == nil { return NullAuthorizer{} } return c.Authorizer }
[ "func", "(", "c", "Client", ")", "authorizer", "(", ")", "Authorizer", "{", "if", "c", ".", "Authorizer", "==", "nil", "{", "return", "NullAuthorizer", "{", "}", "\n", "}", "\n", "return", "c", ".", "Authorizer", "\n", "}" ]
// authorizer returns the Authorizer to use.
[ "authorizer", "returns", "the", "Authorizer", "to", "use", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/client.go#L285-L290
train
Azure/go-autorest
autorest/client.go
WithInspection
func (c Client) WithInspection() PrepareDecorator { if c.RequestInspector == nil { return WithNothing() } return c.RequestInspector }
go
func (c Client) WithInspection() PrepareDecorator { if c.RequestInspector == nil { return WithNothing() } return c.RequestInspector }
[ "func", "(", "c", "Client", ")", "WithInspection", "(", ")", "PrepareDecorator", "{", "if", "c", ".", "RequestInspector", "==", "nil", "{", "return", "WithNothing", "(", ")", "\n", "}", "\n", "return", "c", ".", "RequestInspector", "\n", "}" ]
// WithInspection is a convenience method that passes the request to the supplied RequestInspector, // if present, or returns the WithNothing PrepareDecorator otherwise.
[ "WithInspection", "is", "a", "convenience", "method", "that", "passes", "the", "request", "to", "the", "supplied", "RequestInspector", "if", "present", "or", "returns", "the", "WithNothing", "PrepareDecorator", "otherwise", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/client.go#L294-L299
train
Azure/go-autorest
autorest/client.go
ByInspecting
func (c Client) ByInspecting() RespondDecorator { if c.ResponseInspector == nil { return ByIgnoring() } return c.ResponseInspector }
go
func (c Client) ByInspecting() RespondDecorator { if c.ResponseInspector == nil { return ByIgnoring() } return c.ResponseInspector }
[ "func", "(", "c", "Client", ")", "ByInspecting", "(", ")", "RespondDecorator", "{", "if", "c", ".", "ResponseInspector", "==", "nil", "{", "return", "ByIgnoring", "(", ")", "\n", "}", "\n", "return", "c", ".", "ResponseInspector", "\n", "}" ]
// ByInspecting is a convenience method that passes the response to the supplied ResponseInspector, // if present, or returns the ByIgnoring RespondDecorator otherwise.
[ "ByInspecting", "is", "a", "convenience", "method", "that", "passes", "the", "response", "to", "the", "supplied", "ResponseInspector", "if", "present", "or", "returns", "the", "ByIgnoring", "RespondDecorator", "otherwise", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/client.go#L303-L308
train
Azure/go-autorest
logger/logger.go
ParseLevel
func ParseLevel(s string) (lt LevelType, err error) { switch strings.ToUpper(s) { case logFatal: lt = LogFatal case logPanic: lt = LogPanic case logError: lt = LogError case logWarning: lt = LogWarning case logInfo: lt = LogInfo case logDebug: lt = LogDebug default: err = fmt.Errorf("bad log level '%s'", s) } return }
go
func ParseLevel(s string) (lt LevelType, err error) { switch strings.ToUpper(s) { case logFatal: lt = LogFatal case logPanic: lt = LogPanic case logError: lt = LogError case logWarning: lt = LogWarning case logInfo: lt = LogInfo case logDebug: lt = LogDebug default: err = fmt.Errorf("bad log level '%s'", s) } return }
[ "func", "ParseLevel", "(", "s", "string", ")", "(", "lt", "LevelType", ",", "err", "error", ")", "{", "switch", "strings", ".", "ToUpper", "(", "s", ")", "{", "case", "logFatal", ":", "lt", "=", "LogFatal", "\n", "case", "logPanic", ":", "lt", "=", ...
// ParseLevel converts the specified string into the corresponding LevelType.
[ "ParseLevel", "converts", "the", "specified", "string", "into", "the", "corresponding", "LevelType", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/logger/logger.go#L72-L90
train
Azure/go-autorest
logger/logger.go
String
func (lt LevelType) String() string { switch lt { case LogNone: return logNone case LogFatal: return logFatal case LogPanic: return logPanic case LogError: return logError case LogWarning: return logWarning case LogInfo: return logInfo case LogDebug: return logDebug default: return logUnknown } }
go
func (lt LevelType) String() string { switch lt { case LogNone: return logNone case LogFatal: return logFatal case LogPanic: return logPanic case LogError: return logError case LogWarning: return logWarning case LogInfo: return logInfo case LogDebug: return logDebug default: return logUnknown } }
[ "func", "(", "lt", "LevelType", ")", "String", "(", ")", "string", "{", "switch", "lt", "{", "case", "LogNone", ":", "return", "logNone", "\n", "case", "LogFatal", ":", "return", "logFatal", "\n", "case", "LogPanic", ":", "return", "logPanic", "\n", "cas...
// String implements the stringer interface for LevelType.
[ "String", "implements", "the", "stringer", "interface", "for", "LevelType", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/logger/logger.go#L93-L112
train
Azure/go-autorest
logger/logger.go
shouldLogBody
func (fl fileLogger) shouldLogBody(header http.Header, body io.ReadCloser) bool { ct := header.Get("Content-Type") return fl.logLevel >= LogDebug && body != nil && !strings.Contains(ct, "application/octet-stream") }
go
func (fl fileLogger) shouldLogBody(header http.Header, body io.ReadCloser) bool { ct := header.Get("Content-Type") return fl.logLevel >= LogDebug && body != nil && !strings.Contains(ct, "application/octet-stream") }
[ "func", "(", "fl", "fileLogger", ")", "shouldLogBody", "(", "header", "http", ".", "Header", ",", "body", "io", ".", "ReadCloser", ")", "bool", "{", "ct", ":=", "header", ".", "Get", "(", "\"", "\"", ")", "\n", "return", "fl", ".", "logLevel", ">=", ...
// returns true if the provided body should be included in the log
[ "returns", "true", "if", "the", "provided", "body", "should", "be", "included", "in", "the", "log" ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/logger/logger.go#L319-L322
train
Azure/go-autorest
logger/logger.go
entryHeader
func entryHeader(level LevelType) string { // this format provides a fixed number of digits so the size of the timestamp is constant return fmt.Sprintf("(%s) %s:", time.Now().Format("2006-01-02T15:04:05.0000000Z07:00"), level.String()) }
go
func entryHeader(level LevelType) string { // this format provides a fixed number of digits so the size of the timestamp is constant return fmt.Sprintf("(%s) %s:", time.Now().Format("2006-01-02T15:04:05.0000000Z07:00"), level.String()) }
[ "func", "entryHeader", "(", "level", "LevelType", ")", "string", "{", "// this format provides a fixed number of digits so the size of the timestamp is constant", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "time", ".", "Now", "(", ")", ".", "Format", "(", ...
// creates standard header for log entries, it contains a timestamp and the log level
[ "creates", "standard", "header", "for", "log", "entries", "it", "contains", "a", "timestamp", "and", "the", "log", "level" ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/logger/logger.go#L325-L328
train
Azure/go-autorest
autorest/azure/rp.go
DoRetryWithRegistration
func DoRetryWithRegistration(client autorest.Client) autorest.SendDecorator { return func(s autorest.Sender) autorest.Sender { return autorest.SenderFunc(func(r *http.Request) (resp *http.Response, err error) { rr := autorest.NewRetriableRequest(r) for currentAttempt := 0; currentAttempt < client.RetryAttempts; currentAttempt++ { err = rr.Prepare() if err != nil { return resp, err } resp, err = autorest.SendWithSender(s, rr.Request(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...), ) if err != nil { return resp, err } if resp.StatusCode != http.StatusConflict || client.SkipResourceProviderRegistration { return resp, err } var re RequestError err = autorest.Respond( resp, autorest.ByUnmarshallingJSON(&re), ) if err != nil { return resp, err } err = re if re.ServiceError != nil && re.ServiceError.Code == "MissingSubscriptionRegistration" { regErr := register(client, r, re) if regErr != nil { return resp, fmt.Errorf("failed auto registering Resource Provider: %s. Original error: %s", regErr, err) } } } return resp, err }) } }
go
func DoRetryWithRegistration(client autorest.Client) autorest.SendDecorator { return func(s autorest.Sender) autorest.Sender { return autorest.SenderFunc(func(r *http.Request) (resp *http.Response, err error) { rr := autorest.NewRetriableRequest(r) for currentAttempt := 0; currentAttempt < client.RetryAttempts; currentAttempt++ { err = rr.Prepare() if err != nil { return resp, err } resp, err = autorest.SendWithSender(s, rr.Request(), autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...), ) if err != nil { return resp, err } if resp.StatusCode != http.StatusConflict || client.SkipResourceProviderRegistration { return resp, err } var re RequestError err = autorest.Respond( resp, autorest.ByUnmarshallingJSON(&re), ) if err != nil { return resp, err } err = re if re.ServiceError != nil && re.ServiceError.Code == "MissingSubscriptionRegistration" { regErr := register(client, r, re) if regErr != nil { return resp, fmt.Errorf("failed auto registering Resource Provider: %s. Original error: %s", regErr, err) } } } return resp, err }) } }
[ "func", "DoRetryWithRegistration", "(", "client", "autorest", ".", "Client", ")", "autorest", ".", "SendDecorator", "{", "return", "func", "(", "s", "autorest", ".", "Sender", ")", "autorest", ".", "Sender", "{", "return", "autorest", ".", "SenderFunc", "(", ...
// DoRetryWithRegistration tries to register the resource provider in case it is unregistered. // It also handles request retries
[ "DoRetryWithRegistration", "tries", "to", "register", "the", "resource", "provider", "in", "case", "it", "is", "unregistered", ".", "It", "also", "handles", "request", "retries" ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/azure/rp.go#L30-L70
train
Azure/go-autorest
autorest/mocks/helpers.go
NewRequestWithContent
func NewRequestWithContent(c string) *http.Request { r, _ := http.NewRequest("GET", "https://microsoft.com/a/b/c/", NewBody(c)) return r }
go
func NewRequestWithContent(c string) *http.Request { r, _ := http.NewRequest("GET", "https://microsoft.com/a/b/c/", NewBody(c)) return r }
[ "func", "NewRequestWithContent", "(", "c", "string", ")", "*", "http", ".", "Request", "{", "r", ",", "_", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "\"", "\"", ",", "NewBody", "(", "c", ")", ")", "\n", "return", "r", "\n", "}" ]
// NewRequestWithContent instantiates a new request using the passed string for the body content.
[ "NewRequestWithContent", "instantiates", "a", "new", "request", "using", "the", "passed", "string", "for", "the", "body", "content", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/mocks/helpers.go#L58-L61
train
Azure/go-autorest
autorest/mocks/helpers.go
NewRequestWithCloseBodyContent
func NewRequestWithCloseBodyContent(c string) *http.Request { r, _ := http.NewRequest("GET", "https://microsoft.com/a/b/c/", NewBodyClose(c)) return r }
go
func NewRequestWithCloseBodyContent(c string) *http.Request { r, _ := http.NewRequest("GET", "https://microsoft.com/a/b/c/", NewBodyClose(c)) return r }
[ "func", "NewRequestWithCloseBodyContent", "(", "c", "string", ")", "*", "http", ".", "Request", "{", "r", ",", "_", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "\"", "\"", ",", "NewBodyClose", "(", "c", ")", ")", "\n", "return", "r", "\n",...
// NewRequestWithCloseBodyContent instantiates a new request using the passed string for the body content.
[ "NewRequestWithCloseBodyContent", "instantiates", "a", "new", "request", "using", "the", "passed", "string", "for", "the", "body", "content", "." ]
da8db3a19ec5aba5d01f6032407abf1bb1cc15d3
https://github.com/Azure/go-autorest/blob/da8db3a19ec5aba5d01f6032407abf1bb1cc15d3/autorest/mocks/helpers.go#L69-L72
train