Offer Knob to Disable Syslog | Default logging to syslog enabled (#268)

* Provide Knob For Syslog

* Reverting changes to GetTags/SetTags & BlobPropertiesInternal (#269)

* Adding MSI Login Example (#241)

* Added MSI login example

* Minor edits

Co-authored-by: zezha-msft <zezha@microsoft.com>

* Reverting changes to GetTags/SetTags & BlobPropertiesInternal

Co-authored-by: Mohit Sharma <65536214+mohsha-msft@users.noreply.github.com>
Co-authored-by: zezha-msft <zezha@microsoft.com>

Co-authored-by: siminsavani-msft <77068571+siminsavani-msft@users.noreply.github.com>
Co-authored-by: zezha-msft <zezha@microsoft.com>
This commit is contained in:
Mohit Sharma 2021-04-07 08:08:46 +05:30 коммит произвёл GitHub
Родитель e80b0e0063
Коммит 16cf969ec1
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 52 добавлений и 45 удалений

Просмотреть файл

@ -146,15 +146,15 @@ func (b BlobURL) Delete(ctx context.Context, deleteOptions DeleteSnapshotsOption
// Each call to this operation replaces all existing tags attached to the blob.
// To remove all tags from the blob, call this operation with no tags set.
// https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-tags
func (b BlobURL) SetTags(ctx context.Context, timeout *int32, versionID *string, transactionalContentMD5 []byte, transactionalContentCrc64 []byte, requestID *string, ifTags *string, blobTagsMap BlobTagsMap) (*BlobSetTagsResponse, error) {
func (b BlobURL) SetTags(ctx context.Context, transactionalContentMD5 []byte, transactionalContentCrc64 []byte, ifTags *string, blobTagsMap BlobTagsMap) (*BlobSetTagsResponse, error) {
tags := SerializeBlobTags(blobTagsMap)
return b.blobClient.SetTags(ctx, timeout, versionID, transactionalContentMD5, transactionalContentCrc64, requestID, ifTags, nil, &tags)
return b.blobClient.SetTags(ctx, nil, nil, transactionalContentMD5, transactionalContentCrc64, nil, ifTags, nil, &tags)
}
// GetTags operation enables users to get tags on a blob or specific blob version, or snapshot.
// https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-tags
func (b BlobURL) GetTags(ctx context.Context, timeout *int32, requestID *string, snapshot *string, versionID *string, ifTags *string) (*BlobTags, error) {
return b.blobClient.GetTags(ctx, timeout, requestID, snapshot, versionID, ifTags, nil)
func (b BlobURL) GetTags(ctx context.Context, ifTags *string) (*BlobTags, error) {
return b.blobClient.GetTags(ctx, nil, nil, nil, nil, ifTags, nil)
}
// Undelete restores the contents and metadata of a soft-deleted blob and any associated soft-deleted snapshots.

Просмотреть файл

@ -18,6 +18,11 @@ type RequestLogOptions struct {
// LogWarningIfTryOverThreshold logs a warning if a tried operation takes longer than the specified
// duration (-1=no logging; 0=default threshold).
LogWarningIfTryOverThreshold time.Duration
// SyslogDisabled is a flag to check if logging to Syslog/Windows-Event-Logger is enabled or not
// We by default print to Syslog/Windows-Event-Logger.
// If SyslogDisabled is not provided explicitly, the default value will be false.
SyslogDisabled bool
}
func (o RequestLogOptions) defaults() RequestLogOptions {
@ -59,7 +64,7 @@ func NewRequestLogPolicyFactory(o RequestLogOptions) pipeline.Factory {
// If the response took too long, we'll upgrade to warning.
if o.LogWarningIfTryOverThreshold > 0 && tryDuration > o.LogWarningIfTryOverThreshold {
// Log a warning if the try duration exceeded the specified threshold
logLevel, forceLog = pipeline.LogWarning, true
logLevel, forceLog = pipeline.LogWarning, !o.SyslogDisabled
}
var sc int
@ -73,8 +78,9 @@ func NewRequestLogPolicyFactory(o RequestLogOptions) pipeline.Factory {
}
}
if sc == 0 || ((sc >= 400 && sc <= 499) && sc != http.StatusNotFound && sc != http.StatusConflict && sc != http.StatusPreconditionFailed && sc != http.StatusRequestedRangeNotSatisfiable) || (sc >= 500 && sc <= 599) {
logLevel, forceLog = pipeline.LogError, true // Promote to Error any 4xx (except those listed is an error) or any 5xx
if sc == 0 || ((sc >= 400 && sc <= 499) && sc != http.StatusNotFound && sc != http.StatusConflict &&
sc != http.StatusPreconditionFailed && sc != http.StatusRequestedRangeNotSatisfiable) || (sc >= 500 && sc <= 599) {
logLevel, forceLog = pipeline.LogError, !o.SyslogDisabled // Promote to Error any 4xx (except those listed is an error) or any 5xx
} else {
// For other status codes, we leave the level as is.
}

Просмотреть файл

@ -27,11 +27,11 @@ func (s *aztestsSuite) TestSetBlobTags(c *chk.C) {
blockBlobUploadResp, err := blobURL.Upload(ctx, bytes.NewReader([]byte("data")), BlobHTTPHeaders{}, basicMetadata, BlobAccessConditions{}, DefaultAccessTier, nil, ClientProvidedKeyOptions{})
c.Assert(err, chk.IsNil)
c.Assert(blockBlobUploadResp.StatusCode(), chk.Equals, 201)
blobSetTagsResponse, err := blobURL.SetTags(ctx, nil, nil, nil, nil, nil, nil, blobTagsMap)
blobSetTagsResponse, err := blobURL.SetTags(ctx, nil, nil, nil, blobTagsMap)
c.Assert(err, chk.IsNil)
c.Assert(blobSetTagsResponse.StatusCode(), chk.Equals, 204)
blobGetTagsResponse, err := blobURL.GetTags(ctx, nil, nil, nil, nil, nil)
blobGetTagsResponse, err := blobURL.GetTags(ctx, nil)
c.Assert(err, chk.IsNil)
c.Assert(blobGetTagsResponse.StatusCode(), chk.Equals, 200)
c.Assert(blobGetTagsResponse.BlobTagSet, chk.HasLen, 3)
@ -61,11 +61,11 @@ func (s *aztestsSuite) TestSetBlobTagsWithVID(c *chk.C) {
versionId2 := blockBlobUploadResp.VersionID()
blobURL1 := blobURL.WithVersionID(versionId1)
blobSetTagsResponse, err := blobURL1.SetTags(ctx, nil, nil, nil, nil, nil, nil, blobTagsMap)
blobSetTagsResponse, err := blobURL1.SetTags(ctx, nil, nil, nil, blobTagsMap)
c.Assert(err, chk.IsNil)
c.Assert(blobSetTagsResponse.StatusCode(), chk.Equals, 204)
blobGetTagsResponse, err := blobURL1.GetTags(ctx, nil, nil, nil, nil, nil)
blobGetTagsResponse, err := blobURL1.GetTags(ctx, nil)
c.Assert(err, chk.IsNil)
c.Assert(blobGetTagsResponse.StatusCode(), chk.Equals, 200)
c.Assert(blobGetTagsResponse.BlobTagSet, chk.HasLen, 3)
@ -74,7 +74,7 @@ func (s *aztestsSuite) TestSetBlobTagsWithVID(c *chk.C) {
}
blobURL2 := blobURL.WithVersionID(versionId2)
blobGetTagsResponse, err = blobURL2.GetTags(ctx, nil, nil, nil, nil, nil)
blobGetTagsResponse, err = blobURL2.GetTags(ctx, nil)
c.Assert(err, chk.IsNil)
c.Assert(blobGetTagsResponse.StatusCode(), chk.Equals, 200)
c.Assert(blobGetTagsResponse.BlobTagSet, chk.IsNil)
@ -103,11 +103,11 @@ func (s *aztestsSuite) TestSetBlobTagsWithVID2(c *chk.C) {
}
blobURL1 := blobURL.WithVersionID(versionId1)
blobSetTagsResponse, err := blobURL1.SetTags(ctx, nil, nil, nil, nil, nil, nil, blobTags1)
blobSetTagsResponse, err := blobURL1.SetTags(ctx, nil, nil, nil, blobTags1)
c.Assert(err, chk.IsNil)
c.Assert(blobSetTagsResponse.StatusCode(), chk.Equals, 204)
blobGetTagsResponse, err := blobURL1.GetTags(ctx, nil, nil, nil, nil, nil)
blobGetTagsResponse, err := blobURL1.GetTags(ctx, nil)
c.Assert(err, chk.IsNil)
c.Assert(blobGetTagsResponse.StatusCode(), chk.Equals, 200)
c.Assert(blobGetTagsResponse.BlobTagSet, chk.HasLen, 3)
@ -121,11 +121,11 @@ func (s *aztestsSuite) TestSetBlobTagsWithVID2(c *chk.C) {
}
blobURL2 := blobURL.WithVersionID(versionId2)
blobSetTagsResponse, err = blobURL2.SetTags(ctx, nil, nil, nil, nil, nil, nil, blobTags2)
blobSetTagsResponse, err = blobURL2.SetTags(ctx, nil, nil, nil, blobTags2)
c.Assert(err, chk.IsNil)
c.Assert(blobSetTagsResponse.StatusCode(), chk.Equals, 204)
blobGetTagsResponse, err = blobURL2.GetTags(ctx, nil, nil, nil, nil, nil)
blobGetTagsResponse, err = blobURL2.GetTags(ctx, nil)
c.Assert(err, chk.IsNil)
c.Assert(blobGetTagsResponse.StatusCode(), chk.Equals, 200)
c.Assert(blobGetTagsResponse.BlobTagSet, chk.NotNil)
@ -148,7 +148,7 @@ func (s *aztestsSuite) TestUploadBlockBlobWithSpecialCharactersInTags(c *chk.C)
c.Assert(err, chk.IsNil)
c.Assert(blockBlobUploadResp.StatusCode(), chk.Equals, 201)
blobGetTagsResponse, err := blobURL.GetTags(ctx, nil, nil, nil, nil, nil)
blobGetTagsResponse, err := blobURL.GetTags(ctx, nil)
c.Assert(err, chk.IsNil)
c.Assert(blobGetTagsResponse.StatusCode(), chk.Equals, 200)
c.Assert(blobGetTagsResponse.BlobTagSet, chk.HasLen, 3)
@ -198,7 +198,7 @@ func (s *aztestsSuite) TestStageBlockWithTags(c *chk.C) {
c.Assert(contentData, chk.DeepEquals, []uint8(strings.Join(data, "")))
blobURL1 := blobURL.WithVersionID(versionId)
blobGetTagsResp, err := blobURL1.GetTags(ctx, nil, nil, nil, nil, nil)
blobGetTagsResp, err := blobURL1.GetTags(ctx, nil)
c.Assert(err, chk.IsNil)
c.Assert(blobGetTagsResp, chk.NotNil)
c.Assert(blobGetTagsResp.BlobTagSet, chk.HasLen, 3)
@ -206,7 +206,7 @@ func (s *aztestsSuite) TestStageBlockWithTags(c *chk.C) {
c.Assert(blobTagsMap[blobTag.Key], chk.Equals, blobTag.Value)
}
blobGetTagsResp, err = blobURL.GetTags(ctx, nil, nil, nil, nil, nil)
blobGetTagsResp, err = blobURL.GetTags(ctx, nil)
c.Assert(err, chk.IsNil)
c.Assert(blobGetTagsResp, chk.NotNil)
c.Assert(blobGetTagsResp.BlobTagSet, chk.HasLen, 3)
@ -290,7 +290,7 @@ func (s *aztestsSuite) TestStageBlockFromURLWithTags(c *chk.C) {
c.Assert(err, chk.IsNil)
c.Assert(destData, chk.DeepEquals, sourceData)
blobGetTagsResp, err := destBlob.GetTags(ctx, nil, nil, nil, nil, nil)
blobGetTagsResp, err := destBlob.GetTags(ctx, nil)
c.Assert(err, chk.IsNil)
c.Assert(blobGetTagsResp.BlobTagSet, chk.HasLen, 3)
for _, blobTag := range blobGetTagsResp.BlobTagSet {
@ -402,7 +402,7 @@ func (s *aztestsSuite) TestSetBlobTagForSnapshot(c *chk.C) {
"Storage+SDK": "SDK/GO",
"GO ": ".Net",
}
_, err := blobURL.SetTags(ctx, nil, nil, nil, nil, nil, nil, blobTagsMap)
_, err := blobURL.SetTags(ctx, nil, nil, nil, blobTagsMap)
c.Assert(err, chk.IsNil)
resp, err := blobURL.CreateSnapshot(ctx, nil, BlobAccessConditions{}, ClientProvidedKeyOptions{})
@ -433,7 +433,7 @@ func (s *aztestsSuite) TestCreatePageBlobWithTags(c *chk.C) {
c.Assert(putResp.Version(), chk.Not(chk.Equals), "")
c.Assert(putResp.rawResponse.Header.Get("x-ms-version-id"), chk.NotNil)
setTagResp, err := blob.SetTags(ctx, nil, nil, nil, nil, nil, nil, blobTagsMap)
setTagResp, err := blob.SetTags(ctx, nil, nil, nil, blobTagsMap)
c.Assert(err, chk.IsNil)
c.Assert(setTagResp.StatusCode(), chk.Equals, 204)
@ -447,7 +447,7 @@ func (s *aztestsSuite) TestCreatePageBlobWithTags(c *chk.C) {
"b0l1o2b3": "s0d1k2",
}
setTagResp, err = blob.SetTags(ctx, nil, nil, nil, nil, nil, nil, modifiedBlobTags)
setTagResp, err = blob.SetTags(ctx, nil, nil, nil, modifiedBlobTags)
c.Assert(err, chk.IsNil)
c.Assert(setTagResp.StatusCode(), chk.Equals, 204)
@ -482,7 +482,7 @@ func (s *aztestsSuite) TestSetTagOnPageBlob(c *chk.C) {
"b0l1o2b3": "s0d1k2",
}
setTagResp, err := blob.SetTags(ctx, nil, nil, nil, nil, nil, nil, modifiedBlobTags)
setTagResp, err := blob.SetTags(ctx, nil, nil, nil, modifiedBlobTags)
c.Assert(err, chk.IsNil)
c.Assert(setTagResp.StatusCode(), chk.Equals, 204)
@ -519,7 +519,7 @@ func (s *aztestsSuite) TestListBlobReturnsTags(c *chk.C) {
"tag2": "+-./:=_",
"+-./:=_1": "+-./:=_",
}
resp, err := blobURL.SetTags(ctx, nil, nil, nil, nil, nil, nil, blobTagsMap)
resp, err := blobURL.SetTags(ctx, nil, nil, nil, blobTagsMap)
c.Assert(err, chk.IsNil)
c.Assert(resp.StatusCode(), chk.Equals, 204)
@ -632,11 +632,11 @@ func (s *aztestsSuite) TestFilterBlobsUsingAccountSAS(c *chk.C) {
}
blobTagsMap := BlobTagsMap{"tag1": "firsttag", "tag2": "secondtag", "tag3": "thirdtag"}
setBlobTagsResp, err := blobURL.SetTags(ctx, nil, nil, nil, nil, nil, nil, blobTagsMap)
setBlobTagsResp, err := blobURL.SetTags(ctx, nil, nil, nil, blobTagsMap)
c.Assert(err, chk.IsNil)
c.Assert(setBlobTagsResp.StatusCode(), chk.Equals, 204)
blobGetTagsResp, err := blobURL.GetTags(ctx, nil, nil, nil, nil, nil)
blobGetTagsResp, err := blobURL.GetTags(ctx, nil)
c.Assert(err, chk.IsNil)
c.Assert(blobGetTagsResp.StatusCode(), chk.Equals, 200)
c.Assert(blobGetTagsResp.BlobTagSet, chk.HasLen, 3)

Просмотреть файл

@ -144,6 +144,7 @@ func ExampleNewPipeline() {
// Set RequestLogOptions to control how each HTTP request & its response is logged
RequestLog: RequestLogOptions{
LogWarningIfTryOverThreshold: time.Millisecond * 200, // A successful response taking more than this time to arrive is logged as a warning
SyslogDisabled: true,
},
// Set LogOptions to control what & where all pipeline log events go

Просмотреть файл

@ -2358,16 +2358,16 @@ type BlobHierarchyListSegment struct {
// BlobItemInternal - An Azure Storage blob
type BlobItemInternal struct {
// XMLName is used for marshalling and is subject to removal in a future release.
XMLName xml.Name `xml:"Blob"`
Name string `xml:"Name"`
Deleted bool `xml:"Deleted"`
Snapshot string `xml:"Snapshot"`
VersionID *string `xml:"VersionId"`
IsCurrentVersion *bool `xml:"IsCurrentVersion"`
Properties BlobPropertiesInternal `xml:"Properties"`
Metadata Metadata `xml:"Metadata"`
BlobTags *BlobTags `xml:"Tags"`
ObjectReplicationMetadata map[string]string `xml:"ObjectReplicationMetadata"`
XMLName xml.Name `xml:"Blob"`
Name string `xml:"Name"`
Deleted bool `xml:"Deleted"`
Snapshot string `xml:"Snapshot"`
VersionID *string `xml:"VersionId"`
IsCurrentVersion *bool `xml:"IsCurrentVersion"`
Properties BlobProperties `xml:"Properties"`
Metadata Metadata `xml:"Metadata"`
BlobTags *BlobTags `xml:"Tags"`
ObjectReplicationMetadata map[string]string `xml:"ObjectReplicationMetadata"`
}
// BlobMetadata ...
@ -2384,8 +2384,8 @@ type BlobPrefix struct {
Name string `xml:"Name"`
}
// BlobPropertiesInternal - Properties of a blob
type BlobPropertiesInternal struct {
// BlobProperties - Properties of a blob
type BlobProperties struct {
// XMLName is used for marshalling and is subject to removal in a future release.
XMLName xml.Name `xml:"Properties"`
CreationTime *time.Time `xml:"Creation-Time"`
@ -2438,14 +2438,14 @@ type BlobPropertiesInternal struct {
}
// MarshalXML implements the xml.Marshaler interface for BlobPropertiesInternal.
func (bpi BlobPropertiesInternal) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
bpi2 := (*blobPropertiesInternal)(unsafe.Pointer(&bpi))
func (bpi BlobProperties) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
bpi2 := (*blobProperties)(unsafe.Pointer(&bpi))
return e.EncodeElement(*bpi2, start)
}
// UnmarshalXML implements the xml.Unmarshaler interface for BlobPropertiesInternal.
func (bpi *BlobPropertiesInternal) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
bpi2 := (*blobPropertiesInternal)(unsafe.Pointer(bpi))
func (bpi *BlobProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
bpi2 := (*blobProperties)(unsafe.Pointer(bpi))
return d.DecodeElement(bpi2, &start)
}
@ -7499,7 +7499,7 @@ func init() {
if reflect.TypeOf((*AccessPolicy)(nil)).Elem().Size() != reflect.TypeOf((*accessPolicy)(nil)).Elem().Size() {
validateError(errors.New("size mismatch between AccessPolicy and accessPolicy"))
}
if reflect.TypeOf((*BlobPropertiesInternal)(nil)).Elem().Size() != reflect.TypeOf((*blobPropertiesInternal)(nil)).Elem().Size() {
if reflect.TypeOf((*BlobProperties)(nil)).Elem().Size() != reflect.TypeOf((*blobProperties)(nil)).Elem().Size() {
validateError(errors.New("size mismatch between BlobPropertiesInternal and blobPropertiesInternal"))
}
if reflect.TypeOf((*ContainerProperties)(nil)).Elem().Size() != reflect.TypeOf((*containerProperties)(nil)).Elem().Size() {
@ -7589,7 +7589,7 @@ type accessPolicy struct {
}
// internal type used for marshalling
type blobPropertiesInternal struct {
type blobProperties struct {
// XMLName is used for marshalling and is subject to removal in a future release.
XMLName xml.Name `xml:"Properties"`
CreationTime *timeRFC1123 `xml:"Creation-Time"`