-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Watcher: Remove extraneous auth classes #32300
Changes from 2 commits
5a1023c
93b7248
6e2a024
612a394
dd97372
8142993
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,22 +3,22 @@ | |
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
package org.elasticsearch.xpack.watcher.common.http.auth.basic; | ||
package org.elasticsearch.xpack.watcher.common.http; | ||
|
||
import org.elasticsearch.ElasticsearchParseException; | ||
import org.elasticsearch.common.ParseField; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.common.xcontent.XContentParser; | ||
import org.elasticsearch.xpack.core.watcher.common.secret.Secret; | ||
import org.elasticsearch.xpack.core.watcher.crypto.CryptoService; | ||
import org.elasticsearch.xpack.core.watcher.support.xcontent.WatcherParams; | ||
import org.elasticsearch.xpack.core.watcher.support.xcontent.WatcherXContentParser; | ||
import org.elasticsearch.xpack.watcher.common.http.auth.HttpAuth; | ||
|
||
import java.io.IOException; | ||
import java.util.Objects; | ||
|
||
public class BasicAuth implements HttpAuth { | ||
public class BasicAuth implements ToXContentObject { | ||
|
||
public static final String TYPE = "basic"; | ||
|
||
|
@@ -34,11 +34,6 @@ public BasicAuth(String username, Secret password) { | |
this.password = password; | ||
} | ||
|
||
@Override | ||
public String type() { | ||
return TYPE; | ||
} | ||
|
||
public String getUsername() { | ||
return username; | ||
} | ||
|
@@ -74,7 +69,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws | |
return builder.endObject(); | ||
} | ||
|
||
public static BasicAuth parse(XContentParser parser) throws IOException { | ||
public static BasicAuth parseInner(XContentParser parser) throws IOException { | ||
String username = null; | ||
Secret password = null; | ||
|
||
|
@@ -103,6 +98,20 @@ public static BasicAuth parse(XContentParser parser) throws IOException { | |
return new BasicAuth(username, password); | ||
} | ||
|
||
public static BasicAuth parse(XContentParser parser) throws IOException { | ||
String type = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about using an object parser here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not new, it was just yanked from |
||
XContentParser.Token token; | ||
BasicAuth auth = null; | ||
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { | ||
if (token == XContentParser.Token.FIELD_NAME) { | ||
type = parser.currentName(); | ||
} else if (token == XContentParser.Token.START_OBJECT && type != null) { | ||
auth = BasicAuth.parseInner(parser); | ||
} | ||
} | ||
return auth; | ||
} | ||
|
||
interface Field { | ||
ParseField USERNAME = new ParseField("username"); | ||
ParseField PASSWORD = new ParseField("password"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.